Issues with group_left to exclude specific label value

21 views
Skip to first unread message

Al

unread,
Jun 25, 2020, 10:05:09 AM6/25/20
to Prometheus Users
All hosts from which I collect node_exporter metrics each have an additional node_role metric (added via textfile collector) which identifies all the Chef roles a given host has.  As an example, say we have 3 hosts with the following textfile collector metrics:

server1:
node_role{role="web_server_app1"}

server2:
node_role{role="redis_server"}

server3:
node_role{role="db_server"}

server4:
node_role{role="web_server_app2"}



I'm attempting to write a PromQL query which will return the current disk usage % for hosts that do not have a specific role "web_server" assigned to them.  I've attempted the following PromQL query although it's invalid as we end up with many results on the right hand side, which doesn't match the many-to-one nature of the group left:

100 - (

   (node_filesystem_free_bytes{mountpoint=“”/data} * on (hostname) group_left(role) node_role{role!~“web_server.*”} )

   /

   (node_filesystem_size_bytes{mountpoint=“”/data} * on (hostname) group_left(role) node_role{role!~“web_server”} )

   *

   100

)


How could I modify this query so that it correctly return the disk usage percentage of server2 and server3?


I appreciate your help.

Christian Hoffmann

unread,
Jun 30, 2020, 2:25:59 AM6/30/20
to Al, Prometheus Users
Hi,

On 6/25/20 4:05 PM, Al wrote:
> All hosts from which I collect node_exporter metrics each have an
> additional node_role metric (added via textfile collector) which
> identifies all the Chef roles a given host has.  As an example, say we
> have 3 hosts with the following textfile collector metrics:
>
> *server1:*
> |
> node_role{role="web_server_app1"}
> |
>
> *server2:*
> |
> node_role{role="redis_server"}
> |
>
> *server3:*
> |
> node_role{role="db_server"}
> |
>
> *server4:*
> |
> node_role{role="web_server_app2"}
> |
>
>
>
> I'm attempting to write a PromQL query which will return the current
> disk usage % for hosts that do not have a specific role "web_server"
> assigned to them.  I've attempted the following PromQL query although
> it's invalid as we end up with many results on the right hand side,
> which doesn't match the many-to-one nature of the group left:
>
> |
>
> 100-(
>
>    (node_filesystem_free_bytes{mountpoint=“”/data}*on
> (hostname)group_left(role)node_role{role!~“web_server.*”})
>
>    /
>
>    (node_filesystem_size_bytes{mountpoint=“”/data}*on
> (hostname)group_left(role)node_role{role!~“web_server”})
>
>    *
>
>    100
>
> )
>
> |
>
> How could I modify this query so that it correctly return the disk usage
> percentage of server2 and server3?

The pattern basically looks fine.
Some remarks:

- Your quotation marks do not look like ASCII quotes -- I guess this
comes from pasting?
- The quotation marks around mountpoint= seem off (one should come after
/data).
- Your role regexp is not identical. The regexp in the second part lacks
the .* and will therefore match all your example servers.
- The role "join" can probably be omitted from the second part when
using on(instance, mountpoint)

In general I suggest trying the parts of your query individually and
only putting them into the larger query once both parts return what you
need.

Kind regards,
Christian
Reply all
Reply to author
Forward
0 new messages