prometheus-community / elasticsearch_exporter

Elasticsearch stats exporter for Prometheus
Apache License 2.0
1.93k stars 790 forks source link

Error decoding Elasticsearch 6 output #133

Closed carlosjgp closed 6 years ago

carlosjgp commented 6 years ago

I have built a Docker image using the most recent commit (6101e75) and run it like this

docker run --network=host --rm justwatch/elasticsearch_exporter:my-branch -es.uri=https://localhost:2006 -es.ssl-skip-verify -es.all -es.indices

where https://localhost:2006 is an ssh tunnel to an instance in my AWS VPC that can access my AWS ES instance

when I request the Prometheus metrics I have this logs on the exporter

level=info ts=2018-03-20T10:50:31.247196875Z caller=main.go:78 msg="starting elasticsearch_exporter" addr=:9108
level=warn ts=2018-03-20T10:50:34.808472329Z caller=cluster_health.go:258 msg="failed to fetch and decode cluster health" err="failed to get cluster health from https://localhost:2006/_cluster/health: Get https://localhost:2006/_cluster/health: x509: certificate is valid for *.amazonaws.com, not localhost"
level=warn ts=2018-03-20T10:50:34.808551908Z caller=nodes.go:1383 msg="failed to fetch and decode node stats" err="failed to get cluster health from https://localhost:2006/_nodes/stats: Get https://localhost:2006/_nodes/stats: x509: certificate is valid for *.amazonaws.com, not localhost"
level=warn ts=2018-03-20T10:50:34.816269535Z caller=indices.go:409 msg="failed to fetch and decode index stats" err="failed to get index stats from https://localhost:2006/_all/_stats: Get https://localhost:2006/_all/_stats: x509: certificate is valid for *.amazonaws.com, not localhost"

I did send the http requests manually and this is the output https://gist.github.com/carlosjgp/6e6a6d74eda703b93e9067734ff4618c

I can try to create a PR to add a parameter to configure the ES version... maybe is not that easy. I would like to start doing some GoLang coding, so I'm quite keen to try it

zwopir commented 6 years ago

Hi Carlos,

thanks for bringing this up and thanks for the helpful gist. I need to have a closer look at it. Until now we tried to avoid explicitly setting an ES version. If possible we'd like to stick with an version agnostic elasticsearch_exporter. To avoid creating an unnecessaryPR, we should finish this discussion about setting an ES version first.

As far as I know, ES supports POST and GET requests for some queries. So maybe a possible solution is to add a method flag. I need to evaluate this. If it is the way to go, I'll happily help you with creating the code/PR.

milesbxf commented 6 years ago

I've just looked into this, and the errors above are purely SSL verification errors - I tested the project with ES version 6 and it still works perfectly :+1:

zwopir commented 6 years ago

Hi @carlosjgp, I've just merged a es.ssl-skip-verify fix PR. Can you try the latest master again with -es.ssl-skip-verify flag set?!

zwopir commented 6 years ago

closing this issue as I think it's resolved. Feel free to re-open if the problem isn't solved for you, @carlosjgp

sammit20 commented 6 years ago

I am still facing this issue. Getting 401 error, bash-4.1$./elasticsearch_exporter -es.all=true -es.indices=true -es.shards=true -es.ssl-skip-verify -es.uri="http://localhost:9200" level=info ts=2018-07-03T08:14:46.113926062Z caller=main.go:81 msg="starting elasticsearch_exporter" addr=:9108 level=warn ts=2018-07-03T08:14:54.129103043Z caller=nodes.go:1383 msg="failed to fetch and decode node stats" err="HTTP Request failed with code 401" level=warn ts=2018-07-03T08:14:54.129136234Z caller=indices.go:458 msg="failed to fetch and decode index stats" err="HTTP Request failed with code 401" due to which I am not able to get all the metrics supported by the elasticsearch exporter.

zwopir commented 6 years ago

Hi sammit20,

using -es.ssl-skip-verify with a non-https es.uri doesn't make sense. So your either getting the 401 because TLS is required (thus using a https es.uri) or basic auth is required. In the latter case you can specify the credentials like so -es.uri=http://username:password@localhost:9200

sammit20 commented 6 years ago

Thanks zwopir for the quick response. However my cluster doesn't have any authentication specified. Its a test one for checking the elasticsearch exporter metrics. I can easily access the apis like http://localhost:9200, http://localhost:9200//_nodes/stats,http:/localhost:9200/_nodes/stats, http://localhost:9200/_all/_stats without any authentication. So in that case what value I need to pass in the ES.URI parameter to get the nodes and indices metrics?

zwopir commented 6 years ago

Hi sammit20,

I tried to reproduce your issue with the latest ES docker image. Started the image as described in https://www.elastic.co/guide/en/elasticsearch/reference/6.3/docker.html and then the exporter with

./elasticsearch_exporter -es.all=true -es.indices=true -es.shards=true

I was not able to reproduce your issue. The es.uri Parameter defaults to http://localhost:9200, so you don't need to specify it, if you are running the exporter on one of the ES cluster nodes

sammit20 commented 6 years ago

Thanks Zwopir for checking on that. Can you check the same from Binary as well? As I've downloaded the binary"elasticsearch_exporter_1.0.3rc1.linux_amd64-v1.0.3rc1" and executing with that.

zwopir commented 6 years ago

I did check it with the binary. The ES (not the elasticsearch_exporter) was running in the container

sammit20 commented 6 years ago

Thanks zwopir for your help. The issue was with my cookie which was not letting me to access metrics page. Is there any way to include the cookie while executing the exporter?