diff options
Diffstat (limited to 'kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala')
-rw-r--r-- | kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala | 75 |
1 files changed, 12 insertions, 63 deletions
diff --git a/kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala b/kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala index 7ba8b105..e1d6689c 100644 --- a/kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala +++ b/kamon-jdbc/src/main/scala/kamon/jdbc/metric/StatementsMetrics.scala @@ -16,68 +16,17 @@ package kamon.jdbc.metric -import akka.actor.ActorSystem -import com.typesafe.config.Config -import kamon.metric.{ CollectionContext, MetricGroupCategory, MetricGroupFactory, MetricGroupIdentity, MetricGroupRecorder, MetricGroupSnapshot, MetricIdentity, MetricSnapshot } -import kamon.metric.instrument.{ Counter, Histogram } - -case class StatementsMetrics(name: String) extends MetricGroupIdentity { - val category = StatementsMetrics -} - -object StatementsMetrics extends MetricGroupCategory { - val name = "jdbc-statements" - - case object Writes extends MetricIdentity { val name = "writes" } - case object Reads extends MetricIdentity { val name = "reads" } - case object Slows extends MetricIdentity { val name = "slow-queries" } - case object Errors extends MetricIdentity { val name = "errors" } - - case class StatementsMetricsRecorder(writes: Histogram, reads: Histogram, slow: Counter, errors: Counter) - extends MetricGroupRecorder { - - def collect(context: CollectionContext): MetricGroupSnapshot = { - StatementsMetricsSnapshot(writes.collect(context), reads.collect(context), slow.collect(context), errors.collect(context)) - } - - def cleanup: Unit = {} - } - - case class StatementsMetricsSnapshot(writes: Histogram.Snapshot, reads: Histogram.Snapshot, slows: Counter.Snapshot, errors: Counter.Snapshot) - extends MetricGroupSnapshot { - - type GroupSnapshotType = StatementsMetricsSnapshot - - def merge(that: StatementsMetricsSnapshot, context: CollectionContext): GroupSnapshotType = { - StatementsMetricsSnapshot(writes.merge(that.writes, context), reads.merge(that.reads, context), slows.merge(that.slows, context), errors.merge(that.errors, context)) - } - - lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map( - Writes -> writes, - Reads -> reads, - Slows -> slows, - Reads -> errors) - } - - val Factory = StatementsMetricsGroupFactory -} - -case object StatementsMetricsGroupFactory extends MetricGroupFactory { - import kamon.jdbc.metric.StatementsMetrics._ - - type GroupRecorder = StatementsMetricsRecorder - - def create(config: Config, system: ActorSystem): GroupRecorder = { - val settings = config.getConfig("precision.jdbc.statements") - - val writesConfig = settings.getConfig("writes") - val readsConfig = settings.getConfig("reads") - - new StatementsMetricsRecorder( - Histogram.fromConfig(writesConfig), - Histogram.fromConfig(readsConfig), - Counter(), - Counter()) - } +import kamon.metric._ +import kamon.metric.instrument.{ Time, InstrumentFactory } + +class StatementsMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) { + val reads = histogram("reads", Time.Nanoseconds) + val writes = histogram("writes", Time.Nanoseconds) + val slows = counter("slows") + val errors = counter("errors") } +object StatementsMetrics extends EntityRecorderFactory[StatementsMetrics] { + def category: String = "jdbc-statements" + def createRecorder(instrumentFactory: InstrumentFactory): StatementsMetrics = new StatementsMetrics(instrumentFactory) +}
\ No newline at end of file |