|
|
@ -9,10 +9,12 @@ import * as _ from 'lodash'; |
|
|
|
const parser = new ArgumentParser(); |
|
|
|
const parser = new ArgumentParser(); |
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument('-v', '--version', { action: 'version', version }); |
|
|
|
parser.add_argument('-v', '--version', { action: 'version', version }); |
|
|
|
parser.add_argument('-u', '--url', { help: 'Datasource URL', required: true }); |
|
|
|
parser.add_argument('-U', '--url', { help: 'Datasource URL', required: true }); |
|
|
|
parser.add_argument('-q', '--query', { help: 'Query Template', 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('-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' }); |
|
|
|
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 args = parser.parse_args(); |
|
|
|
|
|
|
|
|
|
|
@ -22,12 +24,19 @@ const PROMETHEUS_URL = args.url; |
|
|
|
const QUERY = args.query; |
|
|
|
const QUERY = args.query; |
|
|
|
const FROM = args.from || timeNowInMs - 5 * 60 * 1000; |
|
|
|
const FROM = args.from || timeNowInMs - 5 * 60 * 1000; |
|
|
|
const TO = args.to || timeNowInMs; |
|
|
|
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) |
|
|
|