Repository: cassandra Updated Branches: refs/heads/trunk 578c85dc7 -> 33f2f844b
Allow metrics export for prometheus in its native format patch by Robert Stupp; reviewed by Sam Tunnicliffe for CASSANDRA-11967 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/33f2f844 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/33f2f844 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/33f2f844 Branch: refs/heads/trunk Commit: 33f2f844b6bef7b3e5977f649bb2bfaf2e4db904 Parents: 578c85d Author: Robert Stupp <[email protected]> Authored: Fri Jun 24 18:28:32 2016 +0200 Committer: Robert Stupp <[email protected]> Committed: Fri Jun 24 18:28:32 2016 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + NEWS.txt | 5 +++ .../cassandra/service/CassandraDaemon.java | 35 ++++++++++++++++++++ 3 files changed, 41 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f2f844/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index d40cab4..9495c96 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.8 + * Allow metrics export for prometheus in its native format (CASSANDRA-11967) * Move skip_stop_words filter before stemming (CASSANDRA-12078) * Support seek() in EncryptedFileSegmentInputStream (CASSANDRA-11957) * SSTable tools mishandling LocalPartitioner (CASSANDRA-12002) http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f2f844/NEWS.txt ---------------------------------------------------------------------- diff --git a/NEWS.txt b/NEWS.txt index 7418f3a..11e3b37 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -19,6 +19,11 @@ using the provided 'sstableupgrade' tool. New features ------------ + - Support for alternative metrics exporters has been added. To use them, the appropiate + libraries need to be placed in the lib directory. Cassandra will load the class given in + the system property cassandra.metricsExporter and instantiate it by calling the constructor + taking an instance of com.codahale.metrics.MetricRegistry. If the provided class implements + java.io.Closeable, its close() method will be called on shutdown. - Shared pool threads are now named according to the stage they are executing tasks for. Thread names mentioned in traced queries change accordingly. - A new option has been added to cassandra-stress "-rate fixed={number}/s" http://git-wip-us.apache.org/repos/asf/cassandra/blob/33f2f844/src/java/org/apache/cassandra/service/CassandraDaemon.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java index 2d21bff..b1c44be 100644 --- a/src/java/org/apache/cassandra/service/CassandraDaemon.java +++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java @@ -17,10 +17,12 @@ */ package org.apache.cassandra.service; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; +import java.lang.reflect.Constructor; import java.net.InetAddress; import java.net.URL; import java.net.UnknownHostException; @@ -40,6 +42,7 @@ import org.slf4j.LoggerFactory; import com.addthis.metrics3.reporter.config.ReporterConfig; import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistryListener; import com.codahale.metrics.SharedMetricRegistries; import org.apache.cassandra.batchlog.LegacyBatchlogMigrator; @@ -365,6 +368,38 @@ public class CassandraDaemon } } + // Alternative metrics + String metricsExporterClass = System.getProperty("cassandra.metricsExporter"); + if (metricsExporterClass != null) + { + logger.info("Trying to initialize metrics-exporter {}", metricsExporterClass); + try + { + Constructor<?> ctor = Class.forName(metricsExporterClass).getConstructor(MetricRegistry.class); + Object metricsExporter = ctor.newInstance(CassandraMetricsRegistry.Metrics); + if (metricsExporter.getClass().isAssignableFrom(Closeable.class)) + { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() + { + try + { + ((Closeable)metricsExporter).close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + }); + } + } + catch (Exception e) + { + logger.warn("Failed to initialize metrics-exporter", e); + } + } + // start server internals StorageService.instance.registerDaemon(this); try
