-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
73 lines (58 loc) · 2.09 KB
/
test.js
File metadata and controls
73 lines (58 loc) · 2.09 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
const test = require('tape')
const path = require('path')
const collector = require('.')
const sockstatPath = path.join(__dirname, 'sockstat_fixture')
test('emits all metrics by default', function (t) {
t.plan(2)
const c = collector({ sockstatPath })
const metrics = []
const common = { unit: 'count', resolution: 60, tags: {} }
const expect = (name, value) => Object.assign({ name, value }, common)
c.on('metric', metrics.push.bind(metrics))
c.ping((err) => {
t.ifError(err, 'no ping error')
t.same(metrics.map(simplify), [
expect('telemetry.sockstat.tcp.inuse.count', 30426),
expect('telemetry.sockstat.tcp.orphan.count', 55),
expect('telemetry.sockstat.tcp.time_wait.count', 337),
expect('telemetry.sockstat.tcp.alloc.count', 30430),
expect('telemetry.sockstat.tcp.mem.count', 21042)
])
})
})
test('can filter metrics with wildcard', function (t) {
t.plan(2)
const c = collector({ sockstatPath, metrics: ['telemetry.sockstat.tcp.alloc.*', '*.time_wait.count'] })
const metrics = []
const common = { unit: 'count', resolution: 60, tags: {} }
const expect = (name, value) => Object.assign({ name, value }, common)
c.on('metric', metrics.push.bind(metrics))
c.ping((err) => {
t.ifError(err, 'no ping error')
t.same(metrics.map(simplify), [
// Order is dictated by pattern order
expect('telemetry.sockstat.tcp.alloc.count', 30430),
expect('telemetry.sockstat.tcp.time_wait.count', 337)
])
})
})
test('can filter metrics with single name', function (t) {
t.plan(2)
const c = collector({ sockstatPath, metrics: ['telemetry.sockstat.tcp.orphan.count'] })
const metrics = []
const common = { unit: 'count', resolution: 60, tags: {} }
const expect = (name, value) => Object.assign({ name, value }, common)
c.on('metric', metrics.push.bind(metrics))
c.ping((err) => {
t.ifError(err, 'no ping error')
t.same(metrics.map(simplify), [
expect('telemetry.sockstat.tcp.orphan.count', 55)
])
})
})
function simplify (metric) {
delete metric.date
delete metric.statistic
return metric
}