Panel should display colored bars for window_service_state states

  • What Grafana version and what operating system are you using?
    Grafana-12.0.0 .. as docker container on a Debian-12.11 host

  • What are you trying to achieve?
    I read data into prometheus by using the windows_exporter.
    I want to create a panel that displays one line per windows instance, showing the state of one service (metric “windows_service_state”) in a color.

  • How are you trying to achieve it?
    I try to use “Time Series” or “State timeline” visualization.
    I try to group/filter the states via thresholds.
    I defined the variable $instance to match “label_values(windows_os_hostname,instance)”
    I defined thresholds to match the various states like “Running” “Stopped”, etc

  • queries
    For example I try to use these queries:

windows_service_state{name=~"postgresql-x64-1*.*"} * on (instance,name) group_left(display_name) windows_service_info 
windows_service_state{job="windows-exporter",name="postgresql-x64-*"}
  • What happened?
    Either I get problems with the State timeline because my data seems not to have a timestamp.
    Or I get one line per status, but not one line per instance.

Hi, can you share some more info about the data:

  1. Is the state a label? If so, what is the convention? Does it expose 0 value whenever the state is not occurring and state 1 of state is occurring (e.g. windows_service_state{job="windows-exporter",name="postgresql-x64-*", instance="1", state="Running"} 1 and windows_service_state{job="windows-exporter",name="postgresql-x64-*", instance="1", state="Stopped"} 0 would mean the instance 1 would be running?
  2. Do you use the variable $instance inside the queries (it’s not enough to define a variable, you should also use it).

thanks @dawiddebowski

  1. does this doc help: windows_exporter/docs/collector.service.md at master · prometheus-community/windows_exporter · GitHub ?
  2. I am currently trying to start a “State timeline” visualization from scratch and use your suggested query somehow. And yes, I add instance like in:
windows_service_state{job="windows-exporter",state="running",name="postgresql-x64-10",instance="$instance"}

For this I get “Data does not have a time field”.

I see in the docs that the current state of the instance has value 1, so your query should end with == 1 (that will filter out all the states that the instance is not in). As for the Data does not have time field - I think it’s quite hard for prometheus data not to have a timestamp (at least I think). Do you use some transformations (the tab next to the query)? Can you share the screen of the query (like the entire query editor, there are a couple of settings but they also shouldn’t cause such an error).

See this query with “$instance”:

without that I get bars, but multiple per instance:

Variable definition:

thanks for your help

“Data does not have a time field” can happen when either a) the data returned is missing a timestamp that state timeline can understand, or b) no data was returned at all for the panel query. In your case it’s likely the latter. If you hit the “Table View” toggle while in panel edit mode and it says “No Data”, that confirms that.

Based on your screenshots, I’m guessing the instance you have selected in your variable (192.168.1.51:9182) isn’t actually running postgres, as this instance isn’t present in the list shown in the second screenshot. If you want this dashboard to only display the servers that actually run postgres, you can change your variable query from windows_os_hostname to windows_service_state and add a label filter of name=“postgresql-x64-10”, so that your panel query will always match.

Re-reading your initial post, I think you’ll want to drop the instance variable altogether, and do something like so:

Set the name label match to your target service, and set the format to Table. Do not include state=“running”, as you want to get all states:

Add a transformation to group the results by instance:

Add value mappings to colourize the results. Here I chose running=green and any other state=red, and renamed them to up/down:

This will give you a result that looks like so, with one row per instance (I only have one Windows instance in this prometheus instance):

However, state timeline connects missing values by default, so if an instance was offline for a period of time (as mine was between 1100h-1135h), it’s not going to reflect that properly. Easily fixed by setting a disconnect threshold appropriate to your scrape interval:

Which makes the final product looks like:

2 Likes

@tjamesking a quick thank you! Your suggestions look very helpful, I will try to apply things as soon as I find the time to (hopefully tomorrow).

EDIT: I just found the time to try the suggested steps, and it looks good … !

Great, thank you. I will play with parameters etc, but the general solution seems to be exactly what I need in this case. thanks @tjamesking

1 Like