Skip to content

Commit 6d9fb27

Browse files
authored
Merge pull request #12 from bobymicroby/master
Enable support for ES 5.0.0
2 parents 615a7dd + f75713d commit 6d9fb27

File tree

8 files changed

+134
-109
lines changed

8 files changed

+134
-109
lines changed

plugin-descriptor.properties

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
description=Prometheus Exporter
3535
#
3636
# 'version': plugin's version
37-
version=2.4.1.0
37+
version=5.0.0
3838
#
3939
# 'name': the plugin name
4040
name=prometheus-exporter
@@ -68,13 +68,5 @@ java.version=1.8
6868
# elasticsearch release. This version is checked when the plugin
6969
# is loaded so Elasticsearch will refuse to start in the presence of
7070
# plugins with the incorrect elasticsearch.version.
71-
elasticsearch.version=2.4.1
72-
#
73-
### deprecated elements for jvm plugins :
74-
#
75-
# 'isolated': true if the plugin should have its own classloader.
76-
# passing false is deprecated, and only intended to support plugins
77-
# that have hard dependencies against each other. If this is
78-
# not specified, then the plugin is isolated by default.
79-
isolated=false
80-
#
71+
elasticsearch.version=5.0.0
72+
#

plugin-security.policy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
grant {
22
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
3+
permission java.lang.RuntimePermission "accessDeclaredMembers";
34
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
45
};

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</scm>
2828

2929
<properties>
30-
<elasticsearch.version>2.4.1</elasticsearch.version>
30+
<elasticsearch.version>5.0.0</elasticsearch.version>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3232
</properties>
3333

@@ -48,6 +48,12 @@
4848
<artifactId>simpleclient_common</artifactId>
4949
<version>0.0.15</version>
5050
</dependency>
51+
52+
<dependency>
53+
<groupId>org.apache.logging.log4j</groupId>
54+
<artifactId>log4j-api</artifactId>
55+
<version>2.6.2</version>
56+
</dependency>
5157
</dependencies>
5258
<build>
5359
<plugins>

src/main/assemblies/plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<fileSets>
99
<fileSet>
1010
<directory>${project.basedir}</directory>
11-
<outputDirectory>/</outputDirectory>
11+
<outputDirectory>/elasticsearch</outputDirectory>
1212
<includes>
1313
<include>plugin-descriptor.properties</include>
1414
<include>plugin-security.policy</include>
@@ -17,15 +17,15 @@
1717
</fileSets>
1818
<dependencySets>
1919
<dependencySet>
20-
<outputDirectory>/</outputDirectory>
20+
<outputDirectory>/elasticsearch</outputDirectory>
2121
<useProjectArtifact>true</useProjectArtifact>
2222
<useTransitiveFiltering>true</useTransitiveFiltering>
2323
<excludes>
2424
<exclude>org.elasticsearch:elasticsearch</exclude>
2525
</excludes>
2626
</dependencySet>
2727
<dependencySet>
28-
<outputDirectory>/</outputDirectory>
28+
<outputDirectory>/elasticsearch</outputDirectory>
2929
<useProjectArtifact>true</useProjectArtifact>
3030
<useTransitiveFiltering>true</useTransitiveFiltering>
3131
<includes>

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.prometheus.client.Gauge;
66
import io.prometheus.client.Summary;
77
import io.prometheus.client.exporter.common.TextFormat;
8-
import org.elasticsearch.common.logging.ESLogger;
8+
import org.apache.logging.log4j.Logger;
99
import org.elasticsearch.common.logging.ESLoggerFactory;
1010
import org.elasticsearch.rest.prometheus.RestPrometheusMetricsAction;
1111

@@ -14,22 +14,25 @@
1414
import java.io.Writer;
1515
import java.util.HashMap;
1616

