Prometheus Web Exporter is a prometheus exporter that collects information about web pages. You can collect 2 different type of information from url. Network health info (response time and response body size) and content based info (Number of elements in a page that matches with given css query.)
Web exporter uses same technology with firefox browser engine (servo) to parse and run css queries. So it is quite fast and supports wide veriety of css queries. Unfortunately it does not run javascript so any dom manipulation done with javascript will not be caught by web exporter.
Web configuration is done with a file named webexporter.yaml that is located in the same directory with the executable. Here is an example for webexporterl.yaml file:
``` yaml ipaddress: "0.0.0.0" port: 3030 metricspath: "metrics" targets: - url: "https://www.rust-lang.org/" queries: - "#language-values div.flex-none section" - "header h1" - "footer div.attribution"
url: "https://www.rust-lang.org/invalid-page-with-404-response" queries:
url: "https://www.page-does-not-exist.io/" queries:
url: "https://www.rust-lang.org/invalid-css-query" queries:
Configuration above will generate metrics like following:
txt
web_exporter_response_duration_milliseconds{url="https://www.rust-lang.org/", status=200, error=0} 640
web_exporter_response_response_size_bytes{url="https://www.rust-lang.org/", status=200, error=0} 19220
web_exporter_query_count{url="https://www.rust-lang.org/", query="#language-values div.flex-none section", status=200, error=0} 3
web_exporter_query_count{url="https://www.rust-lang.org/", query="header h1", status=200, error=0} 1
web_exporter_query_count{url="https://www.rust-lang.org/", query="footer div.attribution", status=200, error=0} 1
web_exporter_response_duration_milliseconds{url="https://www.rust-lang.org/invalid-page-with-404-response", status=404, error=0} 292
web_exporter_response_response_size_bytes{url="https://www.rust-lang.org/invalid-page-with-404-response", status=404, error=0} 8244
web_exporter_query_count{url="https://www.rust-lang.org/invalid-page-with-404-response", query="div.flex", status=404, error=0} 6
web_exporter_query_count{url="https://www.rust-lang.org/invalid-page-with-404-response", query="div", status=404, error=0} 14
web_exporter_response_duration_milliseconds{url="https://www.page-does-not-exist.io/", status=0, error=1} 270
web_exporter_response_response_size_bytes{url="https://www.page-does-not-exist.io/", status=0, error=1} 0
web_exporter_response_duration_milliseconds{url="https://www.rust-lang.org/invalid-css-query", status=404, error=0} 306
web_exporter_response_response_size_bytes{url="https://www.rust-lang.org/invalid-css-query", status=404, error=0} 8244
web_exporter_query_count{url="https://www.rust-lang.org/invalid-css-query", query="**XX**", status=404, error=0} 0
web_exporter_scrape_duration_milliseconds 641
``` bash
wget https://raw.githubusercontent.com/huseyinyilmaz/webexporter/master/sampleweb_exporter.yaml
mv samplewebexporter.yaml web_exporter.yaml
$ docker run \ --rm -ti -d \ -p 3030:3030 \ --name webexporter \ -v $(pwd)/webexporter.yaml:/usr/local/prometheuswebexporter/webexporter.yaml \ huseyinyilmaz/webexporter:v1.0.0
```
First download sample configuration from repository and put it in the same directory as docker-compose.yaml file. Then you can add following config to your docker-compose file.
webexporter:
image: huseyinyilmaz/web_exporter:v1.0.1
volumes:
- ./web_exporter.yaml:/usr/local/prometheus_web_exporter/web_exporter.yaml
environment:
WEB_EXPORTER_LOG_LEVEL: warn
ports:
- 3030:3030
expose:
- 3030
``` bash
cargo install prometheuswebexporter
cd ~/.cargo/bin
wget https://raw.githubusercontent.com/huseyinyilmaz/webexporter/master/sampleweb_exporter.yaml
mv samplewebexporter.yaml web_exporter.yaml
./prometheuswebexporter
```
Logging configuration can be provided through environment variables. To run the project with info logging level you can run it like this
bash
$ WEB_EXPORTER_LOG_LEVEL=info ./prometheus_web_exporter