RobustPerception / azure_metrics_exporter

Azure metrics exporter for Prometheus
Apache License 2.0
133 stars 70 forks source link

Can it add "resource type" as one of the metrics label #56

Open zysimplelife opened 5 years ago

zysimplelife commented 5 years ago

I am wondering if it is possible to add "resource type" in the exposed metrics labels. for example what I have got is as follows. it shows the "resource_group" and "resource_name" but no "resource type".
Resource type might be a useful information when the user want to filter interesting metrics.

# HELP bitsinpersecond_countpersecond_average bitsinpersecond_countpersecond_average
# TYPE bitsinpersecond_countpersecond_average gauge
bitsinpersecond_countpersecond_average{resource_group="bca-dev-westeurope",resource_name="azure-to-c3-mash-up-connection"} 0
bitsinpersecond_countpersecond_average{resource_group="bca-dev-westeurope",resource_name="azure-to-ims-connection"} 0 

one of the resource related to above metrics in the azure is like

{
    "id": "/subscriptions/15b4d43c-7a12-42ea-8184-cedd7e6f229a/resourceGroups/bca-dev-westeurope/providers/Microsoft.Network/connections/azure-to-ims-connection",
    "identity": null,
    "kind": null,
    "location": "westeurope",
    "managedBy": null,
    "name": "azure-to-ims-connection",
    "plan": null,
    "properties": null,
    "resourceGroup": "bca-dev-westeurope",
    "sku": null,
    "tags": null,
    "type": "Microsoft.Network/connections"
  },

it would be nice to get metric like follows

# HELP bitsinpersecond_countpersecond_average bitsinpersecond_countpersecond_average
# TYPE bitsinpersecond_countpersecond_average gauge
bitsinpersecond_countpersecond_average{resource_group="bca-dev-westeurope", resource_type="connections", resource_name="azure-to-c3-mash-up-connection"} 0
bitsinpersecond_countpersecond_average{resource_group="bca-dev-westeurope", resource_type="connections",  resource_name="azure-to-ims-connection"} 0 
brian-brazil commented 5 years ago

What would be an example resultant metric?

zysimplelife commented 5 years ago

What would be an example resultant metric?

I have just added the expectation result in the description.

brian-brazil commented 5 years ago

That looks like something that should be part of the metric name.

zysimplelife commented 5 years ago

That looks like something that should be part of the metric name.

It would also be a solution. but from the answer in the issue you seems like it is not good idea to put it as part of the metric name

brian-brazil commented 5 years ago

What's an actual example of the metric we produce for the above?

zysimplelife commented 5 years ago

What's an actual example of the metric we produce for the above?

I don't understand the question. the current produced metric has been put in the description above, the expected result is as well.

andreygolev commented 5 years ago

I'm not sure if this follows all the development rules there, but here's the quick fix for that case


 diff --git a/utils.go b/utils.go
 index 9088e13..bfe20a5 100644
 --- a/utils.go
 +++ b/utils.go
 @@ -33,6 +33,7 @@ func CreateResourceLabels(resourceID string) map[string]string {
     labels := make(map[string]string)
     resource := strings.Split(resourceID, "/")
     labels["resource_group"] = resource[4]
 +        labels["resource_type"] = invalidMetricChars.ReplaceAllString(resource[6], "_")
     labels["resource_name"] = resource[8]
     if len(resource) > 13 {
         labels["sub_resource_name"] = resource[10]
louisfelix commented 5 years ago

@zysimplelife, as part of issue #64, resource_type was added as a label of the new azure_resource_info metric (follow the discussion in issue #64 to understand why it is a separate metric).

For the record, in the specific case you mentioned above, you can now do the following to apply the resource_type label to your metric, in any PromQL query:

(bitsinpersecond_countpersecond_average * on (resource_group, resource_name) group_left(resource_type) azure_resource_info)

I think that feature would close the current issue.