mirror of https://github.com/grafana/grafana
parent
a5e5db20e1
commit
b816f35c41
@ -0,0 +1,11 @@ |
||||
package azuremonitor |
||||
|
||||
import "fmt" |
||||
|
||||
// formatLegendKey builds the legend key or timeseries name
|
||||
func formatLegendKey(resourceName string, metricName string, metadataName string, metadataValue string) string { |
||||
if len(metadataName) > 0 { |
||||
return fmt.Sprintf("%s{%s=%s}.%s", resourceName, metadataName, metadataValue, metricName) |
||||
} |
||||
return fmt.Sprintf("%s.%s", resourceName, metricName) |
||||
} |
||||
@ -0,0 +1,128 @@ |
||||
{ |
||||
"cost": 0, |
||||
"timespan": "2019-02-09T15:21:39Z\/2019-02-09T21:21:39Z", |
||||
"interval": "PT1H", |
||||
"value": [ |
||||
{ |
||||
"id": "\/subscriptions\/xxx\/resourceGroups\/grafanastaging\/providers\/Microsoft.Storage\/storageAccounts\/grafanastaging\/blobServices\/default\/providers\/Microsoft.Insights\/metrics\/BlobCount", |
||||
"type": "Microsoft.Insights\/metrics", |
||||
"name": { |
||||
"value": "BlobCount", |
||||
"localizedValue": "Blob Count" |
||||
}, |
||||
"unit": "Count", |
||||
"timeseries": [ |
||||
{ |
||||
"metadatavalues": [ |
||||
{ |
||||
"name": { |
||||
"value": "blobtype", |
||||
"localizedValue": "blobtype" |
||||
}, |
||||
"value": "PageBlob" |
||||
} |
||||
], |
||||
"data": [ |
||||
{ |
||||
"timeStamp": "2019-02-09T15:21:00Z", |
||||
"average": 3 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T16:21:00Z", |
||||
"average": 3 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T17:21:00Z", |
||||
"average": 3 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T18:21:00Z", |
||||
"average": 3 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T19:21:00Z", |
||||
"average": 3 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T20:21:00Z" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
"metadatavalues": [ |
||||
{ |
||||
"name": { |
||||
"value": "blobtype", |
||||
"localizedValue": "blobtype" |
||||
}, |
||||
"value": "BlockBlob" |
||||
} |
||||
], |
||||
"data": [ |
||||
{ |
||||
"timeStamp": "2019-02-09T15:21:00Z", |
||||
"average": 1 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T16:21:00Z", |
||||
"average": 1 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T17:21:00Z", |
||||
"average": 1 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T18:21:00Z", |
||||
"average": 1 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T19:21:00Z", |
||||
"average": 1 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T20:21:00Z" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
"metadatavalues": [ |
||||
{ |
||||
"name": { |
||||
"value": "blobtype", |
||||
"localizedValue": "blobtype" |
||||
}, |
||||
"value": "Azure Data Lake Storage" |
||||
} |
||||
], |
||||
"data": [ |
||||
{ |
||||
"timeStamp": "2019-02-09T15:21:00Z", |
||||
"average": 0 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T16:21:00Z", |
||||
"average": 0 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T17:21:00Z", |
||||
"average": 0 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T18:21:00Z", |
||||
"average": 0 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T19:21:00Z", |
||||
"average": 0 |
||||
}, |
||||
{ |
||||
"timeStamp": "2019-02-09T20:21:00Z" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
], |
||||
"namespace": "Microsoft.Storage\/storageAccounts\/blobServices", |
||||
"resourceregion": "westeurope" |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
package azuremonitor |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
) |
||||
|
||||
// URLBuilder builds the URL for calling the Azure Monitor API
|
||||
type URLBuilder struct { |
||||
ResourceGroup string |
||||
MetricDefinition string |
||||
ResourceName string |
||||
} |
||||
|
||||
// Build checks the metric definition property to see which form of the url
|
||||
// should be returned
|
||||
func (ub *URLBuilder) Build() string { |
||||
|
||||
if strings.Count(ub.MetricDefinition, "/") > 1 { |
||||
rn := strings.Split(ub.ResourceName, "/") |
||||
lastIndex := strings.LastIndex(ub.MetricDefinition, "/") |
||||
service := ub.MetricDefinition[lastIndex+1:] |
||||
md := ub.MetricDefinition[0:lastIndex] |
||||
return fmt.Sprintf("resourceGroups/%s/providers/%s/%s/%s/%s/providers/microsoft.insights/metrics", ub.ResourceGroup, md, rn[0], service, rn[1]) |
||||
} |
||||
|
||||
return fmt.Sprintf("resourceGroups/%s/providers/%s/%s/providers/microsoft.insights/metrics", ub.ResourceGroup, ub.MetricDefinition, ub.ResourceName) |
||||
} |
||||
@ -0,0 +1,45 @@ |
||||
package azuremonitor |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
. "github.com/smartystreets/goconvey/convey" |
||||
) |
||||
|
||||
func TestURLBuilder(t *testing.T) { |
||||
Convey("AzureMonitor URL Builder", t, func() { |
||||
|
||||
Convey("when metric definition is in the short form", func() { |
||||
ub := &URLBuilder{ |
||||
ResourceGroup: "rg", |
||||
MetricDefinition: "Microsoft.Compute/virtualMachines", |
||||
ResourceName: "rn", |
||||
} |
||||
|
||||
url := ub.Build() |
||||
So(url, ShouldEqual, "resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/rn/providers/microsoft.insights/metrics") |
||||
}) |
||||
|
||||
Convey("when metric definition is Microsoft.Storage/storageAccounts/blobServices", func() { |
||||
ub := &URLBuilder{ |
||||
ResourceGroup: "rg", |
||||
MetricDefinition: "Microsoft.Storage/storageAccounts/blobServices", |
||||
ResourceName: "rn1/default", |
||||
} |
||||
|
||||
url := ub.Build() |
||||
So(url, ShouldEqual, "resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/rn1/blobServices/default/providers/microsoft.insights/metrics") |
||||
}) |
||||
|
||||
Convey("when metric definition is Microsoft.Storage/storageAccounts/fileServices", func() { |
||||
ub := &URLBuilder{ |
||||
ResourceGroup: "rg", |
||||
MetricDefinition: "Microsoft.Storage/storageAccounts/fileServices", |
||||
ResourceName: "rn1/default", |
||||
} |
||||
|
||||
url := ub.Build() |
||||
So(url, ShouldEqual, "resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/rn1/fileServices/default/providers/microsoft.insights/metrics") |
||||
}) |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue