-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (52 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const appmetrics = require('appmetrics');
const Influx = require('influx');
const app = express();
const monitoring = appmetrics.monitor();
const influx = new Influx.InfluxDB({
host: 'influxsrx',
port: 8086,
database: 'cadvisor',
username: 'admin',
password: 'admin',
schema: [
{
measurement: 'memory',
fields: {
physical_total: Influx.FieldType.INTEGER,
physical_used: Influx.FieldType.INTEGER,
virtual: Influx.FieldType.INTEGER,
physical: Influx.FieldType.INTEGER,
},
tags: [],
}
]
});
monitoring.on('memory', function ({ physical_total, physical_used, virtual, physical }) {
influx.writePoints([
{
measurement: 'memory',
tags: [],
fields: { physical_total, physical_used, virtual, physical },
}
]).catch(err => {
console.error(`Error saving data to InfluxDB! ${err.stack}`)
})
});
monitoring.on('cpu', function ({ process }) {
influx.writePoints([
{
measurement: 'node_cpu',
tags: [],
fields: { process },
}
]).catch(err => {
console.error(`Error saving data to InfluxDB! ${err.stack}`)
})
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(6001, function () {
console.log('Example app listening on port 6001!');
});