• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Graphite类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 }
  }
} 
开发者ID:InnovaCo,项目名称:kafka-mimic,代码行数:55,代码来源:Metrics.scala


示例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);

 }
} 
开发者ID:RobTaylor76,项目名称:play-scala-metrics,代码行数:43,代码来源:config.scala


示例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")
    }
  }
} 
开发者ID:InnovaCo,项目名称:service-metrics-graphite,代码行数:45,代码来源:GraphiteReporterLoader.scala


示例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)
    }
  }
} 
开发者ID:Harl0,项目名称:play-scala-forms-2.6,代码行数:34,代码来源:Graphite.scala



注:本文中的com.codahale.metrics.graphite.Graphite类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Mockito类代码示例发布时间:2022-05-23
下一篇:
Scala Breaks类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap