Browse Source

init CLI arguments

pull/8/head
rozetko 2 years ago
parent
commit
82dfc20b2f
  1. 1
      package.json
  2. 22
      src/tsdb-kit/index.ts
  3. 2
      webpack.config.js
  4. 5
      yarn.lock

1
package.json

@ -32,6 +32,7 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.15", "@types/jest": "^26.0.15",
"@types/lodash": "^4.14.165", "@types/lodash": "^4.14.165",
"argparse": "^2.0.1",
"jest": "^26.6.3", "jest": "^26.6.3",
"ts-jest": "^26.4.4", "ts-jest": "^26.4.4",
"ts-loader": "^9.3.1", "ts-loader": "^9.3.1",

22
src/tsdb-kit/index.ts

@ -2,14 +2,26 @@ import { queryByConfig, QueryConfig } from '..';
import { DatasourceType, QueryType } from '../connectors'; import { DatasourceType, QueryType } from '../connectors';
import { ArgumentParser } from 'argparse';
import * as _ from 'lodash'; import * as _ from 'lodash';
const parser = new ArgumentParser();
// TODO: these `const`s should be CLI arguments // TODO: parse version from package.json
const PROMETHEUS_URL = 'http://localhost:9090'; parser.add_argument('-v', '--version', { action: 'version', version: '0.1.1' });
const QUERY = '100-(avg by (instance) (irate(node_cpu_seconds_total{job="nvicta-ai-node-exporter",mode="idle"}[5m])) * 100)'; parser.add_argument('-u', '--url', { help: 'Datasource URL', required: true });
const FROM = 1660670020000; // ms parser.add_argument('-q', '--query', { help: 'Query Template', required: true });
const TO = 1660670026000; // ms 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 = { const datasource = {
type: DatasourceType.PROMETHEUS, type: DatasourceType.PROMETHEUS,

2
webpack.config.js

@ -18,7 +18,7 @@ module.exports = {
module: { module: {
rules: [ rules: [
{ {
test: /.ts?$/, test: /.ts$/,
loader: 'ts-loader', loader: 'ts-loader',
options: { options: {
configFile: 'bin.tsconfig.json' configFile: 'bin.tsconfig.json'

5
yarn.lock

@ -905,6 +905,11 @@ argparse@^1.0.7:
dependencies: dependencies:
sprintf-js "~1.0.2" sprintf-js "~1.0.2"
argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
arr-diff@^4.0.0: arr-diff@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"

Loading…
Cancel
Save