foomo/pagespeed_exporter

how to display curl output on grafana

Closed this issue · 22 comments

i am able to get the output on curl command, attached (curl localhost:9271/metrics) but not able to display same on grafana dashboard.

i create Prometheus data-source (with localhost:9271, tried with 9090 also) on grafana and imported pagespeed dashboard also.

getting below error.
curl output.txt

{"err":{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","silent":true,"url":"http://localhost:9090/api/v1/series?match[]=pagespeed_lighthouse_category_score&start=1556111452&end=1556115052","retry":0,"headers":{"Accept":"application/json, text/plain, /"}},"statusText":"","xhrStatus":"error"},"cancelled":true}

Hi @muzammil84 , the pagespeed works by contacting remote API. So if you can hit it via https://developers.google.com/speed/pagespeed/insights/
it can be used by the application

Oh, wait I misunderstood the question!

So, given that you used docker-compose to start the whole ordeal, that means that the data source has its internal networking from docker.

So, given that you're using https://github.com/foomo/pagespeed_exporter/blob/master/example/docker-compose.yml example,
the grafana data-source for prometheus would be prometheus:9090 and the pagespeed exported is located under pagespeed_exporter:9271 (due to docker DNS container resolution)

thanks for the quick reply. but couldn't understand the solution you provided.

can you please tell with what parameters prometheus data source i need to create in grafana as localhost:9090 and localhost:9271 both are failing in my case.

Did you run the example as specified in the readme?

i did below steps

  1. git clone https://github.com/foomo/pagespeed_exporter
  2. cd pagespeed_exporter/example
  3. docker-compose up -d
  4. docker run -p "9271:9271" -d --rm foomo/pagespeed_exporter -t https://google.com
  5. curl localhost:9271/metric --> it gave me output which i attached in my first ticket.

any update here? did i follow the instructions correctly?

Hi, close!

So the pagespeed is already running on docker, which can be accessed via docker networking. If you'd like to configure new targets, please configure it in the docker-compose.

The prometheus collects from the pagespeed running in docker network under pagespeed_exporter

If you'd like to see active prometheus targets, you can see them @ localhost:9090/targets, since port 9090 is mapped on the docker host.

You don't need docker run -p "9271:9271" -d --rm foomo/pagespeed_exporter -t https://google.com since it's already running in docker

as of now i am trying to get the output of google.com on grafana. when i created browser based prometheus data source in grafana with localhost:9090 (and localhost:9090/target also) then it is giving below error on pagespeeed dashboard.

{"err":{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","silent":true,"url":"http://localhost:9090/api/v1/series?match[]=pagespeed_lighthouse_category_score&start=1556176768&end=1556180368","retry":0,"headers":{"Accept":"application/json, text/plain, /"}},"statusText":"","xhrStatus":"error"},"cancelled":true}

That's weird, the data source should already be there.

If you create a grafana source, you need to set prometheus:9090 (not localhost:9090) since localhost is grafana itself in the docker networking

data source and dashboard were not present. i manually imported it and created dashboard. below is snapshot of ports.

image

I can't reproduce, did the same thing as in readme and I got everything working

image

image

i am doing --> git clone https://github.com/foomo/pagespeed_exporter
and--> git clone git@github.com:foomo/pagespeed_exporter.git
is not working for me...is this correct?

It's the same repository, only thing is that I'm using SSH keys to authenticate.

You can also try docker-compose down (in the example folder) it needs a few minutes to scrape.

Also, refresh the page after a minute-or-two (on grafana) to pick up the hosts

is below correct? getting response on 3000 port, but not on 9271

image

I'd suggest you check the logs in prometheus and why it's not starting. Perhaps the port is already allocated or something. (e.g. docker logs -f example_prometheus_1)

But at this point, it's more of a docker / prometheus issue than a pagespeed issue

level=error ts=2019-04-25T11:34:47.250Z caller=main.go:717 err="error loading config from "/etc/prometheus/prometheus.yml": couldn't load configuration (--config.file="/etc/prometheus/prometheus.yml"): open /etc/prometheus/prometheus.yml: permission denied"

You can add https://stackoverflow.com/questions/48727548/how-to-configure-docker-compose-yml-to-up-a-container-as-root

Aka to run prometheus as root to have access to the file (or give access to the permissions)

Just make it run, and everything will work

cool. it worked. i gave execute permission to all folders and sub-folders. and it worked.

now another query about execution, how often the url (google.com is hit or tested?

i have changed google to another url (github.com) but stats are not showing on grafana. please see below docker-compose.yml file. did docker-compose down and docker-compose up again.

image

I'd presume that it's showing now?