Browse Source

upd types

pull/1/head
rozetko 2 years ago
parent
commit
fbf6c4949f
  1. 1
      src/index.ts
  2. 5
      src/metrics/metric.ts
  3. 13
      src/metrics/prometheus_metric.ts

1
src/index.ts

@ -1,3 +1,4 @@
export { Metric } from './metrics/metrics_factory';
export { Datasource } from './metrics/metric'
// TODO: move queryByMetric from Grafana service
export { queryByMetric, GrafanaUnavailable, DatasourceUnavailable } from './grafana_service';

5
src/metrics/metric.ts

@ -1,5 +1,6 @@
export declare type Datasource = {
url: string;
// TODO: type: enum
type: string;
params?: {
db: string;
@ -18,8 +19,8 @@ export type MetricQuery = {
}
export type MetricResults = {
values: any;
columns: any;
values: (number | null)[][];
columns: string[];
}
export type MetricId = string;

13
src/metrics/prometheus_metric.ts

@ -36,13 +36,13 @@ export class PrometheusMetric extends AbstractMetric {
}
let result = res.data.data.result;
let result_matrix = {
let result_matrix: MetricResults = {
columns: ['timestamp'],
values: []
};
result.map(r => {
let keys = [];
let keys: string[] = [];
for(let key in r.metric) {
keys.push(`${key}=${r.metric[key]}`);
}
@ -51,8 +51,8 @@ export class PrometheusMetric extends AbstractMetric {
let values = result.map(r => r.values);
let timestamps = [];
values.map(v => v.map(row => timestamps.push(row[0])));
let timestamps: (number | null)[] = [];
values.forEach(v => v.forEach((row: number[]) => timestamps.push(row[0])));
timestamps = timestamps.filter(function(item, i, ar) {
return ar.indexOf(item) === i; //uniq values
});
@ -70,12 +70,11 @@ export class PrometheusMetric extends AbstractMetric {
if(currentTimestamp === t) {
row.push(+currentValue);
v.shift();
}
else {
} else {
row.push(null);
}
});
row[0] = +row[0] * 1000; //convert timestamp to ms
row[0] = +(row[0] as number) * 1000; //convert timestamp to ms
result_matrix.values.push(row);
};
return result_matrix;

Loading…
Cancel
Save