aboutsummaryrefslogtreecommitdiff
path: root/kamon-statsd
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-03-31 23:34:22 -0300
committerDiego <diegolparra@gmail.com>2014-03-31 23:34:22 -0300
commit32ba2d5253994e898b9f611870b401aafe4779bb (patch)
tree749e76e7eeb6355f96c591cd016d4540b4e0499e /kamon-statsd
parent503752564267d784b15d3b0d12e45a3c190fdd54 (diff)
downloadKamon-32ba2d5253994e898b9f611870b401aafe4779bb.tar.gz
Kamon-32ba2d5253994e898b9f611870b401aafe4779bb.tar.bz2
Kamon-32ba2d5253994e898b9f611870b401aafe4779bb.zip
first implementation statsd client
Diffstat (limited to 'kamon-statsd')
-rw-r--r--kamon-statsd/src/main/resources/reference.conf12
-rw-r--r--kamon-statsd/src/main/scala/kamon/statsd/Statsd.scala36
-rw-r--r--kamon-statsd/src/main/scala/kamon/statsd/client/StatsdClient.scala22
3 files changed, 70 insertions, 0 deletions
diff --git a/kamon-statsd/src/main/resources/reference.conf b/kamon-statsd/src/main/resources/reference.conf
new file mode 100644
index 00000000..9d09a709
--- /dev/null
+++ b/kamon-statsd/src/main/resources/reference.conf
@@ -0,0 +1,12 @@
+# ==================================== #
+# Kamon-Statsd Reference Configuration #
+# ==================================== #
+
+kamon {
+ statsd {
+ prefix = kamon-app
+ hostname = statsd.example.com
+ port = 8125
+ }
+ }
+} \ No newline at end of file
diff --git a/kamon-statsd/src/main/scala/kamon/statsd/Statsd.scala b/kamon-statsd/src/main/scala/kamon/statsd/Statsd.scala
new file mode 100644
index 00000000..d4198c7f
--- /dev/null
+++ b/kamon-statsd/src/main/scala/kamon/statsd/Statsd.scala
@@ -0,0 +1,36 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+
+package kamon.statsd
+
+import akka.actor.{ ExtendedActorSystem, Extension, ExtensionIdProvider, ExtensionId }
+import kamon.Kamon
+
+object Statsd extends ExtensionId[StatsdExtension] with ExtensionIdProvider {
+ override def lookup(): ExtensionId[_ <: Extension] = Statsd
+ override def createExtension(system: ExtendedActorSystem): StatsdExtension = new StatsdExtension(system)
+}
+
+class StatsdExtension(private val system: ExtendedActorSystem) extends Kamon.Extension {
+ publishInfoMessage(system, "Statsd Extension Loaded!!")
+
+ private val config = system.settings.config.getConfig("kamon.statsd")
+
+ val prefix = config.getString("prefix")
+ val hostname = config.getString("hostname")
+ val port = config.getInt("port")
+}
+
diff --git a/kamon-statsd/src/main/scala/kamon/statsd/client/StatsdClient.scala b/kamon-statsd/src/main/scala/kamon/statsd/client/StatsdClient.scala
new file mode 100644
index 00000000..23376558
--- /dev/null
+++ b/kamon-statsd/src/main/scala/kamon/statsd/client/StatsdClient.scala
@@ -0,0 +1,22 @@
+package kamon.statsd.client
+
+import akka.actor.{ActorRef, Actor}
+import akka.io.{Udp, IO}
+import java.net.InetSocketAddress
+import akka.util.ByteString
+
+class StatsdClient(remote: InetSocketAddress) extends Actor {
+ import context.system
+
+ IO(Udp) ! Udp.SimpleSender
+
+ def receive = {
+ case Udp.SimpleSenderReady =>
+ context.become(ready(sender()))
+ }
+
+ def ready(send: ActorRef): Receive = {
+ case msg: String =>
+ send ! Udp.Send(ByteString(msg), remote)
+ }
+} \ No newline at end of file