Skip to content

Commit

Permalink
add metrics example
Browse files Browse the repository at this point in the history
  • Loading branch information
robin committed Jun 28, 2013
1 parent 3489e7d commit c4be048
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scala/distributed-computing/storm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ resolvers ++= Seq(
)

libraryDependencies ++= Seq(
"storm" % "storm" % "0.8.2" % "provided",
// "storm" % "storm" % "0.8.2" % "provided",
"com.github.velvia" % "scala-storm_2.9.1" % "0.2.2",
"org.clojure" % "clojure" % "1.4.0" % "provided",
"org.twitter4j" % "twitter4j-core" % "2.2.6-SNAPSHOT",
"org.twitter4j" % "twitter4j-stream" % "2.2.6-SNAPSHOT",
Expand Down
25 changes: 25 additions & 0 deletions scala/metrics/metrics/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%date{MM/dd HH:mm:ss} %-5level[%thread] %logger{1} - %msg%n</pattern>
</encoder>
</appender>

<!-- <appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>akka.log</file>
<append>false</append>
<encoder>
<pattern>%date{MM/dd HH:mm:ss} %-5level[%thread] %logger{1} - %msg%n</pattern>
</encoder>
</appender> -->

<logger name="akka" level="INFO" />

<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ansvia.belajar

import com.yammer.metrics.scala.Instrumented
import com.yammer.metrics.reporting.ConsoleReporter
import java.util.concurrent.TimeUnit

object Metrics extends Instrumented {

lazy val reporter = ConsoleReporter.enable(metricsRegistry, 5, TimeUnit.SECONDS)

def main(args:Array[String]){

reporter

while(true){
metrics.timer("sleeper").time {
val min = 1000
val max = 20000
val rand:Long = (min + (math.random * ((max - min) + 1)).toInt)
println("seep in %d ms...".format(rand))
Thread.sleep(rand.toLong)
println("wake up after %d ms!".format(rand))
}
}
}

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ansvia.belajar

import org.specs2.mutable._

class MetricsSpec extends Specification {

"Hello" should {
"match 5 characters" in {
"hello".length must equalTo(5)
}
}

}
32 changes: 32 additions & 0 deletions scala/metrics/project/Build.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sbt._
import Keys._

// Author: Robin

object Build extends Build {
import BuildSettings._
import Dependencies._

// root
lazy val root = Project("root", file("."))
.aggregate(examples, metrics)
.settings(basicSettings: _*)
.settings(noPublishing: _*)

// modules
lazy val examples = Project("examples", file("examples"))
.settings(moduleSettings: _*)
.settings(libraryDependencies ++=
compile(ansviaCommons) ++
test(specs2) ++
runtime(logback)
)

lazy val metrics = Project("metrics", file("metrics"))
.settings(moduleSettings: _*)
.settings(libraryDependencies ++=
compile(ansviaCommons, metricScala) ++
test(specs2) ++
runtime(logback)
)
}
70 changes: 70 additions & 0 deletions scala/metrics/project/BuildSettings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import sbt._
import Keys._
//import com.github.siasia.WebPlugin._
//import ls.Plugin._

object BuildSettings {

lazy val basicSettings = seq(
version := "0.0.1-alpha",
homepage := Some(new URL("http://ansvia.com")),
organization := "com.ansvia.belajar",
organizationHomepage := Some(new URL("http://ansvia.com")),
description := "",
startYear := Some(2012),
licenses := Seq("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt")),
scalaVersion := "2.9.1",
resolvers ++= Dependencies.resolutionRepos,
scalacOptions := Seq("-deprecation", "-encoding", "utf8")
)

lazy val moduleSettings = basicSettings ++ seq(
// scaladoc settings
(scalacOptions in doc) <++= (name, version).map { (n, v) => Seq("-doc-title", n, "-doc-version", v) },

// publishing
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
crossPaths := false,
publishMavenStyle := true

// LS
// (LsKeys.tags in LsKeys.lsync) := Seq("http", "server", "client", "async"),
// (LsKeys.docsUrl in LsKeys.lsync) := Some(new URL("http://spray.github.com/spray/api/spray-can/")),
// (externalResolvers in LsKeys.lsync) := Seq("spray repo" at "http://repo.spray.cc")
)

lazy val noPublishing = seq(
publish := (),
publishLocal := ()
)

lazy val withPublishing = seq(
publishTo <<= version { (v:String) =>
val ansviaRepo = "http://scala.repo.ansvia.com/nexus"
if(v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at ansviaRepo + "/content/repositories/snapshots")
else
Some("releases" at ansviaRepo + "/content/repositories/releases")
},

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),

publishArtifact in Test := false,

pomIncludeRepository := { _ => false },

crossPaths := false,

pomExtra := (
<url>http://your.info.url.here</url>
<developers>
<developer>
<id>your id here</id>
<name>Your name here</name>
<url>http://your.site.here.com</url>
</developer>
</developers>)
)

}

21 changes: 21 additions & 0 deletions scala/metrics/project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sbt._

object Dependencies {
val resolutionRepos = Seq(
"typesafe repo" at "http://repo.typesafe.com/typesafe/releases/",
"glassfish repo" at "http://download.java.net/maven/glassfish/",
"spray repo" at "http://repo.spray.cc/",
"Ansvia repo" at "http://scala.repo.ansvia.com/releases/"
)

def compile (deps: ModuleID*): Seq[ModuleID] = deps map (_ % "compile")
def provided (deps: ModuleID*): Seq[ModuleID] = deps map (_ % "provided")
def test (deps: ModuleID*): Seq[ModuleID] = deps map (_ % "test")
def runtime (deps: ModuleID*): Seq[ModuleID] = deps map (_ % "runtime")
def container (deps: ModuleID*): Seq[ModuleID] = deps map (_ % "container")

val ansviaCommons = "com.ansvia" % "ansvia-commons" % "0.0.6"
val specs2 = "org.specs2" %% "specs2" % "1.12.4"
val logback = "ch.qos.logback" % "logback-classic" % "1.0.9"
val metricScala = "nl.grons" %% "metrics-scala" % "2.2.0"
}
1 change: 1 addition & 0 deletions scala/metrics/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.12.2
17 changes: 17 additions & 0 deletions scala/metrics/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v + "-0.2.11"))

//addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.1")

resolvers ++= Seq(
"Ansvia repo" at "http://scala.repo.ansvia.com/releases"
// "less is" at "http://repo.lessis.me",
// "coda" at "http://repo.codahale.com"
)

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.0")

//addSbtPlugin("com.ansvia" % "onedir" % "0.4")

//addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3")

0 comments on commit c4be048

Please sign in to comment.