[ 
https://issues.apache.org/jira/browse/KAFKA-898?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Scott Clasen updated KAFKA-898:
-------------------------------

    Status: Patch Available  (was: Open)

Subject: [PATCH] add optional librato metrics reporter

---
 config/server.properties                           |  9 ++++++++
 core/build.sbt                                     |  1 +
 .../metrics/KafkaLibratoMetricsReporter.scala      | 26 ++++++++++++++++++++++
 3 files changed, 36 insertions(+)
 create mode 100644 
core/src/main/scala/kafka/metrics/KafkaLibratoMetricsReporter.scala

diff --git a/config/server.properties b/config/server.properties
index bc6a521..a48951c 100644
--- a/config/server.properties
+++ b/config/server.properties
@@ -104,6 +104,7 @@ log.cleanup.interval.mins=1
 # root directory for all kafka znodes.
 zookeeper.connect=localhost:2181

+
 # Timeout in ms for connecting to zookeeper
 zookeeper.connection.timeout.ms=1000000

@@ -114,3 +115,11 @@ kafka.csv.metrics.dir=/tmp/kafka_metrics
 # Disable csv reporting by default.
 kafka.csv.metrics.reporter.enabled=false

+#kafka.metrics.reporters=kafka.metrics.KafkaLibratoMetricsReporter
+#kafka.librato.metrics.reporter.enabled=true
+kafka.librato.metrics.reporter.account=y...@librato.account.com
+kafka.librato.metrics.reporter.token=somelibratoapikey
+kafka.librato.metrics.reporter.prefix=testing123
+kafka.librato.metrics.reporter.source=testingsource
+kafka.librato.metrics.reporter.interval.secs=5
+
diff --git a/core/build.sbt b/core/build.sbt
index 405ea55..e12fa4b 100644
--- a/core/build.sbt
+++ b/core/build.sbt
@@ -16,6 +16,7 @@ libraryDependencies ++= Seq(
   "org.xerial.snappy"     % "snappy-java" % "1.0.4.1",
   "com.yammer.metrics"    % "metrics-core" % "2.2.0",
   "com.yammer.metrics"    % "metrics-annotation" % "2.2.0",
+  "com.librato.metrics"   % "metrics-librato"  % "2.2.0.0",
   "org.easymock"          % "easymock"    % "3.0" % "test",
   "junit"                 % "junit"       % "4.1" % "test"
 )
diff --git 
a/core/src/main/scala/kafka/metrics/KafkaLibratoMetricsReporter.scala 
b/core/src/main/scala/kafka/metrics/KafkaLibratoMetricsReporter.scala
new file mode 100644
index 0000000..5070b98
--- /dev/null
+++ b/core/src/main/scala/kafka/metrics/KafkaLibratoMetricsReporter.scala
@@ -0,0 +1,26 @@
+package kafka.metrics
+
+import kafka.utils.VerifiableProperties
+import com.librato.metrics.{APIUtil, LibratoReporter}
+import java.util.concurrent.TimeUnit
+
+
+class KafkaLibratoMetricsReporter extends KafkaMetricsReporter {
+  def init(props: VerifiableProperties) {
+    val enabled = props.getBoolean("kafka.librato.metrics.reporter.enabled", 
false)
+    if(enabled){
+      val account = props.getString("kafka.librato.metrics.reporter.account")
+      val token = props.getString("kafka.librato.metrics.reporter.token")
+      val source = props.getString("kafka.librato.metrics.reporter.source")
+      val prefix = 
Option(props.getString("kafka.librato.metrics.reporter.prefix", null))
+      val interval = 
props.getInt("kafka.librato.metrics.reporter.interval.secs",30)
+      var builder = LibratoReporter.builder(account, token, source)
+      prefix.foreach(p => builder = builder.setSanitizer(new 
PrefixingSanitizer(p)))
+      LibratoReporter.enable(builder, interval, TimeUnit.SECONDS)
+    }
+  }
+}
+
+class PrefixingSanitizer(prefix:String) extends APIUtil.Sanitizer{
+  def apply(name: String): String = prefix + "." + name
+}
--
1.8.0.1
                
> Add a KafkaMetricsReporter that wraps Librato's reporter
> --------------------------------------------------------
>
>                 Key: KAFKA-898
>                 URL: https://issues.apache.org/jira/browse/KAFKA-898
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Scott Clasen
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to