|
|
@ -7,7 +7,7 @@ import TimeSeries from 'grafana/app/core/time_series2'; |
|
|
|
|
|
|
|
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
export function formatValue(value: number, options: { unit?: string, decimals?: number }): string { |
|
|
|
export function formatValue(value: number, options: { unit?: string; decimals?: number }): string { |
|
|
|
const suffix = getValueFormat(options.unit)(0)?.suffix || ''; |
|
|
|
const suffix = getValueFormat(options.unit)(0)?.suffix || ''; |
|
|
|
const decimals = _.isNumber(options.decimals) ? options.decimals : 2; |
|
|
|
const decimals = _.isNumber(options.decimals) ? options.decimals : 2; |
|
|
|
return `${value.toFixed(decimals)} ${suffix}`; |
|
|
|
return `${value.toFixed(decimals)} ${suffix}`; |
|
|
@ -24,7 +24,7 @@ export function getGrafanaSeriesList(grafanaData: PanelData, timeRange: TimeRang |
|
|
|
export function getLastMetricValue( |
|
|
|
export function getLastMetricValue( |
|
|
|
grafanaSeriesList: TimeSeries[], |
|
|
|
grafanaSeriesList: TimeSeries[], |
|
|
|
metricName: string | undefined, |
|
|
|
metricName: string | undefined, |
|
|
|
optionName: string, |
|
|
|
optionName: string |
|
|
|
): number | null { |
|
|
|
): number | null { |
|
|
|
// optionName -> helper in Error, mb use option path instead
|
|
|
|
// optionName -> helper in Error, mb use option path instead
|
|
|
|
const filteredSeries = filterMetricListByAlias(grafanaSeriesList, metricName, optionName); |
|
|
|
const filteredSeries = filterMetricListByAlias(grafanaSeriesList, metricName, optionName); |
|
|
@ -34,7 +34,7 @@ export function getLastMetricValue( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function filterMetricListByAlias(list: any[], alias: string | undefined, option: string): any[] { |
|
|
|
export function filterMetricListByAlias(list: any[], alias: string | undefined, option: string): any[] { |
|
|
|
console.log(list) |
|
|
|
console.log(list); |
|
|
|
const filteredSeries = _.filter(list, (serie) => serie.alias === alias); |
|
|
|
const filteredSeries = _.filter(list, (serie) => serie.alias === alias); |
|
|
|
if (filteredSeries.length === 0) { |
|
|
|
if (filteredSeries.length === 0) { |
|
|
|
throw new Error(`${option}: Can't find metric for ${alias} name.`); |
|
|
|
throw new Error(`${option}: Can't find metric for ${alias} name.`); |
|
|
|