diff --git a/README.md b/README.md
index b818061..117525d 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ Installation
#### Download from the Maven Central (Recommended)
-[https://repo1.maven.org/maven2/net/thisptr/scriptable-jmx-exporter/0.0.6/scriptable-jmx-exporter-0.0.6.jar](https://repo1.maven.org/maven2/net/thisptr/scriptable-jmx-exporter/0.0.6/scriptable-jmx-exporter-0.0.6.jar)
+[https://repo1.maven.org/maven2/net/thisptr/scriptable-jmx-exporter/0.0.7/scriptable-jmx-exporter-0.0.7.jar](https://repo1.maven.org/maven2/net/thisptr/scriptable-jmx-exporter/0.0.7/scriptable-jmx-exporter-0.0.7.jar)
#### Building from source
@@ -393,7 +393,7 @@ Please also keep in mind that performance is highly dependent on the configurati
See [examples/benchmark-kafka](examples/benchmark-kafka) for the setup details. Here's the results:
| Exporter | # of metrics | Throughput [req/s] |
-|-|-|
+|-|-|-|
| scriptable-jmx-exporter (*1) | 5254 | 552.03 |
| jmx_exporter 0.13.0 | 3157 (*2) | 12.14 |
diff --git a/pom.xml b/pom.xml
index 706ea23..6fd7b42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,10 +7,10 @@
net.thisptr
scriptable-jmx-exporter
- Prometheus Metrics Agent
+ Scriptable JMX Exporter
jar
- 0.0.6
- Java agent for collecting and reporting metrics to Prometheus
+ 0.0.7
+ Java agent for collecting and exposing metrics to Prometheus
https://github.com/eiiches/scriptable-jmx-exporter
@@ -32,7 +32,7 @@
scm:git:git@github.com:eiiches/scriptable-jmx-exporter.git
scm:git:git@github.com:eiiches/scriptable-jmx-exporter.git
git@github.com:eiiches/scriptable-jmx-exporter.git
- v0.0.6
+ v0.0.7
diff --git a/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonOutputToMetricConverter.java b/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonOutputToMetricConverter.java
index 8624346..78f7835 100644
--- a/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonOutputToMetricConverter.java
+++ b/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonOutputToMetricConverter.java
@@ -27,7 +27,7 @@ public PrometheusMetric convert(final JsonNode tree) {
m.value = value != null ? value.asDouble() : 0L;
final JsonNode timestamp = tree.get("timestamp");
- m.timestamp = timestamp != null ? timestamp.asLong() : null;
+ m.timestamp = timestamp != null ? timestamp.asLong() : 0L;
final JsonNode labels = tree.get("labels");
if (labels != null) {
diff --git a/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngine.java b/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngine.java
index 5fc747c..ff1c345 100644
--- a/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngine.java
+++ b/src/main/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngine.java
@@ -49,11 +49,10 @@ public Script compile(final String script) throws ScriptCompileExcept
@Override
public void handle(final Sample sample, final JsonQuery script, final PrometheusMetricOutput output) {
final JsonNode mbeanAttributeNode = SampleToJsonInputConverter.getInstance().convert(sample);
- final JsonQuery transform = sample.rule != null && sample.rule.transform != null ? script : DEFAULT_TRANSFORM;
final List metricNodes = new ArrayList<>();
try {
- transform.apply(scope, mbeanAttributeNode, metricNodes::add);
+ script.apply(scope, mbeanAttributeNode, metricNodes::add);
} catch (final Throwable th) {
LOG.log(Level.INFO, "Failed to transform a MBean attribute (" + mbeanAttributeNode + ") to Prometheus metrics.", th);
return;
diff --git a/src/test/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngineTest.java b/src/test/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngineTest.java
new file mode 100644
index 0000000..3398794
--- /dev/null
+++ b/src/test/java/net/thisptr/jmx/exporter/agent/handler/jq/JsonQueryScriptEngineTest.java
@@ -0,0 +1,52 @@
+package net.thisptr.jmx.exporter.agent.handler.jq;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.junit.jupiter.api.Test;
+
+import net.thisptr.jmx.exporter.agent.PrometheusMetric;
+import net.thisptr.jmx.exporter.agent.Sample;
+import net.thisptr.jmx.exporter.agent.config.Config.PrometheusScrapeRule;
+import net.thisptr.jmx.exporter.agent.misc.FastObjectName;
+
+public class JsonQueryScriptEngineTest {
+ private final JsonQueryScriptEngine sut = new JsonQueryScriptEngine();
+
+ private static Sample sample(final ObjectName objectName, final String attributeName) throws MalformedObjectNameException, InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IntrospectionException {
+ final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ final Object value = server.getAttribute(objectName, attributeName);
+ final long timestamp = System.currentTimeMillis();
+ final MBeanInfo mbeanInfo = server.getMBeanInfo(objectName);
+ final MBeanAttributeInfo attributeInfo = Arrays.stream(mbeanInfo.getAttributes()).filter(a -> attributeName.equals(a.getName())).findFirst().get();
+ return new Sample(null, timestamp, new FastObjectName(objectName), mbeanInfo, attributeInfo, value);
+ }
+
+ @Test
+ void testSimple() throws Exception {
+ final Sample sample = sample(new ObjectName("java.lang:type=OperatingSystem"), "ProcessCpuLoad");
+
+ final List metrics = new ArrayList<>();
+ sut.compile("default_transform_v1([\"type\"]; true)").execute(sample, metrics::add);
+
+ assertThat(metrics.size()).isEqualTo(1);
+ assertThat(metrics.get(0).value).isEqualTo((Double) sample.value);
+ assertThat(metrics.get(0).name).isEqualTo("java.lang:OperatingSystem:ProcessCpuLoad");
+ assertThat(metrics.get(0).labels).isEmpty();
+ }
+}