Comparing version 1.24.2 to 1.24.3
@@ -12,5 +12,13 @@ /* | ||
'use strict' | ||
var moment = require('moment') | ||
var logger = require('./util/logger.js') | ||
var util = require ('util') | ||
function formatArray (a) { | ||
if (a instanceof Array) { | ||
return a.join('\t') | ||
} else { | ||
return a + '' | ||
} | ||
} | ||
/** | ||
@@ -34,2 +42,6 @@ * Agent super class that provides an EventEmitter for 'metric' event. | ||
plugin: plugin, | ||
defaultType: 'njs', | ||
defaultFilters: function () { | ||
return [workerId || 0, process.pid || 0] | ||
}, | ||
metricBuffer: [], | ||
@@ -46,2 +58,9 @@ /** | ||
} | ||
if (!metric.type) { | ||
metric.type = this.defaultType | ||
} | ||
if (!metric.filters && metric.type === 'njs') { | ||
metric.filters = this.defaultFilters() | ||
} | ||
metric.spmLine = this.formatLine(metric) | ||
this.emit('metric', metric) | ||
@@ -52,3 +71,43 @@ if (metric.name) { | ||
}, | ||
collectdFormatLine: function (metric) { | ||
var metricsTs = (metric.ts).toFixed(0) | ||
var now2 = (new Date().getTime() / 1000).toFixed(0) | ||
var metricsTs2 = (metric.ts / 1000).toFixed(0) | ||
var dateString = moment(metric.ts).format('YYYY-MM-DD') | ||
if ((/collectd\-/.test(metric.name))) { | ||
if (/collectd\-cpu/.test(metric.name)) { | ||
line = (now2 + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value) | ||
} else { | ||
line = now2 + '\t' + metric.name + '\t' + metricsTs2 + ',' + metric.value | ||
} | ||
} else { | ||
line = (now / 1000).toFixed(0) + '\t' + metric.name + '\t' + metricsTs + ',' + metric.value | ||
} | ||
return line | ||
}, | ||
defaultFormatLine: function (metric) { | ||
var now = (new Date().getTime()).toFixed(0) | ||
var line = null | ||
if (metric.sct === 'OS') { | ||
this.collectdFormatLine(metric) | ||
} else { | ||
line = util.format("%d\t%s\t%d\t%s\t%s", now, (metric.type || this.defaultType) + '-' + metric.name, metric.ts, formatArray(metric.filters), formatArray(metric.value)) | ||
logger.log( now + '\t' + 'njs-' + metric.name + '\t' + metric.ts + '\t' + (metric.workerId || 0) + '\t' + (metric.pid || 0) + '\t' + formatArray(metric.value) ) | ||
} | ||
return line | ||
}, | ||
/** | ||
* formats a line for SPM sender, if the plugin does not support this method the default formatter for nodejs and OP metrics is used | ||
* @maram metric to format | ||
*/ | ||
formatLine: function (metric) { | ||
if (!this.plugin.formatLine) { | ||
return this.defaultFormatLine(metric) | ||
} else { | ||
return this.plugin.formatLine(metric) | ||
} | ||
}, | ||
/** | ||
* Starts the agent - typically thy create listeners or interval checks for metrics, and use 'addMetrics' to inform listeners | ||
@@ -55,0 +114,0 @@ */ |
@@ -29,3 +29,2 @@ /* | ||
var Datastore = require('nedb') | ||
var moment = require('moment') | ||
var util = require('util') | ||
@@ -69,3 +68,3 @@ var fs = require('fs') | ||
// DB compaction every 10 minutes | ||
db.persistence.setAutocompactionInterval(10*60*1000) | ||
db.persistence.setAutocompactionInterval(10 * 60 * 1000) | ||
@@ -116,3 +115,3 @@ /** | ||
var info = os.platform() + ', ' + os.arch() + ', ' + runtime +' ' + process.versions.node + ', ' + 'spm ' + clientVersion | ||
this.sendEvent ('server-info',{ | ||
this.sendEvent ('server-info', { | ||
message: info, | ||
@@ -203,21 +202,3 @@ tags: info.split (','), | ||
SpmSender.prototype.formatLine = function (metric) { | ||
var now = (new Date().getTime()).toFixed(0) | ||
var metricsTs = (metric.ts).toFixed(0) | ||
var now2 = (new Date().getTime() / 1000).toFixed(0) | ||
var metricsTs2 = (metric.ts / 1000).toFixed(0) | ||
var dateString = moment(metric.ts).format('YYYY-MM-DD') | ||
var line = null | ||
if (metric.sct === 'OS') { | ||
if ((/collectd\-/.test(metric.name))) { | ||
if (/collectd\-cpu/.test(metric.name)) { | ||
line = (now2 + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value) | ||
} else { | ||
line = now2 + '\t' + metric.name + '\t' + metricsTs2 + ',' + metric.value | ||
} | ||
} else { | ||
line = (now / 1000).toFixed(0) + '\t' + metric.name + '\t' + metricsTs + ',' + metric.value | ||
} | ||
} else { | ||
line = now + '\t' + 'njs-' + metric.name + '\t' + metric.ts + '\t' + (metric.workerId || 0) + '\t' + (metric.pid || 0) + '\t' + formatArray(metric.value) | ||
} | ||
var line = metric.spmLine | ||
logger.debug(line) | ||
@@ -224,0 +205,0 @@ return line |
{ | ||
"name": "spm-agent", | ||
"version": "1.24.2", | ||
"version": "1.24.3", | ||
"description": "Node.js agent framework for SPM by Sematext", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -67,8 +67,8 @@ /* | ||
var checked = cfgValue.filter(function (key) { | ||
return (config.get(key) != null || false) | ||
return (config.get(key) == null) | ||
}) | ||
if (cfgValue.length == checked.length) | ||
if (checked.length === 0) | ||
done() | ||
else | ||
done('not all default values set ' + checked) | ||
done('missing config values: ' + checked) | ||
} catch (err) { | ||
@@ -75,0 +75,0 @@ done(err) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
891
49774
13