17-
public class PrometheusMetricsCatalog {
18-
private final static ESLogger logger = ESLoggerFactory.getLogger(RestPrometheusMetricsAction.class.getSimpleName());
17+
public class PrometheusMetricsCatalog
18+
{
19+
private final static Logger logger = ESLoggerFactory.getLogger(RestPrometheusMetricsAction.class.getSimpleName());
1920

2021
private String cluster;
2122
private String metric_prefix;
2223
private HashMap metrics;
2324
private CollectorRegistry registry;
2425

25-
public PrometheusMetricsCatalog(String cluster, String metric_prefix) {
26+
public PrometheusMetricsCatalog(String cluster, String metric_prefix)
27+
{
2628
this.cluster = cluster;
2729
this.metric_prefix = metric_prefix;
2830
metrics = new HashMap();
2931
registry = new CollectorRegistry();
3032
}
3133

32-
private String[] getExtendedLabelNames(String... label_names) {
34+
private String[] getExtendedLabelNames(String... label_names)
35+
{
3336
String[] extended = new String[label_names.length + 1];
3437
extended[0] = "cluster";
3538

@@ -38,7 +41,8 @@ private String[] getExtendedLabelNames(String... label_names) {
3841
return extended;
3942
}
4043

41-
private String[] getExtendedLabelValues(String... label_values) {
44+
private String[] getExtendedLabelValues(String... label_values)
45+
{
4246
String[] extended = new String[label_values.length + 1];
4347
extended[0] = cluster;
4448

@@ -47,7 +51,8 @@ private String[] getExtendedLabelValues(String... label_values) {
4751
return extended;
4852
}
4953

50-
public void registerGauge(String metric, String help, String... labels) {
54+
public void registerGauge(String metric, String help, String... labels)
55+
{
5156
Gauge gauge = Gauge.build().
5257
name(metric_prefix + metric).
5358
help(help).
@@ -59,12 +64,14 @@ public void registerGauge(String metric, String help, String... labels) {
5964
logger.debug(String.format("Registered new gauge %s", metric));
6065
}
6166

62-
public void setGauge(String metric, double value, String... label_values) {
67+
public void setGauge(String metric, double value, String... label_values)
68+
{
6369
Gauge gauge = (Gauge) metrics.get(metric);
6470
gauge.labels(getExtendedLabelValues(label_values)).set(value);
6571
}
6672

67-
public void registerCounter(String metric, String help, String... labels) {
73+
public void registerCounter(String metric, String help, String... labels)
74+
{
6875
Counter counter = Counter.build().
6976
name(metric_prefix + metric).
7077
help(help).
@@ -76,20 +83,25 @@ public void registerCounter(String metric, String help, String... labels) {
7683
logger.debug(String.format("Registered new counter %s", metric));
7784
}
7885

79-
public void setCounter(String metric, double value, String... label_values) {
86+
public void setCounter(String metric, double value, String... label_values)
87+
{
8088
String[] extended_label_values = getExtendedLabelValues(label_values);
8189
Counter counter = (Counter) metrics.get(metric);
8290

8391
double increment = value - counter.labels(extended_label_values).get();
8492

85-
if (increment >= 0) {
93+
if (increment >= 0)
94+
{
8695
counter.labels(extended_label_values).inc(increment);
87-
} else {
96+
}
97+
else
98+
{
8899
logger.error(String.format("Can not increment metric %s with value %f, skipping", metric, increment));
89100
}
90101
}
91102

92-
public void registerSummaryTimer(String metric, String help, String... labels) {
103+
public void registerSummaryTimer(String metric, String help, String... labels)
104+
{
93105
Summary summary = Summary.build().
94106
name(metric_prefix + metric).
95107
help(help).
@@ -101,17 +113,22 @@ public void registerSummaryTimer(String metric, String help, String... labels) {
101113
logger.debug(String.format("Registered new summary %s", metric));
102114
}
103115

104-
public Summary.Timer startSummaryTimer(String metric, String... label_values) {
116+
public Summary.Timer startSummaryTimer(String metric, String... label_values)
117+
{
105118
Summary summary = (Summary) metrics.get(metric);
106119
return summary.labels(getExtendedLabelValues(label_values)).startTimer();
107120
}
108121

109-
public String toTextFormat() throws IOException {
110-
try {
122+
public String toTextFormat() throws IOException
123+
{
124+
try
125+
{
111126
Writer writer = new StringWriter();
112127
TextFormat.write004(writer, registry.metricFamilySamples());
113128
return writer.toString();
114-
} catch (IOException e) {
129+
}
130+
catch (IOException e)
131+
{
115132
throw e;
116133
}
117134
}

0 commit comments

Comments
 (0)