|
|
@ -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 |
|
|
|
if(value === null || value === undefined) { |
|
|
|
? this.getLastValueFromMetrics(threshold.metricName, `Threshold ${idx + 1}`) |
|
|
|
|
|
|
|
: threshold.value; |
|
|
|
|
|
|
|
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, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -88,14 +88,14 @@ export class Options { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _areIconConditionsFulfilled(icon: Icon, iconIdx: number): boolean { |
|
|
|
private _areIconConditionsFulfilled(icon: Icon, iconIdx: number): boolean { |
|
|
|
if(_.isEmpty(icon.metrics)) { |
|
|
|
if (_.isEmpty(icon.metrics)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// check each condition and return false if something goes wrong
|
|
|
|
// check each condition and return false if something goes wrong
|
|
|
|
for (let [conditionIdx, metric] of icon.metrics.entries()) { |
|
|
|
for (let [conditionIdx, metric] of icon.metrics.entries()) { |
|
|
|
const value = this.getLastValueFromMetrics(metric, `Icon ${iconIdx + 1}, Condition ${conditionIdx + 1}`); |
|
|
|
const value = this.getLastValueFromMetrics(metric, `Icon ${iconIdx + 1}, Condition ${conditionIdx + 1}`); |
|
|
|
if(value === null || value === undefined) { |
|
|
|
if (value === null || value === undefined) { |
|
|
|
// TODO: may be throw an error
|
|
|
|
// TODO: may be throw an error
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -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); |
|
|
|