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

spm-agent

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spm-agent - npm Package Compare versions

Comparing version 1.24.0 to 1.24.1

   

10

lib/agent.js

@@ -28,5 +28,5 @@ /*

var workerId = 0 // 0 == Master, default
if (cluster.isMaster == false)
if (!cluster.isMaster) {
workerId = cluster.worker.id
}
var agentSuperClass = {

@@ -42,7 +42,9 @@ plugin: plugin,

metric.pid = process.pid
if (!metric.ts)
if (!metric.ts) {
metric.ts = new Date().getTime()
}
this.emit('metric', metric)
if (metric.name)
if (metric.name) {
this.emit(metric.name, metric)
}
},

@@ -49,0 +51,0 @@ /**

4

lib/index.js

@@ -13,3 +13,2 @@ /*

var events = require('events')
var Agent = require('./agent.js')
/**

@@ -74,3 +73,2 @@ * This module connects the loaded Agents/Plugins from harvester.js to the sender Module sender/spmsender.js

SpmAgent.prototype.createAgent = function (agent) {
//var a = new Agent(agent)
this.metricCollector.addAgent(agent)

@@ -111,3 +109,1 @@ return agent

module.exports.Config = require('./util/spmconfig.js')

@@ -40,4 +40,5 @@ /*

function getFileNameForDb () {
if (dbFileName != null)
if (dbFileName !== null) {
return dbFileName
}
if (!dbDirCreated && !fs.existsSync(DB_DIR)) {

@@ -58,6 +59,6 @@ try {

if (cluster.isMaster === false) {
dbFileName = DB_DIR + '/' + 'metrics.db.' + (cluster.worker.id || '0')
dbFileName = DB_DIR + '/' + 'metrics.db.' + (cluster.worker.id || '0') + '.' + process.pid
return dbFileName
} else {
dbFileName = DB_DIR + '/' + 'metrics.db.0'
dbFileName = DB_DIR + '/' + 'metrics.db.0.' + process.pid
return dbFileName

@@ -111,4 +112,5 @@ }

var runtime = 'io'
if (/0\.1\d\.\d+/.test(process.versions.node))
runtime = 'node'
if (/0\.1\d\.\d+/.test(process.versions.node)) {
runtime = 'node'
}
var info = os.platform() + ', ' + os.arch() + ', ' + runtime +' ' + process.versions.node + ', ' + 'spm ' + clientVersion

@@ -122,6 +124,7 @@ this.sendEvent ('server-info',{

}, function (err, result){
if (err)
if (err) {
logger.error('Error sending clientInfo Event:' + err)
else
} else {
logger.info ('SPM client info event:' + info + ' ' + result.body)
}
})

@@ -145,8 +148,10 @@ }

request.post(options, function (err, res) {
if (err)
if (err) {
self.emit('error', { source: 'sendEvent', err: err })
else
} else {
self.emit('send event', { source: 'sendEvent', event: event, err: err })
if (callback)
}
if (callback) {
callback(err, res)
}
})

@@ -187,10 +192,13 @@ }

var R = []
for (var i = 0, len = arr.length; i < len; i += chunkSize)
for (var i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize))
}
return R
}
function formatArray (a) {
if (a instanceof Array)
if (a instanceof Array) {
return a.join('\t')
else return a + ''
} else {
return a + ''
}
}

@@ -205,9 +213,11 @@ SpmSender.prototype.formatLine = function (metric) {

if (metric.sct === 'OS') {
if ((/collectd\-/.test(metric.name)))
if (/collectd\-cpu/.test(metric.name))
if ((/collectd\-/.test(metric.name))) {
if (/collectd\-cpu/.test(metric.name)) {
line = (now2 + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value)
else
} else {
line = now2 + '\t' + metric.name + '\t' + metricsTs2 + ',' + metric.value
else
}
} else {
line = (now / 1000).toFixed(0) + '\t' + metric.name + '\t' + metricsTs + ',' + metric.value
}
} else {

@@ -227,6 +237,5 @@ line = now + '\t' + 'njs-' + metric.name + '\t' + metric.ts + '\t' + (metric.workerId || 0) + '\t' + (metric.pid || 0) + '\t' + formatArray(metric.value)

metric._id = metric.name + '_' + metric.ts || new Date().getTime()
this.datapoints.push(metric)
if (this.datapoints.length > this.MAX_DATAPOINTS) {
if (this.tid != null) {
if (this.tid !== null) {
clearTimeout(this.tid)

@@ -239,3 +248,3 @@ this.tid = null

} else {
if (this.tid == null) {
if (this.tid === null) {
this.tid = setTimeout(function () {

@@ -286,16 +295,12 @@ self.tid = null

}
SpmSender.prototype.sendErrorHandler = function (err) {
SpmSender.prototype.sendErrorHandler = function () {
var self = this
db.insert(this.datapointsToShip, function (err, data) {
if (err) {
// TODO - if this fails too often we end up with a growing datapointsToShip Array, at some point we need to drop it
// we could count this error and drop the data when it fails e.g 4 times.
// The minimum data lost would be when we clean it right now - instead of let it growing
// the reason for failure could be a unique constraint, and this will not resolve when we don't drop this data
// ok - decided to remove it in any case - or investigate to evaluate the error reasons in detail ...
self.datapointsToShip.length = 0
if (!(/it violates the unique constraint/.test(err.message)))
if (!(/it violates the unique constraint/.test(err.message))) {
logger.debug('Failed to insert data points into NeDB - %s', err.message)
else
} else {
logger.debug('Data points exist already in NeDB - %s', err.message)
}
} else {

@@ -315,3 +320,3 @@ // reset datapointsToShip

if (this.datapointsToShip.length > 0) {
this.datapointsToShip.forEach(function (dp, i) {
this.datapointsToShip.forEach(function (dp) {
lines = lines + JSON.stringify({body: self.formatLine(dp)}) + '\n'

@@ -325,4 +330,5 @@ })

SpmSender.prototype.retransmit = function (metrics, callback) {
if (!metrics || metrics.length === 0)
if (!metrics || metrics.length === 0) {
return
}
var appData = metrics.filter(function (metric) {

@@ -391,6 +397,6 @@ return (metric.sct !== 'OS')

this.datapointsToShip.filter(function (metric) {
return (metric.sct != 'OS')
return (metric.sct !== 'OS')
}),
this.datapointsToShip.filter(function (metric) {
return (metric.sct == 'OS')
return (metric.sct === 'OS')
})

@@ -430,4 +436,5 @@ ]

try {
var msg = ''
if (err || (res && res.statusCode > 299) ) {
var msg = util.format('HTTP Error: %d send failed for %d data points to %s, %s', (res ? res.statusCode : -1), dpCount, url, body || err)
msg = util.format('HTTP Error: %d send failed for %d data points to %s, %s', (res ? res.statusCode : -1), dpCount, url, body || err)
if (!err) {

@@ -442,3 +449,3 @@ err = {}

} else {
var msg = util.format('HTTP: %d - %d data points successfully sent to spm-receiver %s, %s', res.statusCode, dpCount, url, '' + body)
msg = util.format('HTTP: %d - %d data points successfully sent to spm-receiver %s, %s', res.statusCode, dpCount, url, '' + body)
self.emit('send', {msg: msg, count: dpCount, url: url})

@@ -451,5 +458,4 @@ logger.info (msg)

{
url: options.url,
body: options.body,
status: res.statusCode, res: res.body
body: body,
status: res.statusCode, res: body
}, null, 4))

@@ -456,0 +462,0 @@ }

@@ -30,3 +30,3 @@ /*

}
if (logConfig.console)
if (logConfig.console) {
loggers.push(new (winston.transports.Console)({

@@ -37,6 +37,7 @@ colorize: 'all',

}))
var postfix = '.master.-' + config.tokens.spm + '-.log'
if (!cluster.isMaster)
postfix = '.worker-' + cluster.worker.id + '.-' + config.tokens.spm + '-.log'
}
var postfix = '.master.' + config.tokens.spm + '.' + process.pid + '.log'
if (!cluster.isMaster) {
postfix = '.worker' + cluster.worker.id + '.' + config.tokens.spm + '.' + process.pid + '.log'
}
if (logConfig.filename) {

@@ -43,0 +44,0 @@ loggers.push(new (winston.transports.File)({

{
"name": "spm-agent",
"version": "1.24.0",
"version": "1.24.1",
"description": "Node.js agent framework for SPM by Sematext",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

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