Problem:
Hey guys, I had an Idea of querying API to get traces status and then to expose this status in Prometheus. So it is visible to everyone which servers require reboot.
I’ve written one-liner in which using jq I convert json output to prometheus metric.
echo "# HELP reboot_required_status has values 0,1,2: 0-no process require restarting, 1-process requires restart, 2-reboot required"; echo "# TYPE reboot_required_status gauge"; curl -XGET -u $username:$password -s https://foreman.example.com/api/hosts?per_page=all | jq -r '.results[] | "reboot_required_status{name=\"\(.name)\"} \(.traces_status)"'
As you can see I’m only interested in fields “name” and “traces_status” out of many printed per host.
I have almost 11 000 hosts and using “per_page=all” times out after a minute. With pagination I can do around 1000 hosts at a time and it will take each query around 30-55 seconds to finish.
Expected outcome:
Can I somehow query only for fields “name” and “traces_status” in hopes that querying all hosts(11 000) takes less time?
Foreman and Proxy versions:
Foreman 2.2.1
Foreman and Proxy plugin versions:
Foreman 2.2.1
Distribution and version:
CentOS 7.9.2009
Other relevant data:
Here is how an output looks like for anyone interested:
# HELP reboot_required_status has values 0,1,2: 0-no process require restarting, 1-process requires restart, 2-reboot required
# TYPE reboot_required_status gauge
reboot_required_status{name="server-1.domain.local"} 2
reboot_required_status{name="server-2.domain.local"} 0
reboot_required_status{name="server-3.domain.local"} 2
reboot_required_status{name="server-4.domain.local"} 0
reboot_required_status{name="server-5.domain.local"} 2
reboot_required_status{name="server-6.domain.local"} 2