From 0fa983d0e84c7458e7374d921bb33225e2c9b38b Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Fri, 30 Jan 2015 02:05:24 -0800 Subject: [PATCH] Add support for prefixing the metrics with a CLI supplied option Fixes #15 --- build.gradle | 2 +- .../com/github/lookout/verspaetung/Main.groovy | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1e43ca4..bda8333 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'application' group = "com.github.lookout" description = "A utility for monitoring the delay of Kafka consumers" -version = '0.1.4' +version = '0.1.5' mainClassName = 'com.github.lookout.verspaetung.Main' defaultTasks 'clean', 'check' sourceCompatibility = '1.7' diff --git a/src/main/groovy/com/github/lookout/verspaetung/Main.groovy b/src/main/groovy/com/github/lookout/verspaetung/Main.groovy index 0771987..e3a7c20 100644 --- a/src/main/groovy/com/github/lookout/verspaetung/Main.groovy +++ b/src/main/groovy/com/github/lookout/verspaetung/Main.groovy @@ -26,6 +26,7 @@ class Main { private static Logger logger static void main(String[] args) { + String statsdPrefix = METRICS_PREFIX String zookeeperHosts = 'localhost:2181' String statsdHost = 'localhost' Integer statsdPort = 8125 @@ -48,11 +49,15 @@ class Main { logger.info("Running with: ${args}") logger.warn("Using: zookeepers=${zookeeperHosts} statsd=${statsdHost}:${statsdPort}") + if (cli.hasOption('prefix')) { + statsdPrefix = "${cli.getOptionValue('prefix')}.${METRICS_PREFIX}" + } + ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1000, 3) CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperHosts, retry) ConcurrentHashMap> consumers = new ConcurrentHashMap() - statsd = new NonBlockingDogStatsDClient(METRICS_PREFIX, statsdHost, statsdPort) + statsd = new NonBlockingDogStatsDClient(statsdPrefix, statsdHost, statsdPort) client.start() @@ -148,9 +153,17 @@ class Main { .withLongOpt('storm') .create('s') + Option statsdPrefix = OptionBuilder.withArgName('PREFIX') + .hasArg() + .withType(String) + .withDescription("Prefix all metrics with PREFIX before they're reported (e.g. PREFIX.verspaetung.mytopic)") + .withLongOpt('prefix') + .create() + options.addOption(zookeeper) options.addOption(statsdHost) options.addOption(statsdPort) + options.addOption(statsdPrefix) options.addOption(dryRun) options.addOption(stormSpouts)