|
|
@ -1,5 +1,5 @@ |
|
|
|
import { queryByMetric, Datasource, Metric } from 'grafana-datasource-kit'; |
|
|
|
import { queryByMetric, Datasource, Metric } from 'grafana-datasource-kit'; |
|
|
|
import { getApiKey } from './config'; |
|
|
|
import { apiKeys } from './config'; |
|
|
|
|
|
|
|
|
|
|
|
import * as csv from 'fast-csv'; |
|
|
|
import * as csv from 'fast-csv'; |
|
|
|
import * as path from 'path'; |
|
|
|
import * as path from 'path'; |
|
|
@ -7,7 +7,6 @@ import * as fs from 'fs'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
import { URL } from 'url'; |
|
|
|
import { URL } from 'url'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MS_IN_DAY = 24 * 60 * 60 * 1000; |
|
|
|
const MS_IN_DAY = 24 * 60 * 60 * 1000; |
|
|
|
|
|
|
|
|
|
|
|
export class Target { |
|
|
|
export class Target { |
|
|
@ -29,6 +28,7 @@ export class Target { |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.metric = new Metric(datasource, targets); |
|
|
|
this.metric = new Metric(datasource, targets); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public updateStatus(status) { |
|
|
|
public updateStatus(status) { |
|
|
|
let time = moment().valueOf(); |
|
|
|
let time = moment().valueOf(); |
|
|
@ -68,7 +68,12 @@ export class Target { |
|
|
|
|
|
|
|
|
|
|
|
console.log(`${this.day} day: ${from}ms -> ${to}ms`); |
|
|
|
console.log(`${this.day} day: ${from}ms -> ${to}ms`); |
|
|
|
|
|
|
|
|
|
|
|
let apiKey = getApiKey(new URL(this.panelUrl).origin); |
|
|
|
let host = new URL(this.panelUrl).origin; |
|
|
|
|
|
|
|
let apiKey = apiKeys[host]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(apiKey === undefined || apiKey === '') { |
|
|
|
|
|
|
|
throw new Error(`Please configure API key for ${host}`); |
|
|
|
|
|
|
|
} |
|
|
|
let metrics = await queryByMetric(this.metric, this.panelUrl, from, to, apiKey); |
|
|
|
let metrics = await queryByMetric(this.metric, this.panelUrl, from, to, apiKey); |
|
|
|
|
|
|
|
|
|
|
|
if(metrics.values.length > 0) { |
|
|
|
if(metrics.values.length > 0) { |
|
|
@ -89,7 +94,7 @@ export class Target { |
|
|
|
|
|
|
|
|
|
|
|
this.csvStream.pipe(writableStream); |
|
|
|
this.csvStream.pipe(writableStream); |
|
|
|
writableStream.on('finish', async () => { |
|
|
|
writableStream.on('finish', async () => { |
|
|
|
console.log('Everything is written'); |
|
|
|
console.log(`Everything is written to ${this.getFilename('csv')}`); |
|
|
|
await this.updateStatus('finished'); |
|
|
|
await this.updateStatus('finished'); |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|