Skip to content

Instantly share code, notes, and snippets.

@megastef
Created November 14, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megastef/0c86cd7c0e3f3e7ae8d0b3e763687f1c to your computer and use it in GitHub Desktop.
Save megastef/0c86cd7c0e3f3e7ae8d0b3e763687f1c to your computer and use it in GitHub Desktop.
Ship metrics to with Node.js InfluxDB client to Sematext Cloud
const Influx = require('influx')
const os = require('os')
const influx = new Influx.InfluxDB({
host: 'spm-receiver.sematext.com',
port: 443,
database: 'metrics',
protocol: 'https'
})
setInterval(() => {
var memoryUsage = process.memoryUsage()
var cpuUsage = process.cpuUsage()
var tags = {
'os.host': os.hostname(),
token: process.env.MONITORING_TOKEN
PID: process.pid,
nodeVersion: process.version,
user: process.env.USER
}
influx.writePoints([
{
measurement: 'myapp.process.memory',
tags: tags,
fields: { rss: memoryUsage.rss, heapTotal: memoryUsage.heapTotal, heapUsed: memoryUsage.heapUsed }
},
{
measurement: 'myapp.process.cpu',
tags: tags,
fields: { system: cpuUsage.system, user: cpuUsage.user }
}
]).then(() => {
console.log('ok')
}).catch((err) => {
console.error('Error', err)
})
}, 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment