How to use Regex patterns in Grafana datasource

Introduction

With Regex patterns, you can efficiently retrieve data across multiple measurements simultaneously, enhancing the flexibility and ease of data retrieval within Grafana.

Example Regex patterns

regex101 can be used for trying out Regex patterns.

Note

In the Factry Historian datasource we need to wrap the regex pattern with /, such as /<regex_expression>/. Moreover, if the expression does not contain ^ or $, we need to put .* in the beginning and/or at the end of the pattern for the pattern to work.

  • /.*motor_speed/ : Will return data points of measurements where the measurement name contains “motor_speed” in its name.
  • /^motor_speed/ : Will return data points of measurements where the measurement name begins with “motor_speed”.
  • /motor_speed$/ : Will return data points of measurements where the measurement name ends with “motor_speed”.
  • /^first_.*_motor_speed$/ : Will return data points of measurements where the measurement name starts with “first_” and ends with “_motor_speed”. .* is used for matching anything between the start and the end of the measurement name.
    • Example: Captured measurement names can be:
      • first_01_a_motor_speed
      • first_02_b_motor_speed
      • first_03_c_motor_speed
  • /^sensor_\d+_temperature$/ : Will return data points of measurements where the measurement name starts with “sensor_” followed by one or more numbers and ends with “_temperature”.
    • Example: Captured measurement names can be:
      • sensor_1_temperature
      • sensor_25_temperature
      • sensor_100_temperature
  • /.*device_\w+_status$/ : Will return data points of measurements where “device_” is found, followed by word characters and ends with “_status”.
    • Example: Captured measurement names can be:
      • device_sensorA_status
      • device_controller_status
      • device_thermometer_status