Gathering detailed insights and metrics for @figma/hot-shots
Gathering detailed insights and metrics for @figma/hot-shots
Gathering detailed insights and metrics for @figma/hot-shots
Gathering detailed insights and metrics for @figma/hot-shots
npm install @figma/hot-shots
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
527 Stars
801 Commits
136 Forks
31 Watching
1 Branches
102 Contributors
Updated on 01 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-31.7%
1,661
Compared to previous day
Last week
-19.8%
8,981
Compared to previous week
Last month
21%
39,175
Compared to previous month
Last year
-69.2%
386,343
Compared to previous year
A Node.js client for Etsy's StatsD server, Datadog's DogStatsD server, and InfluxDB's Telegraf StatsD server.
This project was originally a fork off of node-statsd. This project includes all changes in the latest node-statsd and many additional changes, including:
You can read about all changes in the changelog.
hot-shots supports Node 10.x and higher.
All initialization parameters are optional.
Parameters (specified as one object passed into hot-shots):
host
: The host to send stats to, if not set, the constructor tries to
retrieve it from the DD_AGENT_HOST
environment variable, default: 'undefined'
which as per UDP/datagram socket docs results in 127.0.0.1
or ::1
being used.port
: The port to send stats to, if not set, the constructor tries to retrieve it from the DD_DOGSTATSD_PORT
environment variable, default: 8125
prefix
: What to prefix each stat name with default: ''
. Note prefix separator must be specified explicitly if desired (e.g. my_prefix.
).suffix
: What to suffix each stat name with default: ''
. Note suffix separator must be specified explicitly if desired (e.g. .my_suffix
).tagPrefix
: Prefix tag list with character default: '#'
. Note does not work with telegraf
option.tagSeparator
: Separate tags with character default: ','
. Note does not work with telegraf
option.globalize
: Expose this StatsD instance globally. default: false
cacheDns
: Caches dns lookup to host for cacheDnsTtl, only used
when protocol is udp
, default: false
cacheDnsTtl
: time-to-live of dns lookups in milliseconds, when cacheDns is enabled. default: 60000
mock
: Create a mock StatsD instance, sending no stats to
the server and allowing data to be read from mockBuffer. Note that
mockBuffer will keep growing, so only use for testing or clear out periodically. default: false
globalTags
: Tags that will be added to every metric. Can be either an object or list of tags. default: {}
.includeDataDogTags
: Whether to include DataDog tags to the global tags. default: true
. The following Datadog tags are appended to globalTags
from the corresponding environment variable if the latter is set:
maxBufferSize
: If larger than 0, metrics will be buffered and only sent when the string length is greater than the size. default: 0
bufferFlushInterval
: If buffering is in use, this is the time in ms to always flush any buffered metrics. default: 1000
telegraf
: Use Telegraf's StatsD line protocol, which is slightly different than the rest default: false
sampleRate
: Sends only a sample of data to StatsD for all StatsD methods. Can be overridden at the method level. default: 1
errorHandler
: A function with one argument. It is called to handle various errors. default: none
, errors are thrown/logger to consoleuseDefaultRoute
: Use the default interface on a Linux system. Useful when running in containersprotocol
: Use tcp
option for TCP protocol, or uds
for the Unix Domain Socket protocol or stream
for the raw stream. Defaults to udp
otherwise.path
: Used only when the protocol is uds
. Defaults to /var/run/datadog/dsd.socket
.stream
: Reference to a stream instance. Used only when the protocol is stream
.tcpGracefulErrorHandling
: Used only when the protocol is tcp
. Boolean indicating whether to handle socket errors gracefully. Defaults to true.tcpGracefulRestartRateLimit
: Used only when the protocol is tcp
. Time (ms) between re-creating the socket. Defaults to 1000
.udsGracefulErrorHandling
: Used only when the protocol is uds
. Boolean indicating whether to handle socket errors gracefully. Defaults to true.udsGracefulRestartRateLimit
: Used only when the protocol is uds
. Time (ms) between re-creating the socket. Defaults to 1000
.closingFlushInterval
: Before closing, StatsD will check for inflight messages. Time (ms) between each check. Defaults to 50
.udpSocketOptions
: Used only when the protocol is udp
. Specify the options passed into dgram.createSocket(). Defaults to { type: 'udp4' }
All StatsD methods other than event
, close
, and check
have the same API:
name
: Stat name required
value
: Stat value required except in increment/decrement where it defaults to 1/-1 respectively
sampleRate
: Sends only a sample of data to StatsD default: 1
tags
: The tags to add to metrics. Can be either an object { tag: "value"}
or an array of tags. default: []
callback
: The callback to execute once the metric has been sent or bufferedIf an array is specified as the name
parameter each item in that array will be sent along with the specified value.
close
The close method has the following API:
callback
: The callback to execute once close is complete. All other calls to statsd will fail once this is called.event
The event method has the following API:
title
: Event title required
text
: Event description default is title
options
: Options for the event
date_happened
Assign a timestamp to the event default is now
hostname
Assign a hostname to the event.aggregation_key
Assign an aggregation key to the event, to group it with some others.priority
Can be ‘normal’ or ‘low’ default: normal
source_type_name
Assign a source type to the event.alert_type
Can be ‘error’, ‘warning’, ‘info’ or ‘success’ default: info
tags
: The tags to add to metrics. Can be either an object { tag: "value"}
or an array of tags. default: []
callback
: The callback to execute once the metric has been sent.check
The check method has the following API:
name
: Check name required
status
: Check status required
options
: Options for the check
date_happened
Assign a timestamp to the check default is now
hostname
Assign a hostname to the check.message
Assign a message to the check.tags
: The tags to add to metrics. Can be either an object { tag: "value"}
or an array of tags. default: []
callback
: The callback to execute once the metric has been sent.1 var StatsD = require('hot-shots'), 2 client = new StatsD({ 3 port: 8020, 4 globalTags: { env: process.env.NODE_ENV }, 5 errorHandler: errorHandler, 6 }); 7 8 // Increment: Increments a stat by a value (default is 1) 9 client.increment('my_counter'); 10 11 // Decrement: Decrements a stat by a value (default is -1) 12 client.decrement('my_counter'); 13 14 // Histogram: send data for histogram stat (DataDog and Telegraf only) 15 client.histogram('my_histogram', 42); 16 17 // Distribution: Tracks the statistical distribution of a set of values across your infrastructure. 18 // (DataDog v6) 19 client.distribution('my_distribution', 42); 20 21 // Gauge: Gauge a stat by a specified amount 22 client.gauge('my_gauge', 123.45); 23 24 // Gauge: Gauge a stat by a specified amount, but change it rather than setting it 25 client.gaugeDelta('my_gauge', -10); 26 client.gaugeDelta('my_gauge', 4); 27 28 // Set: Counts unique occurrences of a stat (alias of unique) 29 client.set('my_unique', 'foobar'); 30 client.unique('my_unique', 'foobarbaz'); 31 32 // Event: sends the titled event (DataDog only) 33 client.event('my_title', 'description'); 34 35 // Check: sends a service check (DataDog only) 36 client.check('service.up', client.CHECKS.OK, { hostname: 'host-1' }, ['foo', 'bar']) 37 38 // Incrementing multiple items 39 client.increment(['these', 'are', 'different', 'stats']); 40 41 // Incrementing with tags 42 client.increment('my_counter', ['foo', 'bar']); 43 44 // Sampling, this will sample 25% of the time the StatsD Daemon will compensate for sampling 45 client.increment('my_counter', 1, 0.25); 46 47 // Tags, this will add user-defined tags to the data 48 // (DataDog and Telegraf only) 49 client.histogram('my_histogram', 42, ['foo', 'bar']); 50 51 // Using the callback. This is the same format for the callback 52 // with all non-close calls 53 client.set(['foo', 'bar'], 42, function(error, bytes){ 54 //this only gets called once after all messages have been sent 55 if(error){ 56 console.error('Oh noes! There was an error:', error); 57 } else { 58 console.log('Successfully sent', bytes, 'bytes'); 59 } 60 }); 61 62 // Timing: sends a timing command with the specified milliseconds 63 client.timing('response_time', 42); 64 65 // Timing: also accepts a Date object of which the difference is calculated 66 client.timing('response_time', new Date()); 67 68 // Timer: Returns a function that you call to record how long the first 69 // parameter takes to execute (in milliseconds) and then sends that value 70 // using 'client.timing'. 71 // The parameters after the first one (in this case 'fn') 72 // match those in 'client.timing'. 73 var fn = function(a, b) { return a + b }; 74 client.timer(fn, 'fn_execution_time')(2, 2); 75 76 // Async timer: Similar to timer above, but you instead pass in a function 77 // that returns a Promise. And then it returns a Promise that will record the timing. 78 var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; 79 var instrumented = statsd.asyncTimer(fn, 'fn_execution_time'); 80 instrumented().then(function() { 81 console.log('Code run and metric sent'); 82 }); 83 84 // Async timer: Similar to asyncTimer above, but it instead emits a distribution. 85 var fn = function () { return new Promise(function (resolve, reject) { setTimeout(resolve, n); }); }; 86 var instrumented = statsd.asyncDistTimer(fn, 'fn_execution_time'); 87 instrumented().then(function() { 88 console.log('Code run and metric sent'); 89 }); 90 91 // Sampling, tags and callback are optional and could be used in any combination (DataDog and Telegraf only) 92 client.histogram('my_histogram', 42, 0.25); // 25% Sample Rate 93 client.histogram('my_histogram', 42, { tag: 'value'}); // User-defined tag 94 client.histogram('my_histogram', 42, ['tag:value']); // Tags as an array 95 client.histogram('my_histogram', 42, next); // Callback 96 client.histogram('my_histogram', 42, 0.25, ['tag']); 97 client.histogram('my_histogram', 42, 0.25, next); 98 client.histogram('my_histogram', 42, { tag: 'value'}, next); 99 client.histogram('my_histogram', 42, 0.25, { tag: 'value'}, next); 100 101 // Use a child client to add more context to the client. 102 // Clients can be nested. 103 var childClient = client.childClient({ 104 prefix: 'additionalPrefix.', 105 suffix: '.additionalSuffix', 106 globalTags: { globalTag1: 'forAllMetricsFromChildClient'} 107 }); 108 childClient.increment('my_counter_with_more_tags'); 109 110 // Close statsd. This will ensure all stats are sent and stop statsd 111 // from doing anything more. 112 client.close(function(err) { 113 console.log('The close did not work quite right: ', err); 114 });
Some of the functionality mentioned above is specific to DogStatsD or Telegraf. They will not do anything if you are using the regular statsd client.
As usual, callbacks will have an error as their first parameter. You can have an error in both the message and close callbacks.
If the optional callback is not given, an error is thrown in some cases and a console.log message is used in others. An error will only be explicitly thrown when there is a missing callback or if it is some potential configuration issue to be fixed.
If you would like to ensure all errors are caught, specify an errorHandler
in your root
client. This will catch errors in socket setup, sending of messages,
and closing of the socket. If you specify an errorHandler and a callback, the callback will take precedence.
1// Using errorHandler 2var client = new StatsD({ 3 errorHandler: function (error) { 4 console.log("Socket errors caught here: ", error); 5 } 6})
If you get an error like Error sending hot-shots message: Error: congestion
with an error code of 1
,
it is probably because you are sending large volumes of metrics to a single agent/ server.
This error only arises when using the UDS protocol and means that packages are being dropped.
Take a look at the Datadog docs for some tips on tuning your connection.
The 'uds' option as the protocol is to support Unix Domain Sockets for Datadog. It has the following limitations:
The above will cause the underlying library that is used, unix-dgram, to not install properly. Given the library is listed as an optionalDependency, and how it's used in the codebase, this install failure will not cause any problems. It only means that you can't use the uds feature.
Thanks for considering making any updates to this project! This project is entirely community-driven, and so your changes are important. Here are the steps to take in your fork:
When you've done all this we're happy to try to get this merged in right away.
Versions will attempt to follow semantic versioning, with major changes only coming in major versions.
npm publishing is possible by one person, bdeitte, who has two-factor authentication enabled for publishes. Publishes only contain one additional library, unix-dgram.
hot-shots is licensed under the MIT license.
No vulnerabilities found.
Reason
19 commit(s) and 6 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 7/27 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More