Skip to content

Instantly share code, notes, and snippets.

@jdegoes
Created July 31, 2018 21:12
Show Gist options
  • Save jdegoes/27768b0b03d4246b04d8cc32b6cf30ac to your computer and use it in GitHub Desktop.
Save jdegoes/27768b0b03d4246b04d8cc32b6cf30ac to your computer and use it in GitHub Desktop.
Scalaz Metrics
package scalaz.metrics
sealed trait Resevoir[+A]
object Resevoir {
case object Uniform extends Resevoir[Nothing]
case class Bounded[A](lower: A, upper: A) extends Resevoir[A]
}
trait Timer[F] {
def apply[A](io: F[A]): F[A]
}
trait HtmlRender[A] {
def render(a: A): String
}
trait Metrics[C[_], F[_], L] {
def counter(label: L): F[Long => F[Unit]]
def gague[A: Semigroup: C](label: L)(io: F[A]): F[Unit]
def histogram[A: Ord: C](
label: L,
res : Resevoir[A] = Resevoir.Uniform): F[A => F[Unit]]
def timer(label: L): F[Timer[F]]
def meter(label: L): F[Double => F[Unit]]
def contramap[L0](f: L0 => L): Metrics[F, L] = ???
}
// Example usage:
for {
requestCount <- counter(nel("server", "requests", "failed"))
_ <- requestCount(1)
_ <- gague("evictions-count")(cache.getEvictionsCount)
requestLength <- histogram[Double]("request-length")
_ <- requestLength(requestLength)
requestTiming <- timer("request-timing")
_ <- requestTime(doRequest(x, y, z))
}
// Syntax extensions
io.counter(label)
io.timed(label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment