Reputation: 63
I'm trying to get a value embedded in a webpage into prometheus using the blackbox exporter but as it stands it looks like the http blackbox probe doesn't support scraping the source of a webpage which is understandable. My use case is that a webpage can have 3 states: standby, fetching from external source, done (this is embedded in the source of the page). I've considered abusing the http response code to do this and do something like
200 = done,
202 = fetching,
400 = standby
then use probe_http_status_code
for alerting for example.
However I don't really like this solution because the status codes would only be meaningful to blackbox and it would be a pain for any other use case. Is there a clever way to get some of the response (values of headers for example) into prometheus?
Upvotes: 3
Views: 2367
Reputation: 1
Using json_exporter
lets you query any API and map the response into labels or result metrics, it's very handful.
https://github.com/prometheus-community/json_exporter
Upvotes: 0
Reputation: 6863
The blackbox exporter is really intended for backbox monitoring in its narrower sense: monitoring a system from the outside by treating it as a blackbox, from the user point of view. If you need only to check the done
state, you can use the fail_if_body_not_matches_regexp
check of http_probe
.
Trying to put a state into that is already treading toward whitebox monitoring: the state only makes sense if you have a model of the system. This explains why the blackbox exporter is not the right tool if you really need three states.
For a quick hack to get the state, my favorite fallback is using exporter_exporter which is able to run a script and parse the standard output as open-metric content. With a clever use of curl, you can extract whatever you need. This is not the most efficient use of your cpu but it stays relatively cheap.
Otherwise there is no way around rolling your own exporter or integrating Prometheus metrics in your software.
Upvotes: 1