Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hot-shots

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hot-shots - npm Package Compare versions

Comparing version 2.4.0 to 3.0.0

5

CHANGES.md

@@ -5,6 +5,9 @@ CHANGELOG

## HEAD (Unreleased)
none
--------------------
## 3.0.0 (2015-4-27)
* @ash2k Method to create child clients
* @ash2k Shrink npm package a bit more
## 2.4.0 (2015-2-26)

@@ -11,0 +14,0 @@ * @arlolra Shrink npm package

65

lib/statsd.js
var dgram = require('dgram'),
util = require('util'),
dns = require('dns');

@@ -43,15 +44,20 @@

this.suffix = options.suffix || '';
this.socket = dgram.createSocket('udp4');
this.socket = options.isChild ? options.socket : dgram.createSocket('udp4');
this.mock = options.mock;
this.globalTags = options.globalTags || [];
this.globalTags = Array.isArray(options.globalTags) ? options.globalTags : [];
this.telegraf = options.telegraf || false;
this.maxBufferSize = options.maxBufferSize || 0;
this.bufferFlushInterval = options.bufferFlushInterval || 1000;
this.buffer = "";
this.bufferHolder = options.isChild ? options.bufferHolder : { buffer: "" };
if(this.maxBufferSize > 0) {
// We only want a single flush event per parent and all its child clients
if(!options.isChild && this.maxBufferSize > 0) {
this.intervalHandle = setInterval(this.onBufferFlushInterval.bind(this), this.bufferFlushInterval);
}
if(options.cacheDns === true){
if (options.isChild) {
if (options.dnsError) {
this.dnsError = options.dnsError;
}
} else if (options.cacheDns === true){
dns.lookup(options.host, function(err, address, family){

@@ -61,3 +67,3 @@ if(err === null){

} else {
self.dnsError = err;
self.dnsError = err;
}

@@ -347,7 +353,7 @@ });

if (this.buffer.length + message.length > this.maxBufferSize) {
if (this.bufferHolder.buffer.length + message.length > this.maxBufferSize) {
this.flushQueue();
}
this.buffer += message;
this.bufferHolder.buffer += message;
};

@@ -359,4 +365,4 @@

Client.prototype.flushQueue = function(){
this.sendMessage(this.buffer);
this.buffer = "";
this.sendMessage(this.bufferHolder.buffer);
this.bufferHolder.buffer = "";
};

@@ -390,3 +396,3 @@

Client.prototype.onBufferFlushInterval = function() {
if(this.buffer !== "") {
if(this.bufferHolder.buffer !== "") {
this.flushQueue();

@@ -404,3 +410,3 @@ }

if(this.buffer.length >= 0) {
if(this.bufferHolder.buffer.length >= 0) {
this.flushQueue();

@@ -429,3 +435,38 @@ }

/**
* Creates a child client that adds prefix, suffix and/or tags to this client. Child client can itself have children.
* @param options
* @option prefix {String} An optional prefix to assign to each stat name sent
* @option suffix {String} An optional suffix to assign to each stat name sent
* @option globalTags {Array=} Optional tags that will be added to every metric
*/
Client.prototype.childClient = function(options) {
return new ChildClient(this, options);
};
var ChildClient = function (parent, options) {
options = options || {};
Client.call(this, {
isChild : true,
socket : parent.socket, // Child inherits socket from parent. Parent itself can be a child.
// All children and parent share the same buffer via sharing an object (cannot mutate strings)
bufferHolder: parent.bufferHolder,
dnsError : parent.dnsError, // Child inherits an error from parent (if it is there)
host : parent.host,
port : parent.port,
prefix : (options.prefix || '') + parent.prefix, // Child has its prefix prepended to parent's prefix
suffix : parent.suffix + (options.suffix || ''), // Child has its suffix appended to parent's suffix
globalize : false, // Only "root" client can be global
mock : parent.mock,
// Append child's tags to parent's tags
globalTags : Array.isArray(options.globalTags) ? parent.globalTags.concat(options.globalTags) : parent.globalTags,
maxBufferSize : parent.maxBufferSize,
bufferFlushInterval: parent.bufferFlushInterval,
telegraf : parent.telegraf
});
};
util.inherits(ChildClient, Client);
exports = module.exports = Client;
exports.StatsD = Client;
{
"name": "hot-shots",
"description": "Node.js client for StatsD, DogStatsD, and Telegraf",
"version": "2.4.0",
"version": "3.0.0",
"author": "Steve Ivy",

@@ -6,0 +6,0 @@ "contributors": [

@@ -120,2 +120,11 @@ # hot-shots

// Use a child client to add more context to the client.
// Clients can be nested.
var childClient = client.childClient({
prefix: 'additionalPrefix.',
suffix: '.additionalSuffix',
globalTags: ['globalTag1:forAllMetricsFromChildClient']
});
childClient.increment('my_counter_with_more_tags');
// Close statsd. This will ensure all stats are sent and stop statsd

@@ -122,0 +131,0 @@ // from doing anything more.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc