You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
933 B
33 lines
933 B
import { PrometheusMetric } from '../metrics/prometheus_metric'; |
|
|
|
import axios from 'axios'; |
|
import * as _ from 'lodash'; |
|
|
|
|
|
// TODO: these `const`s should be CLI arguments |
|
const PROMETHEUS_URL = 'http://localhost:9090'; |
|
const FROM = 1660307430000; // ms |
|
const TO = 1660307437000; // ms |
|
|
|
const datasource = { |
|
type: 'prometheus', |
|
url: 'api/v1/query_range?query=100-(avg by (instance) (irate(node_cpu_seconds_total{job="nvicta-ai-node-exporter",mode="idle"}[5m])) * 100)&start=1543411320&end=1543432950&step=30' |
|
} |
|
const targets = []; |
|
const prometheus = new PrometheusMetric(datasource, targets); |
|
|
|
const query = prometheus.getQuery(FROM, TO, 1000, 0); |
|
const axiosQuery = { |
|
url: `${PROMETHEUS_URL}/${query.url}`, |
|
method: query.method, |
|
}; |
|
_.defaults(axiosQuery, query.schema); |
|
|
|
axios(axiosQuery) |
|
.then(resp => { |
|
console.log(prometheus.getResults(resp)); |
|
}) |
|
.catch(err => { |
|
console.error('Query error: ', err); |
|
}); |
|
|
|
|