diff --git a/plugins/outputs/azure_monitor/README.md b/plugins/outputs/azure_monitor/README.md index 28bb66af6662e..fbb49358665a5 100644 --- a/plugins/outputs/azure_monitor/README.md +++ b/plugins/outputs/azure_monitor/README.md @@ -40,6 +40,11 @@ written as a dimension on each Azure Monitor metric. ## The Azure Resource ID against which metric will be logged, e.g. ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" + + ## Optionally, if in Azure US Government, China, or other sovereign + ## cloud environment, set the appropriate REST endpoint for receiving + ## metrics. (Note: region may be unused in this context) + # endpoint_url = "https://monitoring.core.usgovcloudapi.net" ``` ### Setup diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index e52d66b991d9b..408976c536338 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -31,6 +31,7 @@ type AzureMonitor struct { StringsAsDimensions bool `toml:"strings_as_dimensions"` Region string ResourceID string `toml:"resource_id"` + EndpointUrl string `toml:"endpoint_url"` url string auth autorest.Authorizer @@ -65,6 +66,7 @@ const ( vmInstanceMetadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-12-01" resourceIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s" urlTemplate = "https://%s.monitoring.azure.com%s/metrics" + urlOverrideTemplate = "%s%s/metrics" maxRequestBodySize = 4000000 ) @@ -91,6 +93,11 @@ var sampleConfig = ` ## The Azure Resource ID against which metric will be logged, e.g. ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" + + ## Optionally, if in Azure US Government, China or other sovereign + ## cloud environment, set appropriate REST endpoint for receiving + ## metrics. (Note: region may be unused in this context) + # endpoint_url = "https://monitoring.core.usgovcloudapi.net" ` // Description provides a description of the plugin @@ -125,6 +132,8 @@ func (a *AzureMonitor) Connect() error { var err error var region string var resourceID string + var endpointUrl string + if a.Region == "" || a.ResourceID == "" { // Pull region and resource identifier region, resourceID, err = vmInstanceMetadata(a.client) @@ -138,13 +147,21 @@ func (a *AzureMonitor) Connect() error { if a.ResourceID != "" { resourceID = a.ResourceID } + if a.EndpointUrl != "" { + endpointUrl = a.EndpointUrl + } if resourceID == "" { return fmt.Errorf("no resource ID configured or available via VM instance metadata") } else if region == "" { return fmt.Errorf("no region configured or available via VM instance metadata") } - a.url = fmt.Sprintf(urlTemplate, region, resourceID) + + if endpointUrl == "" { + a.url = fmt.Sprintf(urlTemplate, region, resourceID) + } else { + a.url = fmt.Sprintf(urlOverrideTemplate, endpointUrl, resourceID) + } log.Printf("D! Writing to Azure Monitor URL: %s", a.url)