You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -9,11 +9,12 @@ MongoDB aggregation query exporter for [Prometheus](https://prometheus.io).
9
9
10
10
## Features
11
11
12
-
* Support for gauge and counter metrics
12
+
* Support for gauge metrics
13
13
* Multiple metrics for different db/collections
14
14
* Pull and Push (Push is only supported for MongoDB >= 3.6)
15
15
* Supports multiple MongoDB servers
16
16
* Public API for Golang
17
+
* Metric caching support
17
18
18
19
Note that this is not designed to be a replacement for the [MongoDB exporter](https://github.com/percona/mongodb_exporter) to instrument MongoDB internals. This application exports custom MongoDB metrics in the prometheus format based on the queries (aggregations) you want.
19
20
@@ -28,6 +29,12 @@ Get Prometheus MongoDB aggregation query exporter, either as a [binary](https://
28
29
### Helm Chart
29
30
For kubernetes users there is an official helm chart for the MongoDB query exporter.
30
31
32
+
Install the chart (Note only helm 3 is supported):
The config version v1.0 is the predescer of v2.0 and does not have support for multiple MongoDB servers
@@ -188,7 +199,6 @@ metrics:
188
199
labels: []
189
200
mode: pull
190
201
interval: 10
191
-
constLabels: []
192
202
database: mydb
193
203
collection: objects
194
204
pipeline: |
@@ -201,7 +211,8 @@ metrics:
201
211
value: total
202
212
mode: push
203
213
labels: [type,status]
204
-
constLabels: []
214
+
constLabels:
215
+
app: foo
205
216
database: mydb
206
217
collection: queue
207
218
pipeline: |
@@ -231,6 +242,55 @@ metrics:
231
242
]
232
243
```
233
244
245
+
## Cache & Push
246
+
Prometheus is designed to scrape metrics (meaning pull). During each scrape the mongodb-query-exporter will evaluate all configured metrics.
247
+
If you have expensive queries there is an option to cache the aggregation result by setting a cache ttl in secconds.
248
+
However it is more effective to **avoid cache** and design good aggregation pipelines or use a different scrape interval or use the **push** mode.
249
+
For individual metrics and/or MongoDB servers older than 3.6 it might still be a good option though.
250
+
251
+
Example:
252
+
```yaml
253
+
metrics:
254
+
- name: myapp_example_simplevalue_total
255
+
servers: [main]
256
+
help: 'Simple gauge metric which is cached for 5min'
257
+
value: total
258
+
mode: pull
259
+
cache: 300
260
+
database: mydb
261
+
collection: objects
262
+
pipeline: |
263
+
[
264
+
{"$count":"total"}
265
+
]
266
+
```
267
+
268
+
A better approach of reducing load on the MongoDB server is the supported push mode. The push automatically caches the metric at scrape time. However the cache for a metric with mode push
269
+
will be invalidated automatically if anything changes on the configured MongoDB collection. Meaning the aggregation will only be executed if there have been changes during scrape intervals.
270
+
271
+
>**Note**: This requires at least MongoDB 3.6.
272
+
273
+
Example:
274
+
```yaml
275
+
metrics:
276
+
# With the mode push the pipeline is only executed if a change occured on the collection called objects
277
+
- name: myapp_example_simplevalue_total
278
+
servers: [main]
279
+
help: 'Simple gauge metric'
280
+
value: total
281
+
mode: push
282
+
database: mydb
283
+
collection: objects
284
+
pipeline: |
285
+
[
286
+
{"$count":"total"}
287
+
]
288
+
```
289
+
290
+
## Debug
291
+
The mongodb-query-exporters also publishes a counter metric called `mongodb_query_exporter_query_total` which publishes query results for each configured metric.
292
+
Furthermore you might increase the log level to get more insight.
293
+
234
294
## Go API
235
295
Instead using the mongodb-query-exporter you may use the API to integrate the exporter within your go project.
236
296
Please check out the [go package reference](https://pkg.go.dev/badge/github.com/raffis/mongodb-query-exporter?tab=subdirectories).
This command deploys the MongoDB Exporter with the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
0 commit comments