sacloud / sakuracloud_exporter

Prometheus exporter for SakuraCloud metrics.
Apache License 2.0
7 stars 2 forks source link

group by SakuraCloud tags #25

Closed TakumaNakagame closed 5 years ago

TakumaNakagame commented 5 years ago

Problem

I want to group with PromQL using "tags". However, grouping is not possible because all tags are grouped in "tags".

Example

There is the following environment.

{tags="@auto-reboot,@group=c,@instance-type=master,k8s-node"}
{tags="@auto-reboot,@group=a,@instance-type=master,k8s-node"}
{tags="@auto-reboot,@group=b,@instance-type=master,k8s-node"}
{tags="@auto-reboot,@group=d,@instance-type=worker,k8s-node"}
{tags="@auto-reboot,@group=a,@instance-type=worker,k8s-node"}
{tags="@auto-reboot,@group=c,@instance-type=worker,k8s-node"}
{tags="@auto-reboot,@group=b,@instance-type=etcd,k8s-node"}
{tags="@auto-reboot,@group=a,@instance-type=etcd,k8s-node"}
{tags="@auto-reboot,@group=d,@instance-type=etcd,k8s-node"}

I want to group by "instance-type". However, tags cannot be grouped by "@gorup" tag. This can be done by grouping with the combination of {tags="@auto-reboot,@instance-type=master,k8s-node"}.

Feature

For example, we want to create a label like this:

{
     tag_at_auto-reboot = "true"
     tag_at_gropu = "a"
     tag_at_instance-type = "master"
     tag_k8s-node = "true"
}

In this case, grouping can be done with the following PromQL This gives you the total number of servers for each instance type.

sum (sakuracloud_server_info) by (tag_at_instance-type)
yamamoto-febc commented 5 years ago

Hi @TakumaNakagame,

I disagree to separate each tags as labels.

Please see https://github.com/prometheus/consul_exporter/issues/45#issuecomment-296429261.

No, this label shouldn't be added to all metrics:

  • Joins work fine here, it's not sane to replicate the same information over and over
  • Tags are not necessarily immutable, which would create new time series every time any label gets updated
  • Labels come at a cost, the more are added the more elaborate aggregations become. As not every query requires a tag label matcher, I don't agree to make such queries harder.

This comment has been made on another type issue, but I think it can fit to this issue as well.

In your case, you can use a regex-matcher like following:

sakuracloud_server_info{tags=~".*,instance-type=worker,.*"}

You can also use with multiple matcher like following:

sakuracloud_server_info{tags=~".*,instance-type=worker,.*",tags=~".*,@group=a,.*"}
TakumaNakagame commented 5 years ago

Hi @yamamoto-febc, Thank you for confirmation!

I didn't know this. Thank you for teaching me. Did not know that you can use multiple matchers! This will solve.

I was saved. This issue will be closed. Thank you as always.