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 {
    pr <- PrometheusRegistry.build[IO]
    counter <- Counter.noLabels(pr, Name("counter"), "Example Counter")
    _ <- counter.inc
    currentMetrics <- pr.write004
  } yield currentMetrics
}
// noLabelsCounterExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.PrometheusRegistry$$$Lambda$11197/0x00007fa08dea8210@58de212c,
//     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
// """

Gauge Example

val noLabelsGaugeExample = {
  for {
    pr <- PrometheusRegistry.build[IO]
    gauge <- Gauge.noLabels(pr, Name("gaugetotal"), "Example Gauge")
    _ <- gauge.inc
    _ <- gauge.inc
    _ <- gauge.dec
    currentMetrics <- pr.write004
  } yield currentMetrics
}
// noLabelsGaugeExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.PrometheusRegistry$$$Lambda$11197/0x00007fa08dea8210@97d073b,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = <function1>,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

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

Histogram Example

val noLabelsHistogramExample = {
  for {
    pr <- PrometheusRegistry.build[IO]
    h <- Histogram.noLabels(pr, Name("example_histogram"), "Example Histogram")
    _ <- h.observe(0.2)
    _ <- h.timed(Temporal[IO].sleep(1.second), SECONDS)
    currentMetrics <- pr.write004
  } yield currentMetrics
}
// noLabelsHistogramExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.PrometheusRegistry$$$Lambda$11197/0x00007fa08dea8210@3ed67f1c,
//     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
// example_histogram_bucket{le="0.01"} 0
// example_histogram_bucket{le="0.025"} 0
// example_histogram_bucket{le="0.05"} 0
// example_histogram_bucket{le="0.075"} 0
// example_histogram_bucket{le="0.1"} 0
// example_histogram_bucket{le="0.25"} 1
// example_histogram_bucket{le="0.5"} 1
// example_histogram_bucket{le="0.75"} 1
// example_histogram_bucket{le="1.0"} 1
// example_histogram_bucket{le="2.5"} 2
// example_histogram_bucket{le="5.0"} 2
// example_histogram_bucket{le="7.5"} 2
// example_histogram_bucket{le="10.0"} 2
// example_histogram_bucket{le="+Inf"} 2
// example_histogram_count 2
// example_histogram_sum 1.2003785679999999
// """

Summary Example

val noLabelsSummaryExample = {
  for {
    pr <- PrometheusRegistry.build[IO]
    s <- Summary.noLabels(pr, Name("example_summary"), "Example Summary", Summary.quantile(0.5,0.05))
    _ <- s.observe(0.1)
    _ <- s.observe(0.2)
    _ <- s.observe(1.0)
    currentMetrics <- pr.write004
  } yield currentMetrics
}
// noLabelsSummaryExample: IO[String] = FlatMap(
//   ioe = Delay(
//     thunk = io.chrisdavenport.epimetheus.PrometheusRegistry$$$Lambda$11197/0x00007fa08dea8210@77ea54e8,
//     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
// example_summary_sum 1.3
// """