-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
38 lines (30 loc) · 1.25 KB
/
example.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
import prometheus from 'k6/x/prometheusread';
export default function () {
query()
queryRange()
}
function query (){
console.log("Query Sample")
var client = prometheus.newPrometheusClient("http://demo.robustperception.io:9090", "user", "password")
var response = client.query("alertmanager_notifications_total")
response.forEach(item => {
var jsonBytes = item.marshalJSON()
var {metric, value} = JSON.parse(String.fromCharCode(...jsonBytes))
console.log(metric.__name__) // show metric name
console.log(value[1]) // show metric value
});
}
function queryRange (){
console.log("QueryRange Sample")
var client = prometheus.newPrometheusClient("http://demo.robustperception.io:9090", "user", "password")
var end = new Date()
var start = new Date(end.getTime() - 5 * 60000)
var period = "minute"
var response = client.queryRange("rate(prometheus_tsdb_head_samples_appended_total[5m])", start.toISOString(), end.toISOString(), period)
response.forEach(item => {
var jsonBytes = item.marshalJSON()
var {metric, values} = JSON.parse(String.fromCharCode(...jsonBytes))
console.log(metric) // show metric
console.log(values) // show metric values
});
}