本文整理汇总了Scala中com.codahale.metrics.graphite.Graphite类的典型用法代码示例。如果您正苦于以下问题:Scala Graphite类的具体用法?Scala Graphite怎么用?Scala Graphite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Graphite类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Metrics
//设置package包名称以及导入依赖的类
package eu.inn.kafka.mimic
import java.net.{InetAddress, InetSocketAddress}
import java.util.concurrent.TimeUnit
import java.util.{Timer, TimerTask}
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import nl.grons.metrics.scala.{InstrumentedBuilder, MetricName}
object Metrics extends Logging {
val metricRegistry = new com.codahale.metrics.MetricRegistry()
def startReporter(host: String, port: Int, prefix: String, reportPeriod: Long) = {
val graphite = new Graphite(new InetSocketAddress(host, port))
val reporter = GraphiteReporter.forRegistry(metricRegistry)
.prefixedWith(prefix + "." + InetAddress.getLocalHost.getHostName.replaceAll("\\.", "-"))
.build(graphite)
new Timer("graphite-reporter-timer").schedule(
new TimerTask { def run() = reporter.report() },
reportPeriod,
reportPeriod
)
}
}
trait Metrics extends InstrumentedBuilder {
override lazy val metricBaseName = MetricName("kafka-mimic")
lazy val metricRegistry = Metrics.metricRegistry
}
trait MetricsComponent extends Metrics with Logging {
this: ConfigComponent =>
def startMetricsReporting() = {
if (config.hasPath("enabled") && config.getBoolean("enabled")) {
val host = config.getString("host")
val port = config.getInt("port")
log.info(s"Starting graphite reporter for $host:$port")
Metrics.startReporter(
host,
port,
config.getString("prefix"),
config.getDuration("report-period", TimeUnit.MILLISECONDS)
)
}
metrics.gauge("heartbeat") { 1 }
}
}
示例2: Config
//设置package包名称以及导入依赖的类
package config
import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit._
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import com.codahale.metrics.{MetricFilter, SharedMetricRegistries}
import play.api._
object Config extends GlobalSettings {
override def onStart(app: Application) {
val metricsEnabled = app.configuration.getString("metrics.enabled").getOrElse("false").toBoolean
if (metricsEnabled) {
setupGraphite(app)
}
Logger.info("Application has started")
}
private def setupGraphite(app: Application) = {
// val graphite = new PickledGraphite(new InetSocketAddress("graphite.example.com", 2004));
val metricsPrefix = app.configuration.getString("metrics.prefix").getOrElse("NO-PREFIX")
val metricsHost = app.configuration.getString("metrics.server.address").getOrElse("localhost")
val metricsPort = app.configuration.getInt("metrics.server.port").getOrElse(2003)
val graphite = new Graphite(new InetSocketAddress(metricsHost, metricsPort));
val registry = SharedMetricRegistries.getOrCreate("default")
val reporter : GraphiteReporter = GraphiteReporter.forRegistry(registry)
.prefixedWith(s"$metricsPrefix.${java.net.InetAddress.getLocalHost.getHostName}")
.convertRatesTo(SECONDS)
.convertDurationsTo(MILLISECONDS)
.filter(MetricFilter.ALL)
.build(graphite);
reporter.start(1, SECONDS);
}
}
示例3: GraphiteOptions
//设置package包名称以及导入依赖的类
package eu.inn.metrics.loaders
import java.net.InetAddress
import java.util.concurrent.TimeUnit
import com.codahale.metrics.MetricRegistry
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import com.typesafe.config.Config
import eu.inn.binders.tconfig._
import org.slf4j.LoggerFactory
import scala.concurrent.duration.Duration
import scala.util.Try
case class GraphiteOptions(enabled: Boolean,
host: String,
port: Int,
prefix: String,
hostSuffix: Option[String],
reportPeriod: Duration
)
class GraphiteReporterLoader(options: GraphiteOptions, registry: MetricRegistry) extends MetricsReporterLoader {
val log = LoggerFactory.getLogger(getClass)
def this(config: Config, registry: MetricRegistry) = this(config.getValue("graphite-reporter").read[GraphiteOptions], registry)
def run() : Unit = {
if (options.enabled) {
val prefix = Seq(options.prefix, Try {
InetAddress.getLocalHost.getHostName
} getOrElse {
"unknown-host"
}.replaceAll("\\.", "-") + options.hostSuffix.fold("")("-" + _)).filter(_.trim.nonEmpty).mkString(".")
log.info(s"Starting graphite reporter / $options")
val graphite = new Graphite(options.host, options.port)
val reporter = GraphiteReporter.forRegistry(registry).prefixedWith(prefix).build(graphite)
reporter.start(options.reportPeriod.toMillis, TimeUnit.MILLISECONDS)
} else {
log.info("Graphite reporter is disabled")
}
}
}
示例4: Graphite
//设置package包名称以及导入依赖的类
package utility.metric
import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit._
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import com.codahale.metrics.{MetricFilter, SharedMetricRegistries}
import config.AppConfig
object Graphite {
lazy val config = AppConfig
val graphite = new Graphite(new InetSocketAddress(
config.metricHost, config.metricPort))
lazy val prefix: String = config.metricPrefix
val reporter = GraphiteReporter.forRegistry(
SharedMetricRegistries.getOrCreate(prefix))
.prefixedWith(s"$prefix.${java.net.InetAddress.getLocalHost.getHostName}")
.convertRatesTo(SECONDS)
.convertDurationsTo(MILLISECONDS)
.filter(MetricFilter.ALL)
.build(graphite)
def startGraphite(): Unit = {
if (config.metricEnabled) {
reporter.start(config.metricRefreshInterval, SECONDS)
}
}
}