how to use regex in grafana variables for dashboards

783 views Asked by At

I am trying to create a grafana dashboard for cassandra and I need assistance how to filter a variable from the metric output.

Grafana Query: label_values(collectd_dse_histogram_p98{cluster_name=~"$cluster",dse=~"org.apache.cassandra.metrics.table.read_latency.*.*"},dse)

Regex tried: org.apache.cassandra.metrics.table.read_latency.(.*)

Output I am getting is in the format keyspace.table_name. Need assistance how a Regex expression be formatted to extract only keyspace from the output.

Getting Output as "keyspace"."table_name"

Need only "keyspace" as output variable.

1

There are 1 answers

0
markalex On

To match keyspace in org.apache.cassandra.metrics.table.read_latency.keyspace.table_name proper regex is org\.apache\.cassandra\.metrics\.table\.read_latency\.(\[^.\]*)\..*:
It matches predefined prefix (while escaping dots, as the have special meaning in regex), and then it captures everything till next dot into a group.

Please notice that regex here matches full string.

/org\.apache\.cassandra\.metrics\.table\.read_latency\.([^.]*)/ might also work work, but in this case notice that regex is surrounded by /.

Difference is due to Grafana treating regexes differently depending on if they are enclosed in /.../ or not. Those without slashes are added with anchors ^ and $ automatically.

enter image description here