Skip to content

Commit 4e6d04a

Browse files
committed
default port and host for reporters
1 parent b7af31d commit 4e6d04a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

app/com/github/sdb/play2/metrics/Reporter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private object Reporter extends ReporterConfigurationSupport {
5353
}
5454

5555
lazy val graphite: (String, Configuration) => Reporter = (name, config) =>
56-
Graphite(name, config, config.period, config.unit, config.host, config.port, config.getString("prefix"))
56+
Graphite(name, config, config.period, config.unit, config.host("localhost"), config.port(2003), config.getString("prefix"))
5757

5858

5959
case class Ganglia(name: String, configuration: Configuration, period: Long, unit: TimeUnit, host: String, port: Int) extends DynamicReporter {
@@ -66,5 +66,5 @@ private object Reporter extends ReporterConfigurationSupport {
6666
}
6767

6868
lazy val ganglia: (String, Configuration) => Reporter = (name, config) =>
69-
Ganglia(name, config, config.period, config.unit, config.host, config.port)
69+
Ganglia(name, config, config.period, config.unit, config.host("localhost"), config.port(8649))
7070
}

app/com/github/sdb/play2/metrics/ReporterConfigurationSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ private trait ReporterConfigurationSupport {
1010
def period = conf.getInt("period") getOrElse 1
1111
def enabled = conf.getBoolean("enabled") getOrElse false
1212
def unit = conf.getString("unit", Some(Set((TimeUnit.values.toSeq map(_.toString)):_*))) map(TimeUnit.valueOf(_)) getOrElse TimeUnit.MINUTES
13-
def host = conf.getString("host") getOrElse "localhost"
14-
def port = conf.getInt("port") getOrElse 2003
13+
def host(default: => String) = conf.getString("host") getOrElse default
14+
def port(default: => Int) = conf.getInt("port") getOrElse default
1515
def path(name: String) = new File(conf.getString(name) getOrElse ".")
1616
}
1717

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/release
88

99
libraryDependencies ++= Seq(
1010
"play" %% "play" % "2.1.0" % "provided",
11-
"com.yammer.metrics" % "metrics-core" % "2.2.0" % "provided"
11+
"com.yammer.metrics" % "metrics-core" % "2.2.0" % "provided",
12+
"org.specs2" %% "specs2" % "1.14" % "test"
1213
)
1314

1415
scalaSource in Compile <<= baseDirectory { (base) => base / "app" }
@@ -17,6 +18,8 @@ resourceDirectory in Compile <<= baseDirectory { (base) => base / "conf" }
1718

1819
scalaSource in Test <<= baseDirectory { (base) => base / "test" }
1920

21+
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
22+
2023
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"))
2124

2225
homepage := Some(url("http://sdb.github.com/play2-metrics/"))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.sdb.play2
2+
package metrics
3+
4+
import org.specs2.Specification
5+
import org.specs2.matcher.DataTables
6+
import play.api.Configuration
7+
8+
object ReporterConfigurationSpec extends Specification with DataTables { def is =
9+
"read period from config" ! pending^
10+
"read enabled from config" ! pending^
11+
"read unit from config" ! pending^
12+
"read host from config" ! pending^
13+
"read port from config" ! pending^
14+
"read file path from config" ! pending
15+
16+
17+
// val data = a.map(a => Map("period" -> a)) getOrElse Map.empty
18+
// val conf = Configuration.from(data)
19+
// val reporterConfig = new ReporterConfigurationSupport.ReporterConfiguration(conf)
20+
// reporterConfig.period must_== b
21+
}

0 commit comments

Comments
 (0)