forked from hharnisc/kubescope-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (45 loc) · 1.41 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
var stats = require('@hharnisc/docker-stats')
var through = require('through2')
var tr = require('@hharnisc/turtle-race')
const { stdin } = require('ttys')
const emptyStatsMessage = 'Waiting For Stats...'
const turtle = tr({
input: stdin,
metrics: {
'cpu percent': {
min: 0,
displayMetric: true,
metricFmt: (metric) => `${metric.toFixed(2)}%`,
},
'memory percent': {
min: 0,
displayMetric: true,
metricFmt: (metric) => `${metric.toFixed(2)}%`,
},
},
pruneStale: true,
pruneInterval: 5,
emptyStatsMessage,
})
turtle.message(emptyStatsMessage)
stats({
statsinterval: parseInt(process.env.STATS_INTERVAL || 1, 10),
matchByName: new RegExp(process.env.MATCH_NAME),
matchByImage: process.env.MATCH_IMAGE ?
new RegExp(process.env.MATCH_IMAGE) : undefined,
skipByName: process.env.SKIP_NAME ?
new RegExp(process.env.SKIP_NAME) : undefined,
skipByImage: process.env.SKIP_IMAGE ?
new RegExp(process.env.SKIP_IMAGE) : undefined,
}).pipe(through.obj((container, enc, cb) => {
const cpuPercent = container.stats.cpu_stats.cpu_usage.cpu_percent
const memoryPercent = (container.stats.memory_stats.usage / container.stats.memory_stats.limit) * 100;
turtle
.metric(container.name, 'cpu percent')
.push(cpuPercent)
turtle
.metric(container.name, 'memory percent')
.push(memoryPercent)
turtle.message('')
return cb();
}));