Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zysimplelife opened this issue Jun 12, 2019 · 8 comments
Open

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

zysimplelife opened this issue Jun 12, 2019 · 8 comments

Comments

@zysimplelife
Copy link

zysimplelife commented Jun 12, 2019

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 
@zysimplelife zysimplelife changed the title new resource type in the metrics label Can it add "resource type" as one of the metrics label Jun 12, 2019
@brian-brazil
Copy link
Member

What would be an example resultant metric?

@zysimplelife
Copy link
Author

What would be an example resultant metric?

I have just added the expectation result in the description.

@brian-brazil
Copy link
Member

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

@zysimplelife
Copy link
Author

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
Copy link
Member

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

@zysimplelife
Copy link
Author

zysimplelife commented Jun 13, 2019

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
Copy link

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
Copy link
Contributor

louisfelix commented Oct 1, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants