New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

statful-client

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statful-client - npm Package Compare versions

Comparing version 4.3.2 to 4.3.3

.eslintrc.js

406

lib/client.js
'use strict';
//jshint latedef: nofunc
var dgram = require('dgram'),

@@ -7,3 +9,3 @@ blocked = require('blocked'),

URL = require('url'),
httpsAgent = new https.Agent({ maxSockets: 50, keepAlive: true }),
httpsAgent = new https.Agent({maxSockets: 50, keepAlive: true}),
merge = require('merge'),

@@ -76,4 +78,4 @@ zlib = require('zlib'),

req.on('error', function(e) {
if (e.code === "ECONNRESET") {
req.on('error', function (e) {
if (e.code === 'ECONNRESET') {
if (logger) {

@@ -92,3 +94,3 @@ logger.error('A timeout occurred on a request to host: ' + options.hostname +

socket.setTimeout(options.timeout);
socket.on('timeout', function() {
socket.on('timeout', function () {
req.abort();

@@ -134,10 +136,92 @@ });

/**
* Puts a metric into the buffer ready to be sent.
*
* @param self A self statful client.
* @param metricTypeConf A configuration for each metric type (counter, gauge, timer). Can be null if it a custom metric.
* @param name A metric name.
* @param value A metric value.
* @param aggregation The aggregation with which metric was aggregated.
* @param aggregationFreq The aggregation frequency with which metric was aggregated.
* @param parameters An object with metric para meters: tags, agg, aggFreq, namespace and timestamp.
*/
function putMetric(self, metricTypeConf, name, value, aggregation, aggregationFreq, parameters) {
var isMetricAggregated = aggregation && aggregationFreq;
var metricParams = parameters || {};
var tags = metricParams.tags,
agg = !isMetricAggregated ? metricParams.agg : [aggregation],
aggFreq = !isMetricAggregated ? metricParams.aggFreq : aggregationFreq,
namespace = metricParams.namespace,
timestamp = metricParams.timestamp,
sampleRate = metricParams.sampleRate;
if (configHelper.areMetricTypesArgumentsValid(agg, aggFreq, tags, timestamp)) {
var putAgg = metricTypeConf ? configHelper.concatAggregations(metricTypeConf.agg, agg) : agg,
putTags = metricTypeConf ? merge(tags, metricTypeConf.tags) : tags,
putAggFreq = metricTypeConf ? (aggFreq || metricTypeConf.aggFreq) : aggFreq;
putRaw(self, name, value, {
tags: putTags,
agg: putAgg,
aggFreq: putAggFreq,
namespace: namespace,
timestamp: timestamp,
sampleRate: sampleRate
}, isMetricAggregated);
} else if (self.logger) {
self.logger.debug('Metric not sent. Please review the following: aggregations, aggregation frequency, tags and timestamp.');
}
}
/**
* Puts a system stats metric into the system stats buffer ready to be sent.
*
* @param self A self statful client.
* @param metricTypeConf A configuration for each metric type (counter, gauge, timer). Can be null if it a custom metric.
* @param name A metric name.
* @param value A metric value.
* @param aggregation The aggregation with which metric was aggregated.
* @param aggregationFreq The aggregation frequency with which metric was aggregated.
* @param parameters An object with metric para meters: tags, agg, aggFreq, namespace and timestamp.
*/
function putSystemStatsMetrics(self, name, value, parameters) {
var metricParams = parameters || {};
var tags = metricParams.tags,
agg = metricParams.agg,
aggFreq = metricParams.aggFreq,
namespace = metricParams.namespace,
timestamp = metricParams.timestamp,
sampleRate = metricParams.sampleRate;
putSystemStats(self, name, value, {
tags: tags,
agg: agg,
aggFreq: aggFreq,
namespace: namespace,
timestamp: timestamp,
sampleRate: sampleRate
});
}
function sendFlushStats(self) {
if (self.systemStats) {
if (self.aggregatedBuffer.bufferSize > 0 && self.transport === 'api') {
self.put('buffer.flush_length', self.aggregatedBuffer.bufferSize, {agg: ['avg'], tags: {"buffer_type": 'aggregated'}});
putSystemStatsMetrics(self, 'buffer.flush_length', self.aggregatedBuffer.bufferSize, {
agg: ['avg', 'sum'],
tags: {'buffer_type': 'aggregated'}
});
}
if (self.nonAggregatedBuffer.bufferSize > 0) {
self.put('buffer.flush_length', self.nonAggregatedBuffer.bufferSize, {agg: ['avg'], tags: {"buffer_type": 'non-aggregated'}});
putSystemStatsMetrics(self, 'buffer.flush_length', self.nonAggregatedBuffer.bufferSize, {
agg: ['avg', 'sum'],
tags: {'buffer_type': 'non-aggregated'}
});
}
if (self.nonAggregatedBuffer.bufferSize > 0) {
putSystemStatsMetrics(self, 'buffer.flush_length', self.systemStatsBuffer.bufferSize, {
agg: ['avg', 'sum'],
tags: {'buffer_type': 'system-stats'}
});
}
}

@@ -147,94 +231,153 @@ }

/**
* Flushes the metrics to the Statful via UDP.
* Logs all the metrics to the logger
*
* @param self A self client instance.
*/
function flush(self) {
var buffer;
function logMetrics(self) {
var stringToLogHeader = '';
var stringToLog = '';
var aggLog;
var aggFreqLog;
sendFlushStats(self);
if (self.nonAggregatedBuffer.bufferSize > 0) {
self.logger.debug('Flushing metrics (non aggregated): ' + self.nonAggregatedBuffer.buffer);
}
if (self.aggregatedBuffer.bufferSize > 0) {
stringToLogHeader = 'Flushing metrics (aggregated): ';
if ( (self.aggregatedBuffer.bufferSize + self.nonAggregatedBuffer.bufferSize) > 0) {
if (self.dryRun) {
if (self.logger) {
if (self.nonAggregatedBuffer.bufferSize > 0) {
self.logger.debug('Flushing metrics (non aggregated): ' + self.nonAggregatedBuffer.buffer);
for (aggLog in self.aggregatedBuffer) {
for (aggFreqLog in self.aggregatedBuffer[aggLog]) {
if (self.aggregatedBuffer[aggLog][aggFreqLog].buffer.length > 0) {
if (stringToLog.length > 0) {
stringToLog += '\n';
}
stringToLog += self.aggregatedBuffer[aggLog][aggFreqLog].buffer;
self.aggregatedBuffer[aggLog][aggFreqLog].buffer = '';
}
if (self.aggregatedBuffer.bufferSize > 0) {
var stringToLogHeader = 'Flushing metrics (aggregated): ';
var stringToLog = '';
}
}
self.logger.debug(stringToLogHeader + stringToLog);
}
if (self.systemStatsBuffer.bufferSize > 0) {
self.logger.debug('Flushing metrics (system stats): ' + self.systemStatsBuffer.buffer);
}
//in case we need to send aggregated stats metrics, add code here
for (var aggLog in self.aggregatedBuffer) {
for (var aggFreqLog in self.aggregatedBuffer[aggLog]) {
if (self.aggregatedBuffer[aggLog][aggFreqLog].buffer.length > 0) {
if (stringToLog.length > 0) {
stringToLog +='\n';
}
stringToLog += self.aggregatedBuffer[aggLog][aggFreqLog].buffer;
self.aggregatedBuffer[aggLog][aggFreqLog].buffer = '';
}
}
}
self.logger.debug(stringToLogHeader + stringToLog);
}
}
}
/**
* Sends the non aggregated and system stats metrics using UDP transport
*
* @param self A self client instance.
*/
function sendMetricsByUdpTransport(self) {
var buffer;
if (self.logger) {
self.logger.debug('Flushing to ' + self.host + ', UDP port: ' + self.port);
}
if (self.aggregatedBuffer.bufferSize > 0) {
if (self.logger) {
self.logger.debug('Can\'t flush aggregated metrics using udp transport.');
}
self.aggregatedBuffer = configHelper.createEmptyAggregatedBuffer();
}
if (self.nonAggregatedBuffer.bufferSize > 0) {
buffer = new Buffer(self.nonAggregatedBuffer.buffer);
self.socket.send(buffer, 0, buffer.length, self.port, self.host);
}
if (self.systemStatsBuffer.bufferSize > 0) {
buffer = new Buffer(self.systemStatsBuffer.buffer);
self.socket.send(buffer, 0, buffer.length, self.port, self.host);
}
}
/**
* Sends all metrics using API transport
*
* @param self A self client instance.
*/
function sendMetricsByApiTransport(self) {
var agg;
var aggFreq;
if (self.nonAggregatedBuffer.bufferSize > 0) {
var nonAggregatedOptions = buildStatfulOptions(
self.protocol, self.host, self.port, self.basePath, self.token, self.timeout);
if (self.logger) {
self.logger.debug('Flushing to ' + nonAggregatedOptions.url + ' non aggregated metrics');
}
if (self.compression) {
sendCompressedMessage(nonAggregatedOptions, self.nonAggregatedBuffer.buffer, self.logger);
} else {
switch (self.transport) {
case 'udp':
sendUncompressedMessage(nonAggregatedOptions, self.nonAggregatedBuffer.buffer, self.logger);
}
}
if (self.aggregatedBuffer.bufferSize > 0) {
for (agg in self.aggregatedBuffer) {
for (aggFreq in self.aggregatedBuffer[agg]) {
if (self.aggregatedBuffer[agg][aggFreq].buffer.length > 0) {
var aggregatedPath = self.basePath + '/aggregation/' + agg + '/frequency/' + aggFreq;
var aggregatedOptions = buildStatfulOptions(
self.protocol, self.host, self.port, aggregatedPath, self.token, self.timeout);
if (self.logger) {
self.logger.debug('Flushing to ' + self.host + ', UDP port: ' + self.port);
self.logger.debug('Flushing to ' + aggregatedOptions.url + ' aggregated metrics');
}
if (self.aggregatedBuffer.bufferSize > 0) {
if (self.logger) {
self.logger.debug('Can\'t flush aggregated metrics using udp transport.');
}
self.aggregatedBuffer = configHelper.createEmptyAggregatedBuffer();
if (self.compression) {
sendCompressedMessage(aggregatedOptions, self.aggregatedBuffer[agg][aggFreq].buffer, self.logger);
} else {
sendUncompressedMessage(aggregatedOptions, self.aggregatedBuffer[agg][aggFreq].buffer, self.logger);
}
self.aggregatedBuffer[agg][aggFreq].buffer = '';
}
}
}
}
if (self.nonAggregatedBuffer.bufferSize > 0) {
buffer = new Buffer(self.nonAggregatedBuffer.buffer);
self.socket.send(buffer, 0, buffer.length, self.port, self.host);
}
break;
case 'api':
if (self.nonAggregatedBuffer.bufferSize > 0) {
var nonAggregatedOptions = buildStatfulOptions(
self.protocol, self.host, self.port, self.basePath, self.token, self.timeout);
if (self.systemStatsBuffer.bufferSize > 0) {
var nonAggregatedStatsOptions = buildStatfulOptions(
self.protocol, self.host, self.port, self.basePath, self.token, self.timeout);
if (self.logger) {
self.logger.debug('Flushing to ' + nonAggregatedOptions.url + ' non aggregated metrics');
}
if (self.logger) {
self.logger.debug('Flushing to ' + nonAggregatedStatsOptions.url + ' system stats metrics');
}
if (self.compression) {
sendCompressedMessage(nonAggregatedOptions, self.nonAggregatedBuffer.buffer, self.logger);
} else {
sendUncompressedMessage(nonAggregatedOptions, self.nonAggregatedBuffer.buffer, self.logger);
}
}
if (self.compression) {
sendCompressedMessage(nonAggregatedStatsOptions, self.systemStatsBuffer.buffer, self.logger);
} else {
sendUncompressedMessage(nonAggregatedStatsOptions, self.systemStatsBuffer.buffer, self.logger);
}
}
}
if (self.aggregatedBuffer.bufferSize > 0) {
for (var agg in self.aggregatedBuffer) {
for (var aggFreq in self.aggregatedBuffer[agg]) {
if (self.aggregatedBuffer[agg][aggFreq].buffer.length > 0) {
var aggregatedPath = self.basePath + '/aggregation/' + agg + '/frequency/' + aggFreq;
var aggregatedOptions = buildStatfulOptions(
self.protocol, self.host, self.port, aggregatedPath, self.token, self.timeout);
/**
* Flushes the metrics to the Statful via UDP.
*
* @param self A self client instance.
*/
function flush(self) {
if (self.logger) {
self.logger.debug('Flushing to ' + aggregatedOptions.url + ' aggregated metrics');
}
sendFlushStats(self);
if (self.compression) {
sendCompressedMessage(aggregatedOptions, self.aggregatedBuffer[agg][aggFreq].buffer, self.logger);
} else {
sendUncompressedMessage(aggregatedOptions, self.aggregatedBuffer[agg][aggFreq].buffer, self.logger);
}
self.aggregatedBuffer[agg][aggFreq].buffer = '';
}
}
}
}
if ((self.aggregatedBuffer.bufferSize + self.nonAggregatedBuffer.bufferSize) > 0) {
if (self.dryRun) {
if (self.logger) {
logMetrics(self);
}
} else {
switch (self.transport) {
case 'udp':
sendMetricsByUdpTransport(self);
break;
case 'api':
sendMetricsByApiTransport(self);
break;
}

@@ -246,2 +389,5 @@ }

self.nonAggregatedBuffer.bufferSize = 0;
self.systemStatsBuffer.buffer = '';
self.systemStatsBuffer.bufferSize = 0;
}

@@ -281,4 +427,4 @@ }

if ( (self.aggregatedBuffer.bufferSize + self.nonAggregatedBuffer.bufferSize) >= self.flushSize) {
setTimeout(function() {
if ((self.aggregatedBuffer.bufferSize + self.nonAggregatedBuffer.bufferSize + self.systemStatsBuffer.bufferSize) >= self.flushSize) {
setTimeout(function () {
flush(self);

@@ -295,2 +441,27 @@ }, 0);

/**
* Adds raw metrics directly into the flush buffer. Use this method with caution.
*
* @param self A self client instance.
* @param metricLines The metrics, in valid line protocol, to push to the buffer.
*/
function addToStatsBuffer(self, metricLines) {
if (typeof metricLines !== 'undefined') {
var targetBuffer = self.systemStatsBuffer;
if (targetBuffer.bufferSize > 0) {
targetBuffer.buffer += '\n';
}
targetBuffer.buffer += metricLines;
targetBuffer.bufferSize++;
} else {
if (self.logger) {
self.logger.error('Invalid metric lines: ' + metricLines);
}
}
}
/**
* Adds a new metric to the in-memory buffer.

@@ -328,3 +499,3 @@ *

if ( (Math.random() <= sampleRateNormalized) || isMetricAggregated) {
if ((Math.random() <= sampleRateNormalized) || isMetricAggregated) {
flushLine = Object.keys(putTags).reduce(function (previousValue, tag) {

@@ -359,31 +530,57 @@ return previousValue + ',' + tag + '=' + putTags[tag];

/**
* Puts a metric into the buffer ready to be sent.
* Adds a new system stats metric to the in-memory system stats buffer.
*
* @param self A self statful client.
* @param metricTypeConf A configuration for each metric type (counter, gauge, timer). Can be null if it a custom metric.
* @param name A metric name.
* @param value A metric value.
* @param aggregation The aggregation with which metric was aggregated.
* @param aggregationFreq The aggregation frequency with which metric was aggregated.
* @param self A self client instance.
* @param metric Name metric such as 'response_time'.
* @param value.
* @param parameters An object with metric para meters: tags, agg, aggFreq, namespace and timestamp.
* - tags: Tags to associate this value with, for example {from: 'serviceA', to: 'serviceB', method: 'login'}.
* - agg: List of aggregations to be applied by Statful. Ex: ['avg', 'p90', 'min'].
* - aggFreq: Aggregation frequency in seconds. One of: 10, 30, 60 ,120, 180, 300. Default: 10.
* - namespace: Define the metric namespace. Default: application.
* - timestamp: Defines the metrics timestamp. Default: current timestamp.
*/
function putMetric(self, metricTypeConf, name, value, aggregation, aggregationFreq, parameters) {
var isMetricAggregated = aggregation && aggregationFreq;
function putSystemStats(self, metric, value, parameters) {
var metricParams = parameters || {};
var tags = metricParams.tags,
agg = !isMetricAggregated ? metricParams.agg : [aggregation],
aggFreq = !isMetricAggregated ? metricParams.aggFreq : aggregationFreq,
agg = metricParams.agg,
aggFreq = metricParams.aggFreq,
namespace = metricParams.namespace,
timestamp = metricParams.timestamp,
sampleRate = metricParams.sampleRate;
sampleRate = parameters.sampleRate || self.sampleRate;
if (configHelper.areMetricTypesArgumentsValid(agg, aggFreq, tags, timestamp)) {
var putAgg = metricTypeConf ? configHelper.concatAggregations(metricTypeConf.agg, agg) : agg,
putTags = metricTypeConf ? merge(tags, metricTypeConf.tags) : tags,
putAggFreq = metricTypeConf ? (aggFreq || metricTypeConf.aggFreq) : aggFreq;
// Vars to Put
var putNamespace = namespace || self.namespace;
var putAggFreq = aggFreq || 10;
var putTags = merge(self.app ? merge({app: self.app}, tags) : tags, self.tags);
putRaw(self, name, value, {tags: putTags, agg: putAgg, aggFreq: putAggFreq, namespace: namespace, timestamp: timestamp, sampleRate: sampleRate}, isMetricAggregated);
} else if (self.logger) {
self.logger.debug('Metric not sent. Please review the following: aggregations, aggregation frequency, tags and timestamp.');
var metricName = putNamespace + '.' + metric,
flushLine = metricName,
sampleRateNormalized = (sampleRate || 100) / 100;
if (Math.random() <= sampleRateNormalized) {
flushLine = Object.keys(putTags).reduce(function (previousValue, tag) {
return previousValue + ',' + tag + '=' + putTags[tag];
}, flushLine);
flushLine += ' ' + value + ' ' + (timestamp || (Math.round(new Date().getTime() / 1000)));
if (agg) {
agg.push(putAggFreq);
flushLine += ' ' + agg.join(',');
if (sampleRate && sampleRate < 100) {
flushLine += ' ' + sampleRate;
}
}
addToStatsBuffer(self, [flushLine]);
} else {
if (self.logger) {
self.logger.debug('Metric was discarded due to sample rate.');
}
}
}

@@ -416,3 +613,3 @@

function putNonAggregatedMetric(self, metricTypeConf, name, value, parameters) {
putMetric(self, metricTypeConf, name, value, null, null, parameters);
putMetric(self, metricTypeConf, name, value, null, null, parameters, false);
}

@@ -488,5 +685,10 @@

this.systemStatsBuffer = {
buffer: '',
bufferSize: 0
};
if (this.systemStats) {
blocked(function (ms) {
self.timer('event_loop', ms);
putSystemStatsMetrics(self, 'timer.event_loop', ms, {agg: ['avg', 'p90', 'count'], tags: {'unit': 'ms'}});
});

@@ -493,0 +695,0 @@ }

{
"name": "statful-client",
"description": "NodeJS Client for the Statful",
"author": {
"name": "Jose Fonseca",
"email": "jose.fonseca@mindera.com"
},
"author": "Jose Fonseca <jose.fonseca@mindera.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/statful/statful-client-nodejs.git"
"url": "git+https://github.com/statful/statful-client-nodejs.git"
},
"version": "4.3.2",
"version": "4.3.3",
"engines": {
"node": ">=0.8"
"node": ">=4.4.0"
},
"main": "statful.js",
"scripts": {
"test": "grunt test"
"eslint": "eslint lib",
"cover": "istanbul cover _mocha spec/*.js",
"test": "npm run eslint && npm run cover"
},
"dependencies": {
"blocked": "^1.1.0",
"blocked": "^1.2.1",
"merge": "^1.2.0",

@@ -27,21 +26,16 @@ "unique-concat": "^0.2.2"

"devDependencies": {
"bunyan": "^1.8.1",
"chai": "^3.5.0",
"grunt": "^0.4.5",
"grunt-bump": "^0.3.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-mocha": "^0.4.13",
"grunt-mocha-cli": "^1.11.0",
"grunt-mocha-istanbul": "^5.0.1",
"grunt-mocha-test": "^0.12.7",
"http": "0.0.0",
"istanbul": "^0.4.4",
"jshint-stylish": "^2.2.0",
"load-grunt-tasks": "^3.1.0",
"mocha": "2.5.3",
"sinon": "^1.17.4",
"time-grunt": "^1.1.0"
"bunyan": "^1.8.12",
"chai": "^4.1.1",
"eslint": "^4.5.0",
"istanbul": "^0.4.5",
"mocha": "3.5.0",
"sinon": "^3.2.1"
},
"bugs": {
"url": "https://github.com/statful/statful-client-nodejs/issues"
},
"homepage": "https://github.com/statful/statful-client-nodejs#readme",
"directories": {
"lib": "lib"
}
}

@@ -22,3 +22,3 @@ Statful Client for NodeJS

|:---|:---|
| 4.x.x | `0.10`, `0.12`, `4` and `Stable` |
| 4.x.x | `4.4.0`, `5.12.0`, `6.9.2`, `7.10.1`, `8.2.0` |

@@ -25,0 +25,0 @@ ## Installation

@@ -47,3 +47,3 @@ 'use strict';

expect(lines.toString()).to.match(/^application.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -72,3 +72,3 @@ }

expect(lines.toString()).to.match(/^application.my_metric1 1 \d+\napplication.my_metric2 1 \d+$/);
expect(lines.toString()).to.match(/^application\.my_metric1 1 \d+\napplication\.my_metric2 1 \d+$/);
done();

@@ -96,3 +96,3 @@ }

expect(lines).to.match(/^application.my_metric 1 \d+$/);
expect(lines).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -121,3 +121,3 @@ }

expect(lines).to.match(/^application.my_metric 1 \d+$/);
expect(lines).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -146,3 +146,3 @@ }

expect(lines).to.match(/^application.my_metric1 1 \d+\napplication.my_metric2 1 \d+$/);
expect(lines).to.match(/^application\.my_metric1 1 \d+\napplication\.my_metric2 1 \d+$/);
done();

@@ -170,3 +170,3 @@ }

expect(lines.toString()).to.match(/^application.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -194,3 +194,3 @@ }

expect(lines.toString()).to.match(/^my_namespace.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^my_namespace\.my_metric 1 \d+$/);
done();

@@ -268,3 +268,3 @@ }

randomStub.restore();
expect(lines.toString()).to.match(/^application.my_metric 1 \d+ avg,10 80$/);
expect(lines.toString()).to.match(/^application\.my_metric 1 \d+ avg,10 80$/);
done();

@@ -364,3 +364,3 @@ }

expect(lines).to.match(/^application.my_metric 1 \d+$/);
expect(lines).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -416,3 +416,3 @@ }

expect(lines.toString()).to.match(/^my_namespace.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^my_namespace\.my_metric 1 \d+$/);
done();

@@ -441,3 +441,3 @@ }

expect(lines.toString()).to.match(/^my_other_namespace.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^my_other_namespace\.my_metric 1 \d+$/);
done();

@@ -489,3 +489,3 @@ }

expect(lines.toString()).to.match(/^application.my_metric 1 \d+$/);
expect(lines.toString()).to.match(/^application\.my_metric 1 \d+$/);
done();

@@ -576,3 +576,3 @@ }

setTimeout(function () {
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(non aggregated\): application.my_metric 1 \d+$/);
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(non aggregated\): application\.my_metric 1 \d+$/);
victim.logger.debug.restore();

@@ -603,3 +603,3 @@ done();

setTimeout(function () {
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(aggregated\): application.my_metric 1 \d+\napplication\.my_metric 1 \d+$/);
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(aggregated\): application\.my_metric 1 \d+\napplication\.my_metric 1 \d+$/);
victim.logger.debug.restore();

@@ -630,4 +630,4 @@ done();

setTimeout(function () {
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(non aggregated\): application.my_metric 1 \d+$/);
expect(victim.logger.debug.getCall(1).args[0]).to.match(/^Flushing metrics \(aggregated\): application.my_metric 1 \d+\napplication\.my_metric 1 \d+$/);
expect(victim.logger.debug.getCall(0).args[0]).to.match(/^Flushing metrics \(non aggregated\): application\.my_metric 1 \d+$/);
expect(victim.logger.debug.getCall(1).args[0]).to.match(/^Flushing metrics \(aggregated\): application\.my_metric 1 \d+\napplication\.my_metric 1 \d+$/);
victim.logger.debug.restore();

@@ -681,3 +681,2 @@ done();

httpsServer.stop();
expect(lines.toString()).to.match(/^application\.my_metric1 1 \d+\napplication\.my_metric2 1 \d+$/);

@@ -709,2 +708,3 @@ done();

expect(lines.toString()).to.match(/^application\.my_metric1 1 \d+\napplication\.my_metric2 1 \d+$/);
done();

@@ -732,3 +732,2 @@ }

httpsServer.stop();
expect(lines.toString()).to.match(/^application\.my_metric1 1 \d+\napplication\.my_metric2 1 \d+$/);

@@ -814,2 +813,88 @@ done();

});
it('should send system stats metrics through UDP', function (done) {
// Given
udpServer.start(udpPort, '127.0.0.1', null, onResponse);
var victim = new Client({
systemStats: true,
transport: 'udp',
port: udpPort,
flushSize: 1,
flushInterval: 10000
}, logger);
// When
victim.put('my_metric', 1, null, false);
// Then
function onResponse(lines) {
//expect my_metric
if (lines.toString().indexOf("\n") === -1) {
expect(lines.toString()).to.match(/^application.my_metric 1 \d+$/);
} else {
//expect systemStats after that
expect(lines.toString()).to.match(/^application\.buffer\.flush_length,buffer_type=non_aggregated 1 \d+$/);
udpServer.stop();
}
done();
}
});
it('should log metrics when dryRun is activated (systemStats)', function (done) {
// Given
var victim = new Client({
systemStats: true,
transport: 'api',
api: apiConf,
flushSize: 1,
dryRun: true
}, logger);
sinon.spy(victim.logger, "debug");
// When
victim.put('my_metric', 1);
// Then
setTimeout(function () {
expect(victim.logger.debug.getCall(1).args[0]).to.match(/^Flushing metrics \(system stats\): application\.buffer\.flush_length,buffer_type=non-aggregated 1 \d+ avg,sum,10\napplication\.buffer\.flush_length,buffer_type=system-stats 1 \d+ avg,sum,10/);
victim.logger.debug.restore();
done();
});
});
it('should send system stats metrics through HTTPS', function (done) {
// Given
httpsServer.start(httpPort, '127.0.0.1', onResponse);
var victim = new Client({
systemStats: true,
transport: 'api',
api: apiConf,
flushSize: 1
}, logger);
// When
victim.put('my_metric', 1);
// Then
function onResponse(lines) {
if (lines.toString().indexOf("\n") === -1) {
expect(lines).to.match(/^application\.my_metric 1 \d+$/);
} else {
expect(lines).to.match(/^Flushing metrics \(system stats\): application\.buffer\.flush_length,buffer_type=aggregated 1 \d+ avg,10\napplication\.buffer\.flush_length,buffer_type=system-stats 1 \d+ avg,10/);
httpsServer.stop();
}
done();
}
});
});
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