Custom query to show overall health of servers in 1 panel

  • What Grafana version and what operating system are you using?
    9.1.3

  • What are you trying to achieve?
    Each Site in in my environment has 30 servers but few sites has only 27 servers. Each site has a unique number and the relevant servers are grouped accordingly. On grafana dashboard, I have created the below query to count the total servers which are up and then color code based on their values. On the value mappings for the value 30 it will display in Green color and rest others in Red color. Since our environment few sites has only 27 servers it is showing in Red for those even though all servers are up at that site. Since I know which site has only 27 servers I want to use some kind of expression and when processing it, anything matches the hardcodes site number in a variable and if all the 27 servers are up mark it Green. Some kind of override i need for this special case.
    Query:
    sort (count by(Site) (probe_success{Site=~"$Site"} == 1))
    Value Mappings
    30 → Green
    27 to 29 → Yellow
    1 to 26 → Red

Screen Shot 2022-12-16 at 3.48.56 PM

  • How are you trying to achieve it?
    Using the below query it works only for the site which has 30 servers but for the sites which only 27 servers.
    Query:
    sort (count by(Site) (probe_success{Site=~"$Site"} == 1))

  • What happened?
    For the sites which has 27 servers it is showing Red color but the whole site is up & running.

  • What did you expect to happen?
    I want to create expression in such a way that it works for both 27 servers site and also 30 servers site. Since I know which site has 27 servers I want to hardcode it but not sure how to do it.

  • Can you copy/paste the configuration(s) that you are having problems with?
    Query:
    sort (count by(Site) (probe_success{Site=~"$Site"} == 1))

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors.

  • Did you follow any online instructions? If so, what is the URL?
    No, I did not follow any.