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

Scala Gauge类代码示例

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

本文整理汇总了Scala中com.codahale.metrics.Gauge的典型用法代码示例。如果您正苦于以下问题:Scala Gauge类的具体用法?Scala Gauge怎么用?Scala Gauge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Gauge类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: CHMetricsStatsReceiver

//设置package包名称以及导入依赖的类
package org.http4s.finagle

import com.codahale.metrics.{ Gauge, MetricRegistry }
import com.twitter.finagle.stats.{ Counter, Stat, StatsReceiver, Gauge => FGauge }

import scalaz.syntax.id._

class CHMetricsStatsReceiver(registry: MetricRegistry, prefix: String) extends StatsReceiver {
  override val repr: AnyRef = this

  override def counter(names: String*): Counter =
    registry.counter(format(names)) |> { c =>
      new Counter {
        override def incr(delta: Int): Unit = c.inc(delta.toLong)
      }
    }

  override def addGauge(names: String*)(f: => Float): FGauge =
    format(names) |> { name =>
      registry.register(format(names), new Gauge[Float] {
        override def getValue: Float = f
      }) |> { g =>
        new FGauge {
          override def remove(): Unit = { registry.remove(name); () }
        }
      }
    }

  override def stat(names: String*): Stat =
    registry.histogram(format(names)) |> { h =>
      new Stat {
        override def add(value: Float): Unit = h.update(value.toLong)
      }
    }

  private def format(names: Seq[String]): String =
    (prefix +: names).mkString(".")
} 
开发者ID:lukiano,项目名称:finagle-http4s,代码行数:39,代码来源:CHMetricsStatsReceiver.scala


示例2: GaugeInjectionListener

//设置package包名称以及导入依赖的类
package de.khamrakulov.play.metrics.annotation.guice.listener

import java.lang.reflect.Method

import com.codahale.metrics.{Gauge, MetricRegistry}
import com.google.inject.spi.InjectionListener


private[annotation] object GaugeInjectionListener {
  def apply(metricRegistry: MetricRegistry, metricName: String, method: Method) =
    new GaugeInjectionListener(metricRegistry, metricName, method)
}

private[annotation] class GaugeInjectionListener[I](metricRegistry: MetricRegistry, metricName: String, method: Method) extends InjectionListener[I] {
  def afterInjection(i: I) = if (metricRegistry.getGauges.get(metricName) == null) {
    metricRegistry.register(metricName, new Gauge[AnyRef]() {
      def getValue = try method.invoke(i) catch {
        case e: Exception => new RuntimeException(e)
      }
    })
  }
} 
开发者ID:htimur,项目名称:metrics-annotation-play,代码行数:23,代码来源:GaugeInjectionListener.scala


示例3: TestMetricsReporter

//设置package包名称以及导入依赖的类
import java.util.concurrent.TimeUnit

import com.codahale.metrics.{Gauge, ScheduledReporter}
import eu.inn.metrics.MetricsTracker
import eu.inn.metrics.modules.ConsoleReporterModule
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{FreeSpec, Matchers}
import scaldi.Injectable

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration.Duration

class TestMetricsReporter extends FreeSpec with Matchers with Injectable with ScalaFutures {
  implicit val injector = new ConsoleReporterModule(Duration.Undefined)

  "MetricsReporter should instantiate" - {
    val metrics = inject[MetricsTracker]

    metrics.counter("counter").inc(100500)
    metrics.meter("meter").mark(15)
    metrics.histogram("histogram").update(13)
    metrics.histogram("histogram").update(12)
    metrics.histogram("histogram").update(13)
    metrics.histogram("histogram").update(15)

    metrics.timer("timer1").update(10, TimeUnit.SECONDS)

    metrics.timeOf("measure-sync") {
      Thread.sleep(10)
    }

    metrics.timeOfFuture("measure-async") {
      Future {
        Thread.sleep(10)
      }
    }.futureValue

    metrics.gauge("gauge1") {
      100500
    }

    metrics.gauge("gauge1") {
      100501
    }

    metrics.gauge("gauge2", new Gauge[Int] {
      override def getValue = 3
    })

    val reporter = inject[ScheduledReporter]
    reporter shouldNot equal (null)
    reporter.report()
  }
} 
开发者ID:InnovaCo,项目名称:service-metrics,代码行数:56,代码来源:TestMetricsReporter.scala


示例4: MetricRegistries

//设置package包名称以及导入依赖的类
package com.rbmhtechnology.eventuate.tools.metrics.dropwizard

import com.codahale.metrics.Gauge
import com.codahale.metrics.MetricRegistry

object MetricRegistries {

  implicit class RichMetricRegistry(metricRegistry: MetricRegistry) {
    def setGaugeValue[A](name: String, value: A): Unit = {
      val oldEntry = Option(metricRegistry.getGauges().get(name))
      if (oldEntry.forall(_.getValue != value)) {
        metricRegistry.remove(name)
        metricRegistry.register(name, fixValueGauge(value))
      }
    }

    private def fixValueGauge[A](value: A): Gauge[A] = new Gauge[A] {
      override def getValue: A = value
    }
  }
} 
开发者ID:RBMHTechnology,项目名称:eventuate-tools,代码行数:22,代码来源:MetricRegistries.scala


示例5: MetricHelper

//设置package包名称以及导入依赖的类
package com.evolutiongaming.util

import com.codahale.metrics.{Gauge, Histogram, MetricRegistry, Timer}

import scala.compat.Platform
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

object MetricHelper {

  object GaugeF {
    def apply[T](f: => T): Gauge[T] = new Gauge[T] { def getValue: T = f }
  }

  implicit class RichTimer(val timer: Timer) extends AnyVal {
    def timeExceed[T](limit: FiniteDuration)(f: => T): T = {
      val start = Platform.currentTime
      try f finally {
        val stop = Platform.currentTime
        val duration = stop - start
        if (duration >= limit.toMillis) timer.update(duration, MILLISECONDS)
      }
    }

    def timeFuture[T](f: => Future[T])(implicit ec: ExecutionContext): Future[T] = {
      val time = timer.time()
      try f andThen { case _ => time.stop() } catch {
        case NonFatal(e) => time.stop(); throw e
      }
    }

    def timeFunc[T](f: => T): T = {
      val time = timer.time()
      try f finally time.stop()
    }
  }

  implicit class HistogramOps(val histogram: Histogram) extends AnyVal {
    def timeFunc[T](f: => T): T = {
      val start = Platform.currentTime
      try f finally histogram.update(Platform.currentTime - start)
    }

    def timeFuture[T](f: => Future[T])(implicit ec: ExecutionContext): Future[T] = {
      val start = Platform.currentTime
      f andThen { case _ => histogram.update(Platform.currentTime - start) }
    }
  }

  implicit class MetricRegistryOps(val self: MetricRegistry) extends AnyVal {
    def gauge[T](name: String, f: => T): Gauge[T] = {
      self remove name
      self.register(name, GaugeF(f))
    }
  }
} 
开发者ID:evolution-gaming,项目名称:metric-tools,代码行数:58,代码来源:MetricHelper.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala DefaultHttpFilters类代码示例发布时间:2022-05-23
下一篇:
Scala CopyOnWriteArrayList类代码示例发布时间: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