diff --git a/.gitignore b/.gitignore index 0e107e12..fa92b3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ build gradle-wrapper.jar gradle-wrapper.properties +gradlew +gradlew.bat # Mac .DS_Store diff --git a/README.md b/README.md index ec6e023b..66609ded 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ It collects all relevant metrics and makes them available to Prometheus via the - Circuit Breaker - Indices status - Cluster settings (selected [disk allocation settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/disk-allocator.html) only) +- Snapshot lifecycle stats: + - retention run + - per policy-id stats (snapshot taken, failed, deleted, failed delete) ## Compatibility matrix @@ -80,6 +83,11 @@ To disable exporting cluster settings use: prometheus.cluster.settings: false ``` +To disable exporting snapshot lifecycle stats use: +``` +prometheus.slm: false +``` + These settings can be also [updated dynamically](https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html). ## Uninstall diff --git a/build.gradle b/build.gradle index f43fe643..3ea05c9f 100644 --- a/build.gradle +++ b/build.gradle @@ -94,6 +94,7 @@ configurations { dependencies { compile "org.elasticsearch:elasticsearch:${versions.elasticsearch}" + compile "org.elasticsearch.client:x-pack-transport:${versions.elasticsearch}" compile "io.prometheus:simpleclient:${versions.prometheus}" compile "io.prometheus:simpleclient_common:${versions.prometheus}" compile "org.apache.logging.log4j:log4j-api:${versions.log4j}" diff --git a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCatalog.java b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCatalog.java index f4dd0505..f7c4a76f 100644 --- a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCatalog.java +++ b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCatalog.java @@ -20,13 +20,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.rest.prometheus.RestPrometheusMetricsAction; - import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.HashMap; import java.util.Locale; - import io.prometheus.client.CollectorRegistry; import io.prometheus.client.Gauge; import io.prometheus.client.Summary; diff --git a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java index 4e0394c2..b447b446 100644 --- a/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java +++ b/src/main/java/org/compuscene/metrics/prometheus/PrometheusMetricsCollector.java @@ -18,6 +18,7 @@ package org.compuscene.metrics.prometheus; import org.elasticsearch.action.ClusterStatsData; +import org.elasticsearch.action.PrometheusSnapshotLifecycleStats; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.indices.stats.CommonStats; @@ -37,11 +38,9 @@ import org.elasticsearch.script.ScriptStats; import org.elasticsearch.threadpool.ThreadPoolStats; import org.elasticsearch.transport.TransportStats; - import java.util.HashMap; import java.util.List; import java.util.Map; - import io.prometheus.client.Summary; /** @@ -51,13 +50,16 @@ public class PrometheusMetricsCollector { private boolean isPrometheusClusterSettings; private boolean isPrometheusIndices; + private boolean isPrometheusSlm; private PrometheusMetricsCatalog catalog; public PrometheusMetricsCollector(PrometheusMetricsCatalog catalog, boolean isPrometheusIndices, - boolean isPrometheusClusterSettings) { + boolean isPrometheusClusterSettings, + boolean isPrometheusSlm) { this.isPrometheusClusterSettings = isPrometheusClusterSettings; this.isPrometheusIndices = isPrometheusIndices; + this.isPrometheusSlm = isPrometheusSlm; this.catalog = catalog; } @@ -79,6 +81,7 @@ public void registerMetrics() { registerOsMetrics(); registerFsMetrics(); registerESSettings(); + registerSlmMetrics(); } private void registerClusterMetrics() { @@ -916,8 +919,38 @@ private void updateESSettings(ClusterStatsData stats) { } } + private void registerSlmMetrics() { + catalog.registerClusterGauge("slm_retention_run_count", "SLM Retention Run Count"); + catalog.registerClusterGauge("slm_retention_failed_count", "SLM Retention Failed Count"); + catalog.registerClusterGauge("slm_retention_timed_out", "SLM Retention Timed Out"); + catalog.registerClusterGauge("slm_snapshot_taken", "SLM Snapshot Taken", "policy_id"); + catalog.registerClusterGauge("slm_snapshot_failed", "SLM Snapshot Failed", "policy_id"); + catalog.registerClusterGauge("slm_snapshot_deleted", "SLM Snapshot Deleted", "policy_id"); + catalog.registerClusterGauge("slm_snapshot_delete_failure", "SLM Snapshot Delete Failure", "policy_id"); + } + + private void updateSlmMetrics(PrometheusSnapshotLifecycleStats slmStats) { + if (slmStats != null) { + catalog.setClusterGauge("slm_retention_run_count", slmStats.getRetentionRunCount().count()); + catalog.setClusterGauge("slm_retention_failed_count", slmStats.getRetentionFailedCount().count()); + catalog.setClusterGauge("slm_retention_timed_out", slmStats.getRetentionTimedOut().count()); + for (Map.Entry entry : + slmStats.getPolicyStats().entrySet()) { + catalog.setClusterGauge("slm_snapshot_taken", entry.getValue().getSnapshotsTaken().count(), + entry.getValue().getPolicyId()); + catalog.setClusterGauge("slm_snapshot_failed", entry.getValue().getSnapshotsFailed().count(), + entry.getValue().getPolicyId()); + catalog.setClusterGauge("slm_snapshot_deleted", entry.getValue().getSnapshotsDeleted().count(), + entry.getValue().getPolicyId()); + catalog.setClusterGauge("slm_snapshot_delete_failure", + entry.getValue().getSnapshotDeleteFailures().count(), entry.getValue().getPolicyId()); + } + } + } + public void updateMetrics(ClusterHealthResponse clusterHealthResponse, NodeStats nodeStats, - IndicesStatsResponse indicesStats, ClusterStatsData clusterStatsData) { + IndicesStatsResponse indicesStats, ClusterStatsData clusterStatsData, + PrometheusSnapshotLifecycleStats slmStats) { Summary.Timer timer = catalog.startSummaryTimer("metrics_generate_time_seconds"); updateClusterMetrics(clusterHealthResponse); @@ -939,6 +972,7 @@ public void updateMetrics(ClusterHealthResponse clusterHealthResponse, NodeStats if (isPrometheusClusterSettings) { updateESSettings(clusterStatsData); } + updateSlmMetrics(slmStats); timer.observeDuration(); } diff --git a/src/main/java/org/compuscene/metrics/prometheus/PrometheusSettings.java b/src/main/java/org/compuscene/metrics/prometheus/PrometheusSettings.java index 69f59e08..c30efb35 100644 --- a/src/main/java/org/compuscene/metrics/prometheus/PrometheusSettings.java +++ b/src/main/java/org/compuscene/metrics/prometheus/PrometheusSettings.java @@ -40,15 +40,21 @@ public class PrometheusSettings { public static final Setting PROMETHEUS_INDICES = Setting.boolSetting("prometheus.indices", true, Setting.Property.Dynamic, Setting.Property.NodeScope); + public static final Setting PROMETHEUS_SLM = + Setting.boolSetting("prometheus.slm", true, + Setting.Property.Dynamic, Setting.Property.NodeScope); private volatile boolean clusterSettings; private volatile boolean indices; + private volatile boolean slm; public PrometheusSettings(Settings settings, ClusterSettings clusterSettings) { setPrometheusClusterSettings(PROMETHEUS_CLUSTER_SETTINGS.get(settings)); setPrometheusIndices(PROMETHEUS_INDICES.get(settings)); + setPrometheusSlm(PROMETHEUS_SLM.get(settings)); clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_CLUSTER_SETTINGS, this::setPrometheusClusterSettings); clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_INDICES, this::setPrometheusIndices); + clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_SLM, this::setPrometheusSlm); } private void setPrometheusClusterSettings(boolean flag) { @@ -59,6 +65,10 @@ private void setPrometheusIndices(boolean flag) { this.indices = flag; } + private void setPrometheusSlm(boolean flag) { + this.slm = flag; + } + public boolean getPrometheusClusterSettings() { return this.clusterSettings; } @@ -66,4 +76,8 @@ public boolean getPrometheusClusterSettings() { public boolean getPrometheusIndices() { return this.indices; } + + public boolean getPrometheusSlm() { + return this.slm; + } } diff --git a/src/main/java/org/elasticsearch/action/ClusterStatsData.java b/src/main/java/org/elasticsearch/action/ClusterStatsData.java index 2e25f9c6..a85a3815 100644 --- a/src/main/java/org/elasticsearch/action/ClusterStatsData.java +++ b/src/main/java/org/elasticsearch/action/ClusterStatsData.java @@ -17,7 +17,6 @@ package org.elasticsearch.action; import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.*; - import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.cluster.metadata.Metadata; @@ -28,7 +27,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.unit.RatioValue; - import java.io.IOException; diff --git a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsRequest.java b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsRequest.java index dc3aca6e..59f3ad82 100644 --- a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsRequest.java +++ b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsRequest.java @@ -19,7 +19,6 @@ import org.elasticsearch.action.support.master.MasterNodeReadRequest; import org.elasticsearch.common.io.stream.StreamInput; - import java.io.IOException; /** diff --git a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsResponse.java b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsResponse.java index b75205f9..62c58b15 100644 --- a/src/main/java/org/elasticsearch/action/NodePrometheusMetricsResponse.java +++ b/src/main/java/org/elasticsearch/action/NodePrometheusMetricsResponse.java @@ -17,27 +17,36 @@ package org.elasticsearch.action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.compuscene.metrics.prometheus.PrometheusSettings; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.admin.indices.stats.PackageAccessHelper; +import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.*; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; - +import org.elasticsearch.rest.prometheus.RestPrometheusMetricsAction; +import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; +import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; /** * Action response class for Prometheus Exporter plugin. */ public class NodePrometheusMetricsResponse extends ActionResponse { + private static final Logger logger = LogManager.getLogger(RestPrometheusMetricsAction.class); private ClusterHealthResponse clusterHealth; private NodeStats nodeStats; @Nullable private IndicesStatsResponse indicesStats; private ClusterStatsData clusterStatsData = null; + private PrometheusSnapshotLifecycleStats slmStats = null; public NodePrometheusMetricsResponse(StreamInput in) throws IOException { super(in); @@ -45,18 +54,80 @@ public NodePrometheusMetricsResponse(StreamInput in) throws IOException { nodeStats = new NodeStats(in); indicesStats = PackageAccessHelper.createIndicesStatsResponse(in); clusterStatsData = new ClusterStatsData(in); + slmStats = new PrometheusSnapshotLifecycleStats(in); + } + + private InputStreamStreamInput getInputStreamFromWriteable(Writeable w) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos); + ByteArrayInputStream bais = null; + InputStreamStreamInput issi; + try { + w.writeTo(osso); + bais = new ByteArrayInputStream(baos.toByteArray()); + issi = new InputStreamStreamInput(bais); + } catch (IOException e) { + throw e; + } finally { + osso.close(); + baos.close(); + if (bais != null) { + bais.close(); + } + } + return issi; + } + + private PrometheusSnapshotLifecycleStats getPrometheusSnapshotLifecycleStats(ClusterStateResponse clusterStateResponse) { + Metadata m = clusterStateResponse.getState().getMetadata(); + InputStreamStreamInput issiSnapshotLifecycleMetadata = null; + InputStreamStreamInput issiSlmStats = null; + PrometheusSnapshotLifecycleStats prometheusSnapshotLifecycleStats = null; + try { + Metadata.Custom metdataCustom = m.getCustoms().get(SnapshotLifecycleMetadata.TYPE); + if (metdataCustom != null) { + issiSnapshotLifecycleMetadata = getInputStreamFromWriteable(metdataCustom); + SnapshotLifecycleStats slmStats = new SnapshotLifecycleMetadata(issiSnapshotLifecycleMetadata).getStats(); + issiSlmStats = getInputStreamFromWriteable(slmStats); + prometheusSnapshotLifecycleStats = new PrometheusSnapshotLifecycleStats(issiSlmStats); + } + } catch (IOException e) { + logger.error("Failed to get SLM stats", e); + } finally { + if (issiSnapshotLifecycleMetadata != null) { + try { + issiSnapshotLifecycleMetadata.close(); + } catch (IOException e) { + logger.error("Failed to close issiSnapshotLifecycleMetadata", e); + } + } + if (issiSlmStats != null) { + try { + issiSlmStats.close(); + } catch (IOException e) { + logger.error("Failed to close issiSlmStats", e); + } + } + } + return prometheusSnapshotLifecycleStats; } public NodePrometheusMetricsResponse(ClusterHealthResponse clusterHealth, NodeStats nodesStats, @Nullable IndicesStatsResponse indicesStats, @Nullable ClusterStateResponse clusterStateResponse, Settings settings, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, + PrometheusSettings prometheusSettings) { this.clusterHealth = clusterHealth; this.nodeStats = nodesStats; this.indicesStats = indicesStats; if (clusterStateResponse != null) { - this.clusterStatsData = new ClusterStatsData(clusterStateResponse, settings, clusterSettings); + if (prometheusSettings.getPrometheusClusterSettings()) { + this.clusterStatsData = new ClusterStatsData(clusterStateResponse, settings, clusterSettings); + } + if (prometheusSettings.getPrometheusSlm()) { + this.slmStats = getPrometheusSnapshotLifecycleStats(clusterStateResponse); + } } } @@ -78,11 +149,17 @@ public ClusterStatsData getClusterStatsData() { return this.clusterStatsData; } + @Nullable + public PrometheusSnapshotLifecycleStats getSlmStats() { + return this.slmStats; + } + @Override public void writeTo(StreamOutput out) throws IOException { clusterHealth.writeTo(out); nodeStats.writeTo(out); out.writeOptionalWriteable(indicesStats); clusterStatsData.writeTo(out); + slmStats.writeTo(out); } } diff --git a/src/main/java/org/elasticsearch/action/PrometheusSnapshotLifecycleStats.java b/src/main/java/org/elasticsearch/action/PrometheusSnapshotLifecycleStats.java new file mode 100644 index 00000000..9c39937f --- /dev/null +++ b/src/main/java/org/elasticsearch/action/PrometheusSnapshotLifecycleStats.java @@ -0,0 +1,116 @@ +/* + * Copyright [2016] [Vincent VAN HOLLEBEKE] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.elasticsearch.action; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.metrics.CounterMetric; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class PrometheusSnapshotLifecycleStats implements Writeable { + private final CounterMetric retentionRunCount = new CounterMetric(); + private final CounterMetric retentionFailedCount = new CounterMetric(); + private final CounterMetric retentionTimedOut = new CounterMetric(); + private final CounterMetric retentionTimeMs = new CounterMetric(); + private final Map policyStats; + + public PrometheusSnapshotLifecycleStats(StreamInput in) throws IOException { + this.policyStats = new ConcurrentHashMap<>(in.readMap(StreamInput::readString, PrometheusSnapshotPolicyStats::new)); + this.retentionRunCount.inc(in.readVLong()); + this.retentionFailedCount.inc(in.readVLong()); + this.retentionTimedOut.inc(in.readVLong()); + this.retentionTimeMs.inc(in.readVLong()); + } + + public CounterMetric getRetentionRunCount() { + return retentionRunCount; + } + + public CounterMetric getRetentionFailedCount() { + return retentionFailedCount; + } + + public CounterMetric getRetentionTimedOut() { + return retentionTimedOut; + } + + public CounterMetric getRetentionTimeMs() { + return retentionTimeMs; + } + + public Map getPolicyStats() { + return policyStats; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeMap(policyStats, StreamOutput::writeString, (v, o) -> o.writeTo(v)); + out.writeVLong(retentionRunCount.count()); + out.writeVLong(retentionFailedCount.count()); + out.writeVLong(retentionTimedOut.count()); + out.writeVLong(retentionTimeMs.count()); + } + + public static class PrometheusSnapshotPolicyStats implements Writeable { + private final String policyId; + private final CounterMetric snapshotsTaken = new CounterMetric(); + private final CounterMetric snapshotsFailed = new CounterMetric(); + private final CounterMetric snapshotsDeleted = new CounterMetric(); + private final CounterMetric snapshotDeleteFailures = new CounterMetric(); + + public PrometheusSnapshotPolicyStats(StreamInput in) throws IOException { + this.policyId = in.readString(); + this.snapshotsTaken.inc(in.readVLong()); + this.snapshotsFailed.inc(in.readVLong()); + this.snapshotsDeleted.inc(in.readVLong()); + this.snapshotDeleteFailures.inc(in.readVLong()); + } + + public String getPolicyId() { + return policyId; + } + + public CounterMetric getSnapshotsTaken() { + return snapshotsTaken; + } + + public CounterMetric getSnapshotsFailed() { + return snapshotsFailed; + } + + public CounterMetric getSnapshotsDeleted() { + return snapshotsDeleted; + } + + public CounterMetric getSnapshotDeleteFailures() { + return snapshotDeleteFailures; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(policyId); + out.writeVLong(snapshotsTaken.count()); + out.writeVLong(snapshotsFailed.count()); + out.writeVLong(snapshotsDeleted.count()); + out.writeVLong(snapshotDeleteFailures.count()); + } + } +} diff --git a/src/main/java/org/elasticsearch/action/TransportNodePrometheusMetricsAction.java b/src/main/java/org/elasticsearch/action/TransportNodePrometheusMetricsAction.java index 270adc6d..2f5ef957 100644 --- a/src/main/java/org/elasticsearch/action/TransportNodePrometheusMetricsAction.java +++ b/src/main/java/org/elasticsearch/action/TransportNodePrometheusMetricsAction.java @@ -90,6 +90,7 @@ private class AsyncAction { // read the state of prometheus dynamic settings only once at the beginning of the async request private boolean isPrometheusIndices = prometheusSettings.getPrometheusIndices(); private boolean isPrometheusClusterSettings = prometheusSettings.getPrometheusClusterSettings(); + private boolean isPrometheusSlm = prometheusSettings.getPrometheusSlm(); // All the requests are executed in sequential non-blocking order. // It is implemented by wrapping each individual request with ActionListener @@ -119,7 +120,7 @@ private AsyncAction(ActionListener listener) { // Cluster settings are get via ClusterStateRequest (see elasticsearch RestClusterGetSettingsAction for details) // We prefer to send it to master node (hence local=false; it should be set by default but we want to be sure). - this.clusterStateRequest = isPrometheusClusterSettings ? Requests.clusterStateRequest() + this.clusterStateRequest = (isPrometheusClusterSettings || isPrometheusSlm) ? Requests.clusterStateRequest() .clear().metadata(true).local(false) : null; } @@ -147,7 +148,7 @@ public void onFailure(Exception e) { @Override public void onResponse(IndicesStatsResponse response) { indicesStatsResponse = response; - if (isPrometheusClusterSettings) { + if (isPrometheusClusterSettings || isPrometheusSlm) { client.admin().cluster().state(clusterStateRequest, clusterStateResponseActionListener); } else { gatherRequests(); @@ -202,7 +203,7 @@ protected NodePrometheusMetricsResponse buildResponse(ClusterHealthResponse clus @Nullable ClusterStateResponse clusterStateResponse) { NodePrometheusMetricsResponse response = new NodePrometheusMetricsResponse(clusterHealth, nodesStats.getNodes().get(0), indicesStats, clusterStateResponse, - settings, clusterSettings); + settings, clusterSettings, prometheusSettings); if (logger.isTraceEnabled()) { logger.trace("Return response: [{}]", response); } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/PackageAccessHelper.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/PackageAccessHelper.java index 8ad9eb5d..9341eb2b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/PackageAccessHelper.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/PackageAccessHelper.java @@ -17,7 +17,6 @@ package org.elasticsearch.action.admin.indices.stats; import org.elasticsearch.common.io.stream.StreamInput; - import java.io.IOException; /** diff --git a/src/main/java/org/elasticsearch/plugin/prometheus/PrometheusExporterPlugin.java b/src/main/java/org/elasticsearch/plugin/prometheus/PrometheusExporterPlugin.java index d9e0ae5c..7b7f0e4d 100644 --- a/src/main/java/org/elasticsearch/plugin/prometheus/PrometheusExporterPlugin.java +++ b/src/main/java/org/elasticsearch/plugin/prometheus/PrometheusExporterPlugin.java @@ -18,7 +18,6 @@ package org.elasticsearch.plugin.prometheus; import static java.util.Collections.singletonList; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.compuscene.metrics.prometheus.PrometheusSettings; @@ -34,7 +33,6 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.prometheus.RestPrometheusMetricsAction; - import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -71,7 +69,8 @@ public List getRestHandlers(Settings settings, RestController restC public List> getSettings() { List> settings = Arrays.asList( PrometheusSettings.PROMETHEUS_CLUSTER_SETTINGS, - PrometheusSettings.PROMETHEUS_INDICES + PrometheusSettings.PROMETHEUS_INDICES, + PrometheusSettings.PROMETHEUS_SLM ); return Collections.unmodifiableList(settings); } diff --git a/src/main/java/org/elasticsearch/rest/prometheus/RestPrometheusMetricsAction.java b/src/main/java/org/elasticsearch/rest/prometheus/RestPrometheusMetricsAction.java index 8c4d2c44..5a7cbe67 100644 --- a/src/main/java/org/elasticsearch/rest/prometheus/RestPrometheusMetricsAction.java +++ b/src/main/java/org/elasticsearch/rest/prometheus/RestPrometheusMetricsAction.java @@ -17,9 +17,10 @@ package org.elasticsearch.rest.prometheus; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.action.NodePrometheusMetricsAction.INSTANCE; import static org.elasticsearch.rest.RestRequest.Method.GET; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.compuscene.metrics.prometheus.PrometheusMetricsCatalog; @@ -33,12 +34,9 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.RestResponseListener; - import java.util.List; import java.util.Locale; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; /** * REST action class for Prometheus Exporter plugin. @@ -92,10 +90,11 @@ public RestResponse buildResponse(NodePrometheusMetricsResponse response) throws PrometheusMetricsCollector collector = new PrometheusMetricsCollector( catalog, prometheusSettings.getPrometheusIndices(), - prometheusSettings.getPrometheusClusterSettings()); + prometheusSettings.getPrometheusClusterSettings(), + prometheusSettings.getPrometheusSlm()); collector.registerMetrics(); collector.updateMetrics(response.getClusterHealth(), response.getNodeStats(), response.getIndicesStats(), - response.getClusterStatsData()); + response.getClusterStatsData(), response.getSlmStats()); return new BytesRestResponse(RestStatus.OK, collector.getCatalog().toTextFormat()); } });