2015-01-09 23:55:35 +00:00
|
|
|
package com.github.lookout.verspaetung
|
|
|
|
|
2015-01-19 19:45:22 +00:00
|
|
|
import com.github.lookout.verspaetung.zk.BrokerTreeWatcher
|
2015-01-19 21:08:01 +00:00
|
|
|
import com.github.lookout.verspaetung.zk.StandardTreeWatcher
|
2015-01-19 19:45:22 +00:00
|
|
|
|
2015-01-18 18:25:04 +00:00
|
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
|
|
import groovy.transform.TypeChecked
|
|
|
|
|
2015-01-20 21:23:01 +00:00
|
|
|
import com.timgroup.statsd.StatsDClient
|
2015-01-26 12:09:47 +00:00
|
|
|
import com.timgroup.statsd.NonBlockingDogStatsDClient
|
2015-01-20 21:23:01 +00:00
|
|
|
|
2015-01-10 02:17:45 +00:00
|
|
|
import org.apache.curator.retry.ExponentialBackoffRetry
|
|
|
|
import org.apache.curator.framework.CuratorFrameworkFactory
|
2015-01-17 22:42:24 +00:00
|
|
|
import org.apache.curator.framework.CuratorFramework
|
|
|
|
import org.apache.curator.framework.recipes.cache.TreeCache
|
2015-01-26 12:09:47 +00:00
|
|
|
import org.slf4j.Logger
|
|
|
|
import org.slf4j.LoggerFactory
|
2015-01-19 19:45:22 +00:00
|
|
|
|
|
|
|
//@TypeChecked
|
2015-01-10 02:17:45 +00:00
|
|
|
class Main {
|
2015-01-26 12:09:47 +00:00
|
|
|
private static final StatsDClient statsd = new NonBlockingDogStatsDClient('verspaetung', '10.32.2.211', 8125)
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Main.class)
|
2015-01-20 21:23:01 +00:00
|
|
|
|
2015-01-10 02:17:45 +00:00
|
|
|
static void main(String[] args) {
|
2015-01-26 12:09:47 +00:00
|
|
|
logger.info("Running with: ${args}")
|
2015-01-10 02:17:45 +00:00
|
|
|
|
|
|
|
ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1000, 3)
|
2015-01-17 22:42:24 +00:00
|
|
|
CuratorFramework client = CuratorFrameworkFactory.newClient(args[0], retry)
|
2015-01-19 18:10:28 +00:00
|
|
|
ConcurrentHashMap<TopicPartition, List<zk.ConsumerOffset>> consumers = new ConcurrentHashMap()
|
2015-01-19 19:45:22 +00:00
|
|
|
|
2015-01-10 02:17:45 +00:00
|
|
|
client.start()
|
2015-01-17 22:42:24 +00:00
|
|
|
|
2015-01-19 19:45:22 +00:00
|
|
|
TreeCache cache = new TreeCache(client, '/consumers')
|
2015-01-17 22:42:24 +00:00
|
|
|
|
2015-01-19 23:55:47 +00:00
|
|
|
KafkaPoller poller = new KafkaPoller(consumers)
|
2015-01-19 21:08:01 +00:00
|
|
|
StandardTreeWatcher consumerWatcher = new StandardTreeWatcher(consumers)
|
2015-01-19 21:15:00 +00:00
|
|
|
consumerWatcher.onInitComplete << {
|
2015-01-26 12:09:47 +00:00
|
|
|
logger.info("standard consumers initialized to ${consumers.size()} (topic, partition) tuples")
|
2015-01-19 21:08:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 19:45:22 +00:00
|
|
|
BrokerTreeWatcher brokerWatcher = new BrokerTreeWatcher(client)
|
2015-01-19 21:15:00 +00:00
|
|
|
brokerWatcher.onBrokerUpdates << { brokers ->
|
2015-01-19 19:45:22 +00:00
|
|
|
poller.refresh(brokers)
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:01 +00:00
|
|
|
cache.listenable.addListener(consumerWatcher)
|
2015-01-19 19:45:22 +00:00
|
|
|
|
2015-01-20 00:22:22 +00:00
|
|
|
poller.onDelta << { String groupName, TopicPartition tp, Long delta ->
|
2015-01-26 12:09:47 +00:00
|
|
|
statsd.recordGaugeValue(tp.topic, delta, [
|
|
|
|
'topic' : tp.topic,
|
|
|
|
'partition' : tp.partition,
|
|
|
|
'consumer-group' : groupName
|
|
|
|
])
|
2015-01-20 00:22:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:01 +00:00
|
|
|
poller.start()
|
2015-01-19 19:45:22 +00:00
|
|
|
brokerWatcher.start()
|
2015-01-17 22:42:24 +00:00
|
|
|
cache.start()
|
2015-01-26 12:09:47 +00:00
|
|
|
|
|
|
|
logger.info("Started wait loop...")
|
2015-01-17 22:42:24 +00:00
|
|
|
|
2015-01-20 21:23:01 +00:00
|
|
|
while (true) { Thread.sleep(1000) }
|
2015-01-17 22:42:24 +00:00
|
|
|
|
2015-01-26 12:09:47 +00:00
|
|
|
logger.info("exiting..")
|
2015-01-19 19:45:22 +00:00
|
|
|
poller.die()
|
2015-01-20 00:22:22 +00:00
|
|
|
poller.join()
|
2015-01-17 22:42:24 +00:00
|
|
|
return
|
2015-01-10 02:17:45 +00:00
|
|
|
}
|
|
|
|
}
|