Commit 6ed1cbd5 by Mitsuhiro Tanda

set unit for CloudWatch GetMetricStatistics result

parent c1fd2e55
...@@ -362,6 +362,7 @@ func (e *CloudWatchExecutor) executeGetMetricDataQuery(ctx context.Context, regi ...@@ -362,6 +362,7 @@ func (e *CloudWatchExecutor) executeGetMetricDataQuery(ctx context.Context, regi
} }
queryRes.Series = append(queryRes.Series, &series) queryRes.Series = append(queryRes.Series, &series)
queryRes.Meta = simplejson.New()
queryResponses = append(queryResponses, queryRes) queryResponses = append(queryResponses, queryRes)
} }
...@@ -565,6 +566,12 @@ func parseResponse(resp *cloudwatch.GetMetricStatisticsOutput, query *CloudWatch ...@@ -565,6 +566,12 @@ func parseResponse(resp *cloudwatch.GetMetricStatisticsOutput, query *CloudWatch
} }
queryRes.Series = append(queryRes.Series, &series) queryRes.Series = append(queryRes.Series, &series)
queryRes.Meta = simplejson.New()
if len(resp.Datapoints) > 0 && resp.Datapoints[0].Unit != nil {
if unit, ok := cloudwatchUnitMappings[*resp.Datapoints[0].Unit]; ok {
queryRes.Meta.Set("unit", unit)
}
}
} }
return queryRes, nil return queryRes, nil
......
package cloudwatch
var cloudwatchUnitMappings = map[string]string{
"Seconds": "s",
"Microseconds": "µs",
"Milliseconds": "ms",
"Bytes": "bytes",
"Kilobytes": "kbytes",
"Megabytes": "mbytes",
"Gigabytes": "gbytes",
//"Terabytes": "",
"Bits": "bits",
//"Kilobits": "",
//"Megabits": "",
//"Gigabits": "",
//"Terabits": "",
"Percent": "percent",
//"Count": "",
"Bytes/Second": "Bps",
"Kilobytes/Second": "KBs",
"Megabytes/Second": "MBs",
"Gigabytes/Second": "GBs",
//"Terabytes/Second": "",
"Bits/Second": "bps",
"Kilobits/Second": "Kbits",
"Megabits/Second": "Mbits",
"Gigabits/Second": "Gbits",
//"Terabits/Second": "",
//"Count/Second": "",
}
...@@ -131,7 +131,7 @@ export default class CloudWatchDatasource { ...@@ -131,7 +131,7 @@ export default class CloudWatchDatasource {
if (res.results) { if (res.results) {
_.forEach(res.results, queryRes => { _.forEach(res.results, queryRes => {
_.forEach(queryRes.series, series => { _.forEach(queryRes.series, series => {
data.push({ target: series.name, datapoints: series.points }); data.push({ target: series.name, datapoints: series.points, unit: queryRes.meta.unit || 'none' });
}); });
}); });
} }
......
...@@ -60,6 +60,7 @@ describe('CloudWatchDatasource', () => { ...@@ -60,6 +60,7 @@ describe('CloudWatchDatasource', () => {
A: { A: {
error: '', error: '',
refId: 'A', refId: 'A',
meta: {},
series: [ series: [
{ {
name: 'CPUUtilization_Average', name: 'CPUUtilization_Average',
...@@ -221,6 +222,7 @@ describe('CloudWatchDatasource', () => { ...@@ -221,6 +222,7 @@ describe('CloudWatchDatasource', () => {
A: { A: {
error: '', error: '',
refId: 'A', refId: 'A',
meta: {},
series: [ series: [
{ {
name: 'TargetResponseTime_p90.00', name: 'TargetResponseTime_p90.00',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment