Created
November 14, 2019 12:22
-
-
Save megastef/0c86cd7c0e3f3e7ae8d0b3e763687f1c to your computer and use it in GitHub Desktop.
Ship metrics to with Node.js InfluxDB client to Sematext Cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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