layout: home


epimetheus - An Afterthought of Prometheus Build Status Maven Central

Quick Start

To use epimetheus in an existing SBT project with Scala 2.11 or a later version, add the following dependencies to your build.sbt depending on your needs:

libraryDependencies ++= Seq(
  "io.chrisdavenport" %% "epimetheus" % "<version>"
)

Quick Examples

First Imports.

import io.chrisdavenport.epimetheus._
import io.chrisdavenport.epimetheus.implicits._
import cats.effect._

import scala.concurrent.duration._

import cats.effect.unsafe.implicits.global

Counter Example

val noLabelsCounterExample = {
  for {
    cr <- CollectorRegistry.build[IO]
    counter <- Counter.noLabels(cr, Name("counter_total"), "Example Counter")
    _ <- counter.inc
    currentMetrics <- cr.write004
  } yield currentMetrics
}
// noLabelsCounterExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.CollectorRegistry$$$Lambda$10220/0x000000080297b0f8@2d82bd4f,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = <function1>,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

noLabelsCounterExample.unsafeRunSync()
// res0: String = """# HELP counter_total Example Counter
// # TYPE counter_total counter
// counter_total 1.0
// # HELP counter_created Example Counter
// # TYPE counter_created gauge
// counter_created 1.658547345237E9
// """

Gauge Example

val noLabelsGaugeExample = {
  for {
    cr <- CollectorRegistry.build[IO]
    gauge <- Gauge.noLabels(cr, Name("gauge_total"), "Example Gauge")
    _ <- gauge.inc
    _ <- gauge.inc
    _ <- gauge.dec
    currentMetrics <- cr.write004
  } yield currentMetrics
}
// noLabelsGaugeExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.CollectorRegistry$$$Lambda$10220/0x000000080297b0f8@32df6794,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = <function1>,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

noLabelsGaugeExample.unsafeRunSync()
// res1: String = """# HELP gauge_total Example Gauge
// # TYPE gauge_total gauge
// gauge_total 1.0
// """

Histogram Example

val noLabelsHistogramExample = {
  for {
    cr <- CollectorRegistry.build[IO]
    h <- Histogram.noLabels(cr, Name("example_histogram"), "Example Histogram")
    _ <- h.observe(0.2)
    _ <- h.timed(Temporal[IO].sleep(1.second), SECONDS)
    currentMetrics <- cr.write004
  } yield currentMetrics
}
// noLabelsHistogramExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.CollectorRegistry$$$Lambda$10220/0x000000080297b0f8@4d2e60cf,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = <function1>,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

noLabelsHistogramExample.unsafeRunSync()
// res2: String = """# HELP example_histogram Example Histogram
// # TYPE example_histogram histogram
// example_histogram_bucket{le="0.005",} 0.0
// example_histogram_bucket{le="0.01",} 0.0
// example_histogram_bucket{le="0.025",} 0.0
// example_histogram_bucket{le="0.05",} 0.0
// example_histogram_bucket{le="0.075",} 0.0
// example_histogram_bucket{le="0.1",} 0.0
// example_histogram_bucket{le="0.25",} 1.0
// example_histogram_bucket{le="0.5",} 1.0
// example_histogram_bucket{le="0.75",} 1.0
// example_histogram_bucket{le="1.0",} 1.0
// example_histogram_bucket{le="2.5",} 2.0
// example_histogram_bucket{le="5.0",} 2.0
// example_histogram_bucket{le="7.5",} 2.0
// example_histogram_bucket{le="10.0",} 2.0
// example_histogram_bucket{le="+Inf",} 2.0
// example_histogram_count 2.0
// example_histogram_sum 1.200462849
// # HELP example_histogram_created Example Histogram
// # TYPE example_histogram_created gauge
// example_histogram_created 1.658547345252E9
// """

Summary Example

val noLabelsSummaryExample = {
  for {
    cr <- CollectorRegistry.build[IO]
    s <- Summary.noLabels(cr, Name("example_summary"), "Example Summary", Summary.quantile(0.5,0.05))
    _ <- s.observe(0.1)
    _ <- s.observe(0.2)
    _ <- s.observe(1.0)
    currentMetrics <- cr.write004
  } yield currentMetrics
}
// noLabelsSummaryExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.CollectorRegistry$$$Lambda$10220/0x000000080297b0f8@472d32bf,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = <function1>,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

noLabelsSummaryExample.unsafeRunSync()
// res3: String = """# HELP example_summary Example Summary
// # TYPE example_summary summary
// example_summary{quantile="0.5",} 0.2
// example_summary_count 3.0
// example_summary_sum 1.3
// # HELP example_summary_created Example Summary
// # TYPE example_summary_created gauge
// example_summary_created 1.658547346261E9
// """