Sign inSign up

foomo/pagespeed_exporter

By foomo

Updated 11 months ago

Pagespeed Exporter Build

Image
5

1M+

foomo/pagespeed_exporter repository overview

Prometheus Exporter for Google Pagespeed Online Metrics

Travis CI

Examples

To start the example with the default dashboard (docker-compose required)

$ git clone [email protected]:foomo/pagespeed_exporter.git
$ cd pagespeed_exporter/example
$ docker-compose up -d

After that, the application should be running on localhost:3000 with username admin and password s3cr3t.

The provided dashboard (Pagespeed) will be loaded with data after the first scrape.

Dashboard

The dashboard can be found at grafana

Understanding Metrics

Prometheus exporter for google pagespeed metrics

Building And Running

Building
$ make
Examples

To run pagespeed exporter we need to obtain the google api key for the pagespeed. Instructions how to create a key for pagespeed can be found here

pagespeed_exporter <arguments>

$ pagespeed_exporter -api-key {KEY} -targets https://google.com,https://prometheus.io -listener :80
Exporter Target Specification

Targets can be configured in either plaintext

https://github.com/foomo/pagespeed_exporter
https://mysite.com/test?test=true

Or via JSON which adds additional parameters

// URL can't be invalid
// Strategy can only be mobile/desktop
// If strategy is not specified, both desktop & mobile will be used
// Parameters are passed down to google pagespeed api

{"url":"https://github.com/foomo/pagespeed_exporter","campaign":"test","locale":"en","source":"source"}

{"url":"https://mysite.com/test?test=true","strategy":"mobile"}

Configuration specification in JSON and plain is supported both in command line & prometheus configuration

Exporter configuration

Configuration of targets can be done via docker and via prometheus

FlagVariableDescriptionDefaultRequired
-api-keyPAGESPEED_API_KEYsets the google API key used for pagespeedFalse
-targetsPAGESPEED_TARGETScomma separated list of targets to measureFalse
-tNONEmulti-value target array (check docker comp)False
-listenerPAGESPEED_LISTENERsets the listener address for the exporters:9271False
-parallelPAGESPEED_PARALLELsets the execution of targets to be parallelfalseFalse
-pushGatewayUrlPUSHGATEWAY_URLsets the pushgateway url to send the metricsFalse
-pushGatewayJobPUSHGATEWAY_JOBsets the pushgateway job namepagespeed_exporterFalse

Note: google api key is required only if scraping more than 2 targets/second

Note: exporter can be run without targets, and later targets provided via prometheus

Pushing metrics via push gateway

If you don't want to change the prometheus scrape_configs, you can send the metrics using push gateway using a batch job. Just configure the pushgateway url and use the /probe endpoint with query parameter target and the metrics will be send to prometheus.

curl http://localhost:9271/probe?target=https://www.example.com

Exporter Target Configuration (VIA PROMETHEUS)

Example configuration with simple and complex values

(Examples can ve found in the example folder)


  - job_name: pagespeed_exporter_probe
      metrics_path: /probe
      # Re-Label configurations so that we can use them
      # to configure the pagespeed exporter
      relabel_configs:
        - source_labels: [__address__]
          target_label: __param_target
        - source_labels: [__param_target]
          target_label: instance
        - target_label: __address__
          replacement: "pagespeed_exporter:9271"
      static_configs:
        - targets:
            - 'https://example.com/' # Example PLAIN
            - '{"url":"https://example.com/","campaign":"test","locale":"en","source":"source"}'  
            - '{"url":"https://example.com/mobileonly","strategy":"mobile"}'                    

Docker
$ docker run -p "9271:9271" --rm foomo/pagespeed_exporter -api-key {KEY} -t https://google.com,https://prometheus.io

or

$ docker run -p "9271:9271" --rm \
    --env PAGESPEED_API_KEY={KEY} \
    --env PAGESPEED_TARGETS=https://google.com,https://prometheus.io \
    foomo/pagespeed_exporter
Prometheus & Docker Compose

Check out the docker-compose folder

Kubernetes/Helm

You can install the included Helm chart to your k8s cluster with:

$ helm install helm/pagespeed-exporter

And then, to quickly test it:

$ kubectl get pods
pagespeed-exporter-riotous-dragonfly-6b99955999-hj2kw   1/1     Running   0          1m

$ kubectl exec -ti pagespeed-exporter-riotous-dragonfly-6b99955999-hj2kw -- sh
# apk add curl
# curl localhost:9271/metrics
pagespeed_lighthouse_audit_score{audit="first-contentful-paint",host="https://www.google.com",path="/",strategy="mobile"} 1
pagespeed_lighthouse_audit_score{audit="first-contentful-paint",host="https://www.google.com",path="/webhp",strategy="desktop"} 1
pagespeed_lighthouse_audit_score{audit="first-contentful-paint",host="https://www.google.com",path="/webhp",strategy="mobile"} 1
...

Tag summary

Content type

Image

Digest

sha256:18e4f78b7

Size

17.3 MB

Last updated

11 months ago

docker pull foomo/pagespeed_exporter