Browse Source

sample bin file

pull/1/head
rozetko 2 years ago
parent
commit
de97390d1e
  1. 34
      src/tsdb-kit/index.ts

34
src/tsdb-kit/index.ts

@ -1 +1,33 @@
console.log('Hello world'); 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);
});

Loading…
Cancel
Save