How can define text filter regex

My last data thta is showing in grafana is such as follow :slight_smile:

HTTP OK: HTTP/1.1 200 - 14716 bytes in 0.011 second response time |time=0.010866s;5.000000;10.000000;0.000000 size=14716B;;;0

so I want to define it in grafana in Stat panel if find 200 show UP and if could not find 200 show service down . How can define value mappring regex for while cannot find 200 ?

Hi, if you’re using value mappings, you can always do:
Mapping 1 β†’ regex .200. β†’ Service UP
Mapping 2 β†’ regex .* β†’ Service Down

the mappings are executed in order, so it will match the first rule.

In your Stat panel β†’ Edit β†’ Value mappings β†’ Add these two regex mappings:

Show UP (when 200 found)

Type: Regex
Pattern: .*200.*
Display: UP
Color: Green

Show Service Down (when 200 NOT found)

Type: Regex
Pattern: ^(?!.*200).*$ or better option .*
Display: Service Down
Color: Red

Mappings are executed in order β†’ Mapping 1 is checked first. If it matches, Mapping 2 is skipped.

^(?!.*200).*$ β†’ explicitly matches strings without 200

.* β†’ catches everything that didn’t match Mapping 1

That is strange . It does not work .

Add value mapping

Add new mappting as regex . then in regulat expression fill with .*200.*

and optional diplay text fill with UP but still showing 200 instead of UP

Could you share a screenshot of your Value Mappings configuration and the panel query result?

The regex mapping shown above works when the field value is a string containing 200 (for example, HTTP/1.1 200 OK).

If your panel value is the numeric value 200, then a Value mapping may be required instead:

Type: Value
Value: 200
Display text: UP

Could you also share the panel configuration or Query Inspector β†’ Data output so we can verify whether the field is being returned as a string or a numeric value?

While my output is string such as :
HTTP OK: HTTP/1.1 200 - 14716 bytes in 0.011 second response time

That regex is working but while output is not string and just return 200 that regex does not work .

How can set Down when out put is any thing except 200

.* Regex does work on numeric values in Grafana. Use these two mappings:

Mapping 1 β†’ UP:

Mapping 2 β†’ catches EVERYTHING except 200:

Grafana executes mappings in order β†’ if value is 200 β†’ shows UP and stops. Anything else (404, 500, 600, null) β†’ caught by .* β†’ shows Service Down.

This works for both string and numeric output

Please find follow pics due define regex for output 200 it does not work while define regex

I was able to reproduce similar behavior with a numeric Zabbix item.

In my testing:

Value mappings (for example, 200 β†’ UP) were applied correctly.

Regex mappings such as 200, .*, and ^.*$ were not applied to the numeric value, and the panel continued to display the raw value (200, 500, etc.).

try changing your mapping from Regex to Value?

UP mapping

  • Type: Value
  • Value: 200
  • Display text: UP
  • Color: Green

If you need to handle other status codes, add additional Value mappings for those codes as well.

Based on the behavior I observed, this appears to be related to how value mappings are being applied to a numeric field rather than an issue with the regex pattern itself

One thing I’d add is to test the regex against a few edge cases before using it in production, especially if the field values can contain unexpected characters or spaces. A small tweak to the pattern can sometimes make a big difference in Grafana filtering results.