|
|
@ -2,20 +2,41 @@ import { queryByConfig, QueryConfig } from '..'; |
|
|
|
|
|
|
|
|
|
|
|
import { DatasourceType, QueryType } from '../connectors'; |
|
|
|
import { DatasourceType, QueryType } from '../connectors'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { version } = require('../../package.json') |
|
|
|
|
|
|
|
import { ArgumentParser } from 'argparse'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parser = new ArgumentParser(); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: these `const`s should be CLI arguments
|
|
|
|
parser.add_argument('-v', '--version', { action: 'version', version }); |
|
|
|
const PROMETHEUS_URL = 'http://localhost:9090'; |
|
|
|
parser.add_argument('-U', '--url', { help: 'Datasource URL', required: true }); |
|
|
|
const QUERY = '100-(avg by (instance) (irate(node_cpu_seconds_total{job="nvicta-ai-node-exporter",mode="idle"}[5m])) * 100)'; |
|
|
|
parser.add_argument('-q', '--query', { help: 'Query Template', required: true }); |
|
|
|
const FROM = 1660670020000; // ms
|
|
|
|
parser.add_argument('-f', '--from', { help: 'From timestamp (ms), e.g. 1660670020000. If not specified, `now-5m` is used' }); |
|
|
|
const TO = 1660670026000; // ms
|
|
|
|
parser.add_argument('-t', '--to', { help: 'To timestamp (ms), e.g. 1660670026000. If not specified, `now` is used' }); |
|
|
|
|
|
|
|
parser.add_argument('-u', '--username', { help: 'Basic Auth Username' }); |
|
|
|
|
|
|
|
parser.add_argument('-p', '--password', { help: 'Basic Auth Password' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 USERNAME = args.username; |
|
|
|
|
|
|
|
const PASSWORD = args.password; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let auth; |
|
|
|
|
|
|
|
if(USERNAME && PASSWORD) { |
|
|
|
|
|
|
|
auth = { username: USERNAME, password: PASSWORD }; |
|
|
|
|
|
|
|
} |
|
|
|
const datasource = { |
|
|
|
const datasource = { |
|
|
|
type: DatasourceType.PROMETHEUS, |
|
|
|
type: DatasourceType.PROMETHEUS, |
|
|
|
// TODO: remove PROMETHEUS_URL from here
|
|
|
|
// TODO: remove PROMETHEUS_URL from here
|
|
|
|
url: `${PROMETHEUS_URL}/api/v1/query_range?query=${QUERY}&start=1543411320&end=1543432950&step=30` |
|
|
|
url: `${PROMETHEUS_URL}/api/v1/query_range?query=${QUERY}&start=1543411320&end=1543432950&step=30`, |
|
|
|
} |
|
|
|
auth, |
|
|
|
|
|
|
|
}; |
|
|
|
const targets = []; |
|
|
|
const targets = []; |
|
|
|
const queryConfig = new QueryConfig(QueryType.DIRECT, datasource, targets); |
|
|
|
const queryConfig = new QueryConfig(QueryType.DIRECT, datasource, targets); |
|
|
|
queryByConfig(queryConfig, PROMETHEUS_URL, FROM, TO) |
|
|
|
queryByConfig(queryConfig, PROMETHEUS_URL, FROM, TO) |
|
|
|