-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathapp.ts
70 lines (59 loc) · 2.25 KB
/
app.ts
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
import { PrometheusDriver, Alert, Metric, QueryResult } from '../../';
const prom = new PrometheusDriver({
endpoint: 'https://prometheus.demo.do.prometheus.io/',
// endpoint: 'http://localhost:9090/',
});
const query = 'up{instance="demo.do.prometheus.io:9090",job="prometheus"}';
// const query = 'up{}';
// last value
prom.instantQuery(query)
.then((res: QueryResult) => {
console.log("****************", "[instantQuery] Query:", query, "****************")
console.log("\n");
const series = res.result;
series.forEach((serie) => {
console.log("[instantQuery] Serie:", serie.metric.toString());
console.log("[instantQuery] Time:", serie.value.time);
console.log("[instantQuery] Value:", serie.value.value);
console.log("\n");
});
})
.catch(console.error);
// during past 24h, 1 point every 6 hours
prom.rangeQuery(query, new Date().getTime() - 24 * 60 * 60 * 1000, new Date(), 6 * 60 * 60)
.then((res: QueryResult) => {
console.log("****************", "[rangeQuery] Query:", query, "****************");
console.log("\n");
const series = res.result;
series.forEach((serie) => {
console.log("[rangeQuery] Serie:", serie.metric.toString());
console.log("[rangeQuery] Values:\n" + serie.values.join('\n'));
console.log("\n");
});
})
.catch(console.error);
// list series matching query
prom.series(query, new Date().getTime() - 24 * 60 * 60 * 1000, new Date())
.then((res: Metric[]) => {
console.log("****************", "[series] matching:", query, "****************");
console.log('[series] Series:');
console.log(res.join('\n'));
console.log("\n");
})
.catch(console.error);
// list all active alerts
prom.alerts()
.then((res: Alert[]) => {
console.log("****************", "[alerts]", "****************");
console.log(res)
console.log("\n");
})
.catch(console.error);
// list all active alerts
prom.labelValues("instance")
.then((res: string[]) => {
console.log("****************", "[alerts]", "****************");
console.log(res)
console.log("\n");
})
.catch(console.error);