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.
 
 

28 lines
891 B

import { queryByConfig, QueryConfig } from '..';
import { DatasourceType, QueryType } from '../connectors';
import * as _ from 'lodash';
// TODO: these `const`s should be CLI arguments
const PROMETHEUS_URL = 'http://localhost:9090';
const QUERY = '100-(avg by (instance) (irate(node_cpu_seconds_total{job="nvicta-ai-node-exporter",mode="idle"}[5m])) * 100)';
const FROM = 1660670020000; // ms
const TO = 1660670026000; // ms
const datasource = {
type: DatasourceType.PROMETHEUS,
// TODO: remove PROMETHEUS_URL from here
url: `${PROMETHEUS_URL}/api/v1/query_range?query=${QUERY}&start=1543411320&end=1543432950&step=30`
}
const targets = [];
const queryConfig = new QueryConfig(QueryType.DIRECT, datasource, targets);
queryByConfig(queryConfig, PROMETHEUS_URL, FROM, TO)
.then(res => {
console.log(res);
})
.catch(err => {
console.error('Query error: ', err);
});