Giovanni
Giovanni

Reputation: 735

Prometheus: extract a substring from a label value?

I have similar services on the same host. For example I have two mysql server named mysql01 e mysql02. I have installed two mysqld_exporter one for each mysql server. The values of label instance are instance="<host>-mysql01" and instance="<host>-mysql02". I have also installed node_exporter on the same host.

I wish to relate mysql_exporter series with node_exporter series. For example, on the same grafana dashboard, dedicated to mysql0x, I wish to visualize metrics about swap memory and buffer pool size. So I need to visualize the following series:

mysql_global_variables_innodb_buffer_pool_size{instance="<host>-mysql0x"}
node_memory_SwapTotal_bytes{instance="<host>"}

How can I extract from instance label value <host>-mysql0x the host part?

As bonus question: there is a best practice to label similar service on the same host?

Upvotes: 5

Views: 14775

Answers (1)

Amjad Hussain Syed
Amjad Hussain Syed

Reputation: 1040

you can use regex to do that as mentioned in the documentation. http://docs.grafana.org/reference/templating/#filter-and-modify-the-options-using-a-regex-capture-group-to-return-part-of-the-text enter image description here

Note: regex in image is just example

Upvotes: 8

Related Questions