mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: convert most common stackdriver units to grafana units if possible
This commit is contained in:
@@ -253,3 +253,19 @@ export const alignmentPeriods = [
|
||||
{ text: '1d', value: '+86400s' },
|
||||
{ text: '1w', value: '+604800s' },
|
||||
];
|
||||
|
||||
export const stackdriverUnitMappings = {
|
||||
bit: 'bits',
|
||||
By: 'bytes',
|
||||
s: 's',
|
||||
min: 'm',
|
||||
h: 'h',
|
||||
d: 'd',
|
||||
us: 'µs',
|
||||
ms: 'ms',
|
||||
ns: 'ns',
|
||||
percent: 'percent',
|
||||
MiBy: 'mbytes',
|
||||
'By/s': 'Bps',
|
||||
GBy: 'decgbytes',
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { stackdriverUnitMappings } from './constants';
|
||||
/** @ngInject */
|
||||
export default class StackdriverDatasource {
|
||||
id: number;
|
||||
@@ -85,6 +86,16 @@ export default class StackdriverDatasource {
|
||||
return interpolatedGroupBys;
|
||||
}
|
||||
|
||||
resolveUnit(targets: any[]) {
|
||||
let unit = 'none';
|
||||
if (targets.length > 0 && targets.every(t => t.unit === targets[0].unit)) {
|
||||
if (stackdriverUnitMappings.hasOwnProperty(targets[0].unit)) {
|
||||
unit = stackdriverUnitMappings[targets[0].unit];
|
||||
}
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
|
||||
async query(options) {
|
||||
const result = [];
|
||||
const data = await this.getTimeSeries(options);
|
||||
@@ -93,12 +104,15 @@ export default class StackdriverDatasource {
|
||||
if (!queryRes.series) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unit = this.resolveUnit(options.targets);
|
||||
queryRes.series.forEach(series => {
|
||||
result.push({
|
||||
target: series.name,
|
||||
datapoints: series.points,
|
||||
refId: queryRes.refId,
|
||||
meta: queryRes.meta,
|
||||
unit,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
unit: string;
|
||||
metricType: string;
|
||||
service: string;
|
||||
refId: string;
|
||||
@@ -47,6 +48,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
||||
metricType: this.defaultDropdownValue,
|
||||
service: this.defaultServiceValue,
|
||||
metric: '',
|
||||
unit: '',
|
||||
aggregation: {
|
||||
crossSeriesReducer: 'REDUCE_MEAN',
|
||||
alignmentPeriod: 'auto',
|
||||
@@ -221,7 +223,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
||||
|
||||
setMetricType() {
|
||||
this.target.metricType = this.metricType;
|
||||
const { valueType, metricKind } = this.metricDescriptors.find(m => m.type === this.target.metricType);
|
||||
const { valueType, metricKind, unit } = this.metricDescriptors.find(m => m.type === this.target.metricType);
|
||||
this.target.unit = unit;
|
||||
this.target.valueType = valueType;
|
||||
this.target.metricKind = metricKind;
|
||||
this.$scope.$broadcast('metricTypeChanged');
|
||||
|
||||
Reference in New Issue
Block a user