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.ExecutionContext.global
import scala.concurrent.duration._

implicit val CS = IO.contextShift(global)
implicit val T = IO.timer(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: cats.effect.IO[String] = IO$1644002000

noLabelsCounterExample.unsafeRunSync
// res0: String =
// "# HELP counter_total Example Counter
// # TYPE counter_total counter
// counter_total 1.0
// "

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: cats.effect.IO[String] = IO$27779927

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(T.sleep(1.second), SECONDS)
    currentMetrics <- cr.write004
  } yield currentMetrics
}
// noLabelsHistogramExample: cats.effect.IO[String] = IO$847366613

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",} 2.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.2
// "

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: cats.effect.IO[String] = IO$1306416343

noLabelsSummaryExample.unsafeRunSync
// res3: String =
// "# HELP example_summary Example Summary
// # TYPE example_summary summary
// example_summary{quantile="0.5",} 0.1
// example_summary_count 3.0
// example_summary_sum 1.3
// "