I have a question regarding PromQL queries. I have the official docs: https://prometheus.io/docs/prometheus/latest/querying/basics/
Also I have looked at other guides on the webs and other stack overflow questions, but I still can't get my head around the logic.
I am using the fortigate_exporter to collect data: https://github.com/bluecmd/fortigate_exporter
Now I have two different metrics. fortigate_ha_member_has_role
and fortigate_managed_switch
.
I need to get the instance name or Serial number of the hosts who are "Master" or active.
This can be done via fortigate_ha_member_has_role{role="root_master"} == 1
This returns to me a list of nodes who are "Master". Because the secondary nodes also publish this data I need to filter it out.
fortigate_ha_member_has_role{environment="example.com", instance="fortigate-hostname", job="fortigate_exporter", monitor="sys-infra", network="REDACTED", priority="3", replica="A", role="root_master", serial="FORTIGATE-SERIAL"}
E.g. I need to get the serial number of the fortigate and match it to the hostname of the fortigate.
Now when I query the managed switches fortigate_managed_switch_info{status="Connected",state="Authorized"}
I get this data:
fortigate_managed_switch_info{environment="example.com", instance="master-fortigate-hostname", job="fortigate_exporter", monitor="sys-infra", network="REDACTED", os_version="REDACTED", priority="3", replica="A", serial="FORTISWITCH-SERIAL", state="Authorized", status="Connected", switch_name="REDACTED", vdom="root"}
So the only thing I can match the two metrics against is the instance name, because the serials from the querys are different - one is for the FG and the other for the FS. So I need to find the instance name via the Serial number from the first metric.
Any suggestions?
OK I was able to solve it like this:
fortigate_ha_member_has_role{role="root_master", instance=~"fortigate-(X|Y)-(int|ext)-(01|02).example.com"} == 1 and on(instance,serial) fortigate_version_info{} == 1 and on(instance) fortigate_managed_switch_info{status!="Connected",state="Authorized"}