|
|
@ -6,14 +6,12 @@ import { getValueFormat } from '@grafana/data'; |
|
|
|
|
|
|
|
|
|
|
|
import _ from 'lodash'; |
|
|
|
import _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convert Grafana options into Chartwerk Gauge options
|
|
|
|
// Convert Grafana options into Chartwerk Gauge options
|
|
|
|
export class Options { |
|
|
|
export class Options { |
|
|
|
private minValue: number | undefined; |
|
|
|
private minValue: number | undefined; |
|
|
|
private maxValue: number | undefined; |
|
|
|
private maxValue: number | undefined; |
|
|
|
private thresholds: { value: number, color: string }[] = []; |
|
|
|
private thresholds: Array<{ value: number; color: string }> = []; |
|
|
|
private icons: { src: string, position: string, size: number}[] = []; |
|
|
|
private icons: Array<{ src: string; position: string; size: number }> = []; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private grafanaSeriesList: any[], private grafanaOptions: PanelOptions) { |
|
|
|
constructor(private grafanaSeriesList: any[], private grafanaOptions: PanelOptions) { |
|
|
|
this._setMin(); |
|
|
|
this._setMin(); |
|
|
@ -50,14 +48,16 @@ export class Options { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _setThreshold(threshold: Threshold, idx: number): void { |
|
|
|
private _setThreshold(threshold: Threshold, idx: number): void { |
|
|
|
const value = threshold.useMetric ? this.getLastValueFromMetrics(threshold.metricName, `Threshold ${idx + 1}`) : threshold.value; |
|
|
|
const value = threshold.useMetric |
|
|
|
|
|
|
|
? this.getLastValueFromMetrics(threshold.metricName, `Threshold ${idx + 1}`) |
|
|
|
|
|
|
|
: threshold.value; |
|
|
|
if (value === null || value === undefined) { |
|
|
|
if (value === null || value === undefined) { |
|
|
|
// TODO: may be throw an error
|
|
|
|
// TODO: may be throw an error
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.thresholds.push({ |
|
|
|
this.thresholds.push({ |
|
|
|
value, |
|
|
|
value, |
|
|
|
color: threshold.color |
|
|
|
color: threshold.color, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -157,11 +157,7 @@ export class Options { |
|
|
|
|
|
|
|
|
|
|
|
getLastValueFromMetrics(metricName: string | undefined, optionName: string): number | null { |
|
|
|
getLastValueFromMetrics(metricName: string | undefined, optionName: string): number | null { |
|
|
|
// optionName -> helper in Error, mb use option path instead
|
|
|
|
// optionName -> helper in Error, mb use option path instead
|
|
|
|
const filteredSeries = filterMetricListByAlias( |
|
|
|
const filteredSeries = filterMetricListByAlias(this.grafanaSeriesList, metricName, optionName); |
|
|
|
this.grafanaSeriesList, |
|
|
|
|
|
|
|
metricName, |
|
|
|
|
|
|
|
optionName |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const serie = filteredSeries[0]; |
|
|
|
const serie = filteredSeries[0]; |
|
|
|
// Last value for now
|
|
|
|
// Last value for now
|
|
|
|
return getAggregatedValueFromSerie(serie, Aggregation.LAST); |
|
|
|
return getAggregatedValueFromSerie(serie, Aggregation.LAST); |
|
|
|