Skip to content

Commit 0f827d4

Browse files
committed
Added ability to disable indices metrics in configuration
1 parent 92b352e commit 0f827d4

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
This is a builtin exporter from ElasticSearch to Prometheus.
44
It collects all relevant metrics and make them available to Prometheus via ElasticSearch REST API.
55

6-
Current available metrics are :
6+
**Current available metrics are :**
77

88
- Cluster status
9-
- Node status :
9+
- Nodes status :
1010
- JVM
1111
- Indices (global)
1212
- Transport
@@ -16,6 +16,7 @@ Current available metrics are :
1616
- Operating System
1717
- File System
1818
- Circuit Breaker
19+
- Indices status
1920

2021
## Compatibility matrix
2122

@@ -49,14 +50,20 @@ Current available metrics are :
4950
- On old 2.x.x versions :
5051
./bin/plugin install https://github.com/vvanholl/elasticsearch-prometheus-exporter/releases/download/2.4.1.0/elasticsearch-prometheus-exporter-2.4.1.0.zip
5152

52-
Do not forget to restart the node after installation !
53+
**Do not forget to restart the node after installation !**
5354

5455
Note that the plugin needs special permissions :
5556

5657
- java.lang.RuntimePermission accessClassInPackage.sun.misc
5758
- java.lang.RuntimePermission accessDeclaredMembers
5859
- java.lang.reflect.ReflectPermission suppressAccessChecks
5960

61+
If you have a lot of indices and think this data is irelevant, you can disable in the main configuration file:
62+
63+
```
64+
prometheus.indices: false
65+
```
66+
6067
## Uninstall
6168

6269
- Since ElasticSearch 5.0.0 :

src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import org.elasticsearch.client.Client;
1616
import org.elasticsearch.cluster.health.ClusterIndexHealth;
1717
import org.elasticsearch.common.logging.ESLoggerFactory;
18+
import org.elasticsearch.common.settings.Setting;
19+
import org.elasticsearch.common.settings.Setting.Property;
20+
import org.elasticsearch.common.settings.Settings;
1821
import org.elasticsearch.http.HttpStats;
1922
import org.elasticsearch.indices.NodeIndicesStats;
2023
import org.elasticsearch.indices.breaker.AllCircuitBreakerStats;
@@ -31,16 +34,20 @@
3134
import java.util.Map;
3235

3336
public class PrometheusMetricsCollector {
37+
public static final Setting<Boolean> PROMETHEUS_INDICES = Setting.boolSetting("prometheus.indices", true, Property.NodeScope);
38+
3439
private final static Logger logger = ESLoggerFactory.getLogger(RestPrometheusMetricsAction.class.getSimpleName());
3540

41+
private final Settings settings;
3642
private final Client client;
3743

3844
private String cluster;
3945
private String node;
4046

4147
private PrometheusMetricsCatalog catalog;
4248

43-
public PrometheusMetricsCollector(final Client client) {
49+
public PrometheusMetricsCollector(Settings settings, final Client client) {
50+
this.settings = settings;
4451
this.client = client;
4552

4653
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("_local").all();
@@ -67,7 +74,7 @@ private void registerMetrics() {
6774
registerCircuitBreakerMetrics();
6875
registerThreadPoolMetrics();
6976
registerFsMetrics();
70-
registerPerIndexMetrics();
77+
if (PROMETHEUS_INDICES.get(settings)) registerPerIndexMetrics();
7178
}
7279

7380
private void registerClusterMetrics() {
@@ -768,14 +775,15 @@ public void updateMetrics() {
768775
updateThreadPoolMetrics(nodeStats.getThreadPool());
769776
updateFsMetrics(nodeStats.getFs());
770777

771-
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
772-
ActionFuture<IndicesStatsResponse> f = client.admin().indices().stats(indicesStatsRequest);
773-
try {
774-
updatePerIndexMetrics(clusterHealthResponse, f.get());
775-
} catch (Exception e) {
776-
logger.warn("Could not get indices statistics");
778+
if (PROMETHEUS_INDICES.get(settings)) {
779+
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
780+
ActionFuture<IndicesStatsResponse> f = client.admin().indices().stats(indicesStatsRequest);
781+
try {
782+
updatePerIndexMetrics(clusterHealthResponse, f.get());
783+
} catch (Exception e) {
784+
logger.warn("Could not get indices statistics");
785+
}
777786
}
778-
779787
timer.observeDuration();
780788
}
781789

src/main/java/org/elasticsearch/plugin/prometheus/PrometheusExporterPlugin.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.elasticsearch.plugin.prometheus;
22

33
import org.apache.logging.log4j.Logger;
4+
import org.compuscene.metrics.prometheus.PrometheusMetricsCollector;
45
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
56
import org.elasticsearch.cluster.node.DiscoveryNodes;
67
import org.elasticsearch.common.inject.Inject;
78
import org.elasticsearch.common.logging.Loggers;
8-
import org.elasticsearch.common.settings.ClusterSettings;
9-
import org.elasticsearch.common.settings.IndexScopedSettings;
10-
import org.elasticsearch.common.settings.Settings;
11-
import org.elasticsearch.common.settings.SettingsFilter;
9+
import org.elasticsearch.common.settings.*;
1210
import org.elasticsearch.index.IndexModule;
1311
import org.elasticsearch.plugins.ActionPlugin;
1412
import org.elasticsearch.plugins.Plugin;
@@ -24,9 +22,12 @@ public class PrometheusExporterPlugin extends Plugin implements ActionPlugin {
2422

2523
private final Logger logger = Loggers.getLogger(PrometheusExporterPlugin.class);
2624

25+
private final Settings settings;
26+
2727
@Inject
2828
public PrometheusExporterPlugin(Settings settings) {
29-
logger.info("starting Prometheus exporter plugin...");
29+
logger.info("starting Prometheus exporter plugin");
30+
this.settings = settings;
3031
}
3132

3233
@Override
@@ -41,4 +42,10 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
4142
);
4243
}
4344

45+
@Override
46+
public List<Setting<?>> getSettings() {
47+
return Arrays.asList(
48+
PrometheusMetricsCollector.PROMETHEUS_INDICES
49+
);
50+
}
4451
}

src/main/java/org/elasticsearch/rest/prometheus/RestPrometheusMetricsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public RestPrometheusMetricsAction(Settings settings, RestController controller)
3535
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
3636
logger.trace(String.format("Received request for Prometheus metrics from %s", request.getRemoteAddress().toString()));
3737

38-
collector.compareAndSet(null, new PrometheusMetricsCollector(client));
38+
collector.compareAndSet(null, new PrometheusMetricsCollector(settings, client));
3939

4040
collector.get().updateMetrics();
4141

0 commit comments

Comments
 (0)