mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure: convert azure units to grafana units (#26429)
This commit is contained in:
parent
c208c7cabe
commit
5d09e4539c
@ -294,7 +294,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A
|
|||||||
dataField.Name = amr.Value[0].Name.LocalizedValue
|
dataField.Name = amr.Value[0].Name.LocalizedValue
|
||||||
dataField.Labels = labels
|
dataField.Labels = labels
|
||||||
dataField.SetConfig(&data.FieldConfig{
|
dataField.SetConfig(&data.FieldConfig{
|
||||||
Unit: amr.Value[0].Unit,
|
Unit: toGrafanaUnit(amr.Value[0].Unit),
|
||||||
})
|
})
|
||||||
if query.Alias != "" {
|
if query.Alias != "" {
|
||||||
dataField.Config.DisplayName = formatAzureMonitorLegendKey(query.Alias, query.UrlComponents["resourceName"],
|
dataField.Config.DisplayName = formatAzureMonitorLegendKey(query.Alias, query.UrlComponents["resourceName"],
|
||||||
@ -386,3 +386,25 @@ func formatAzureMonitorLegendKey(alias string, resourceName string, metricName s
|
|||||||
|
|
||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map values from:
|
||||||
|
// https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftanalysisservicesservers
|
||||||
|
// to
|
||||||
|
// https://github.com/grafana/grafana/blob/master/packages/grafana-data/src/valueFormats/categories.ts#L24
|
||||||
|
func toGrafanaUnit(unit string) string {
|
||||||
|
switch unit {
|
||||||
|
case "Percent":
|
||||||
|
return "percent"
|
||||||
|
case "Count":
|
||||||
|
return "short" // this is used for integers
|
||||||
|
case "Bytes":
|
||||||
|
return "decbytes" // or ICE
|
||||||
|
case "BytesPerSecond":
|
||||||
|
return "Bps"
|
||||||
|
case "CountPerSecond":
|
||||||
|
return "cps"
|
||||||
|
case "Milliseconds":
|
||||||
|
return "ms"
|
||||||
|
}
|
||||||
|
return unit // this will become a suffix in the display
|
||||||
|
}
|
||||||
|
@ -201,7 +201,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
2.0875, 2.1525, 2.155, 3.6925, 2.44,
|
2.0875, 2.1525, 2.155, 3.6925, 2.44,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -221,7 +221,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
8.26, 8.7, 14.82, 10.07, 8.52,
|
8.26, 8.7, 14.82, 10.07, 8.52,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -241,7 +241,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 9, 14, 26, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 9, 14, 26, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
3.07, 2.92, 2.87, 2.27, 2.52,
|
3.07, 2.92, 2.87, 2.27, 2.52,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -261,7 +261,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 9, 14, 43, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 9, 14, 43, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
1.51, 2.38, 1.69, 2.27, 1.96,
|
1.51, 2.38, 1.69, 2.27, 1.96,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -281,7 +281,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 9, 14, 44, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 9, 14, 44, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
4, 4, 4, 4, 4,
|
4, 4, 4, 4, 4,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -300,19 +300,19 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
|
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
|
||||||
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "Count"})),
|
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "short"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"},
|
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"},
|
||||||
[]float64{1, 1, 1, 1, 1, 0}).SetConfig(&data.FieldConfig{Unit: "Count"})),
|
[]float64{1, 1, 1, 1, 1, 0}).SetConfig(&data.FieldConfig{Unit: "short"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"},
|
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"},
|
||||||
[]float64{0, 0, 0, 0, 0, 0}).SetConfig(&data.FieldConfig{Unit: "Count"})),
|
[]float64{0, 0, 0, 0, 0, 0}).SetConfig(&data.FieldConfig{Unit: "short"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -333,7 +333,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
|
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
|
||||||
data.NewField("Percentage CPU", nil, []float64{
|
data.NewField("Percentage CPU", nil, []float64{
|
||||||
8.26, 8.7, 14.82, 10.07, 8.52,
|
8.26, 8.7, 14.82, 10.07, 8.52,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"})),
|
}).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -353,21 +353,21 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
|
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
|
||||||
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "Count", DisplayName: "blobtype=PageBlob"})),
|
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=PageBlob"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, []float64{
|
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, []float64{
|
||||||
1, 1, 1, 1, 1, 0,
|
1, 1, 1, 1, 1, 0,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Count", DisplayName: "blobtype=BlockBlob"})),
|
}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=BlockBlob"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
|
||||||
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, []float64{
|
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, []float64{
|
||||||
0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0,
|
||||||
}).SetConfig(&data.FieldConfig{Unit: "Count", DisplayName: "blobtype=Azure Data Lake Storage"})),
|
}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=Azure Data Lake Storage"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -388,21 +388,21 @@ func TestAzureMonitorParseResponse(t *testing.T) {
|
|||||||
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
||||||
data.NewField("Blob Capacity", data.Labels{"blobtype": "PageBlob", "tier": "Standard"},
|
data.NewField("Blob Capacity", data.Labels{"blobtype": "PageBlob", "tier": "Standard"},
|
||||||
[]float64{675530, 675530, 675530}).SetConfig(
|
[]float64{675530, 675530, 675530}).SetConfig(
|
||||||
&data.FieldConfig{Unit: "Bytes", DisplayName: "danieltest {Blob Type=PageBlob, Tier=Standard}"})),
|
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=PageBlob, Tier=Standard}"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
||||||
data.NewField("Blob Capacity", data.Labels{"blobtype": "BlockBlob", "tier": "Hot"},
|
data.NewField("Blob Capacity", data.Labels{"blobtype": "BlockBlob", "tier": "Hot"},
|
||||||
[]float64{0, 0, 0}).SetConfig(
|
[]float64{0, 0, 0}).SetConfig(
|
||||||
&data.FieldConfig{Unit: "Bytes", DisplayName: "danieltest {Blob Type=BlockBlob, Tier=Hot}"})),
|
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=BlockBlob, Tier=Hot}"})),
|
||||||
|
|
||||||
data.NewFrame("",
|
data.NewFrame("",
|
||||||
data.NewField("", nil,
|
data.NewField("", nil,
|
||||||
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
|
||||||
data.NewField("Blob Capacity", data.Labels{"blobtype": "Azure Data Lake Storage", "tier": "Cool"},
|
data.NewField("Blob Capacity", data.Labels{"blobtype": "Azure Data Lake Storage", "tier": "Cool"},
|
||||||
[]float64{0, 0, 0}).SetConfig(
|
[]float64{0, 0, 0}).SetConfig(
|
||||||
&data.FieldConfig{Unit: "Bytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"})),
|
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user