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