Skip to content

Commit 1bf0399

Browse files
committed
feat: support for scraping multiple elasticsearch instance
1 parent f064629 commit 1bf0399

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ elasticsearch_exporter:
2929
- "127.0.0.1:9114:9114"
3030
```
3131
32+
- /metrics endpoint is used to scrape the elasticsearch-exporter.
33+
- /probe endpoint is used to scrape multiple elasticsearch instances.
34+
3235
#### Kubernetes
3336
3437
You can find a helm chart in the prometheus-community charts repository at <https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-elasticsearch-exporter>
@@ -103,6 +106,49 @@ Further Information
103106
- [Defining Roles](https://www.elastic.co/guide/en/elastic-stack-overview/7.3/defining-roles.html)
104107
- [Privileges](https://www.elastic.co/guide/en/elastic-stack-overview/7.3/security-privileges.html)
105108

109+
110+
### Multi exporter mode
111+
112+
Pass the es url via the url parameter.
113+
114+
```
115+
http://localhost:9114/probe?target=http://server1:9200&auth_module=TEST
116+
```
117+
118+
- target: es url
119+
- auth_module: es url对应的用户名密码环境变量 exp: ES_{auth_module}_USERNAME=elastic, ES_{auth_module}_PASSWORD
120+
121+
```
122+
elasticsearch_exporter:
123+
image: quay.io/prometheuscommunity/elasticsearch-exporter:latest
124+
environment:
125+
- ES_TEST_USERNAME=elastic
126+
- ES_TEST_PASSWORD=changeme
127+
restart: always
128+
ports:
129+
- "127.0.0.1:9114:9114"
130+
```
131+
132+
On the prometheus side you can set a scrape config as follows
133+
```
134+
- job_name: elasticsearch # To get metrics about the elasticsearch exporter’s targets
135+
static_configs:
136+
- targets:
137+
# All elasticsearch hostnames to monitor.
138+
- http://server1:9200
139+
- http://server2:9200
140+
relabel_configs:
141+
- source_labels: [__address__]
142+
target_label: __param_target
143+
- source_labels: [__param_target]
144+
target_label: instance
145+
# The auth_module is used to find out the username and password from the environment variables.
146+
- target_label: __param_auth_module
147+
replacement: test
148+
- target_label: __address__
149+
# The elasticsearch_exporter host:port
150+
replacement: localhost:9114
151+
```
106152
### Metrics
107153

108154
| Name | Type | Cardinality | Help |

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/url"
2020
"os"
2121
"os/signal"
22+
"strings"
2223
"time"
2324

2425
"context"
@@ -194,6 +195,7 @@ func main() {
194195

195196
authModule := params.Get("auth_module")
196197
if authModule != "" {
198+
authModule = strings.ToUpper(authModule)
197199
targetUsername = os.Getenv(fmt.Sprintf("ES_%s_USERNAME", authModule))
198200
targetPassword = os.Getenv(fmt.Sprintf("ES_%s_PASSWORD", authModule))
199201
}

0 commit comments

Comments
 (0)