# Setting up Elasticsearch servicemonitor for prometheus

**URL:** <https://discuss.elastic.co/t/setting-up-elasticsearch-servicemonitor-for-prometheus/374831>\
**Category:** Metrics\
**Created:** [February 20, 2025, 6:23pm UTC](https://discuss.elastic.co/t/setting-up-elasticsearch-servicemonitor-for-prometheus/374831 "2025-02-20T18:23:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ragc007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ragc007/32/137275_2.png) [@ragc007](https://discuss.elastic.co/u/ragc007)\
**Post date:** [February 20, 2025, 6:23pm UTC](https://discuss.elastic.co/t/setting-up-elasticsearch-servicemonitor-for-prometheus/374831/1 "2025-02-20T18:23:13Z")

</div>

trying to setup servicemonitor for elasticsearch exporter to expose elasticsearch cluster metrics to prometheus, but exporter fails to connect to elasticsearch cluster

in exporter we are passing the service url along with port but it seems it trying to connect localhost [we checked the logs and show that]

we logged in to pods and check the environment variable for url and it shows correct value

we have configured exporter and service exposing metrics to 9108 port and our elasticsearch url is running at 9200 port

# logs

level=error ts=2025-02-20T18:23:10.343471202Z caller=clusterinfo.go:188 msg="failed to retrieve cluster info from ES" err="Get "[http://localhost:9200/\](http://localhost:9200/%5C)": dial tcp [::1]:9200: connect: connection refused"  
level=info ts=2025-02-20T18:28:10.342907259Z caller=clusterinfo.go:183 msg="providing consumers with updated cluster info label"  
level=error ts=2025-02-20T18:28:10.343653485Z caller=clusterinfo.go:267 msg="failed to get cluster info" err="Get "[http://localhost:9200/\](http://localhost:9200/%5C)": dial tcp [::1]:9200: connect: connection refused"  
level=error ts=2025-02-20T18:28:10.343710811Z caller=clusterinfo.go:188 msg="failed to retrieve cluster info from ES" err="Get "[http://localhost:9200/\](http://localhost:9200/%5C)": dial tcp [::1]:9200: connect: connection refused"

# ========= exporter servicemonitor

apiVersion: [monitoring.coreos.com/v1](http://monitoring.coreos.com/v1)  
kind: ServiceMonitor  
metadata:  
name: elasticsearch-monitor  
namespace: exporter-test  
labels:  
[app.kubernetes.io/instance:](http://app.kubernetes.io/instance:) exporter-test  
[openshift.io/user-monitoring:](http://openshift.io/user-monitoring:) "true"  
spec:  
endpoints:  
- interval: 30s  
port: "http"  
namespaceSelector:  
matchNames:  
- exporter-test  
selector:  
matchLabels:  
app: exporter-test

# exporter

apiVersion: apps/v1  
kind: Deployment  
metadata:  
name: exporter-test  
namespace: exporter-test  
spec:  
replicas: 1  
selector:  
matchLabels:  
app: exporter-test  
template:  
metadata:  
labels:  
app: exporter-test  
spec:  
containers:  
- name: exporter-test  
image: [Quay](http://quay.io/prometheuscommunity/elasticsearch-exporter:latest)  
ports:  
- containerPort: 9108  
env:  
- name: ES\_SERVER  
value: "[http://elasticsearch-test-es-http:9200](http://elasticsearch-test-es-http:9200)"  
- name: ES\_ALL  
value: "true" # Query stats for all nodes  
- name: ES\_INDICES  
value: "true" # Query stats for all indices  
- name: ES\_INDICES\_SETTINGS  
value: "true" # Query stats for index settings  
- name: ES\_INDICES\_MAPPINGS  
value: "true" # Query stats for index mappings  
- name: ES\_SHARDS  
value: "true" # Query stats for shards  
- name: ES\_SNAPSHOTS  
value: "true" # Query stats for snapshots  
- name: ES\_CLUSTER\_SETTINGS  
value: "false" # Query stats for cluster settings (disabled)  
- name: ES\_TIMEOUT  
value: "30s" # Timeout for Elasticsearch queries  
- name: ES\_SSL\_SKIP\_VERIFY  
value: "false" # Do not skip SSL verification  
- name: ES\_SSL\_ENABLED  
value: "false" #  
resources:  
limits:  
memory: "500Mi"  
cpu: "500m"  
requests:  
memory: "500Mi"  
cpu: "500m"

# exporter service

apiVersion: v1  
kind: Service  
metadata:  
name: elasticsearch-exporter-test  
namespace: exporter-test  
labels:  
app: exporter-test  
spec:  
ports:  
- port: 9108  
targetPort: 9108  
name: http  
selector:  
app: exporter-test

==============================

---

<div class="post-metadata">

**Author:** ![ragc007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ragc007/32/137275_2.png) [@ragc007](https://discuss.elastic.co/u/ragc007)\
**Post date:** [February 21, 2025, 9:32pm UTC](https://discuss.elastic.co/t/setting-up-elasticsearch-servicemonitor-for-prometheus/374831/2 "2025-02-21T21:32:34Z")

</div>

this is resolved so am closing

---

<div class="post-metadata">

**Author:** ![ankit.jarvis](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@ankit.jarvis](https://discuss.elastic.co/u/ankit.jarvis)\
**Post date:** [November 5, 2025, 5:58am UTC](https://discuss.elastic.co/t/setting-up-elasticsearch-servicemonitor-for-prometheus/374831/3 "2025-11-05T05:58:26Z")

</div>

Hi,

I am facing the same issue while exporting the es metrics (hosted on GKE) to prometheous. Can you guide me how did you resolve it?
