|
|
|
@ -2,14 +2,26 @@ import { queryByConfig, QueryConfig } from '..';
|
|
|
|
|
|
|
|
|
|
import { DatasourceType, QueryType } from '../connectors'; |
|
|
|
|
|
|
|
|
|
import { ArgumentParser } from 'argparse'; |
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
const parser = new ArgumentParser(); |
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// TODO: parse version from package.json
|
|
|
|
|
parser.add_argument('-v', '--version', { action: 'version', version: '0.1.1' }); |
|
|
|
|
parser.add_argument('-u', '--url', { help: 'Datasource URL', required: true }); |
|
|
|
|
parser.add_argument('-q', '--query', { help: 'Query Template', required: true }); |
|
|
|
|
parser.add_argument('-f', '--from', { help: 'From timestamp (ms), e.g. 1660670020000. If not specified, `now-5m` is used' }); |
|
|
|
|
parser.add_argument('-t', '--to', { help: 'To timestamp (ms), e.g. 1660670026000. If not specified, `now` is used' }); |
|
|
|
|
|
|
|
|
|
const args = parser.parse_args(); |
|
|
|
|
|
|
|
|
|
const timeNowInMs = new Date().getTime(); |
|
|
|
|
|
|
|
|
|
const PROMETHEUS_URL = args.url; |
|
|
|
|
const QUERY = args.query; |
|
|
|
|
const FROM = args.from || timeNowInMs - 5 * 60 * 1000; |
|
|
|
|
const TO = args.to || timeNowInMs; |
|
|
|
|
|
|
|
|
|
const datasource = { |
|
|
|
|
type: DatasourceType.PROMETHEUS, |
|
|
|
|