Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Reset registry on module load to make sure that we can use hot reload…
Browse files Browse the repository at this point in the history
… of play framework
  • Loading branch information
stijndehaes committed Aug 13, 2017
1 parent eac3420 commit 1161a6e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.prometheus.client.CollectorRegistry
class PrometheusModule extends AbstractModule {

override def configure(): Unit = {
CollectorRegistry.defaultRegistry.clear()
bind(classOf[CollectorRegistry]).toInstance(CollectorRegistry.defaultRegistry)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import com.github.stijndehaes.playprometheusfilters.utils.WriterAdapter
import com.google.inject.Inject
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.exporter.common.TextFormat
import org.slf4j.LoggerFactory
import play.api.http.HttpEntity
import play.api.mvc._

class PrometheusController @Inject()(registry: CollectorRegistry) extends Controller {

private val logger = LoggerFactory.getLogger(classOf[PrometheusController])

def getMetrics = Action {
logger.trace("Metrics call received")
val samples = new StringBuilder()
val writer = new WriterAdapter(samples)
TextFormat.write004(writer, registry.metricFamilySamples())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.github.stijndehaes.playprometheusfilters.filters

import akka.stream.Materializer
import com.google.inject.Inject
import com.google.inject.{Inject, Singleton}
import io.prometheus.client.{Collector, CollectorRegistry, Histogram}
import play.api.mvc.{Filter, RequestHeader, Result}
import play.api.routing.Router.Tags

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class StatusAndRouteLatencyFilter @Inject()(registry: CollectorRegistry) (implicit val mat: Materializer, ec: ExecutionContext) extends Filter {

private[filters] val requestLatency = Histogram.build
Expand Down

0 comments on commit 1161a6e

Please sign in to comment.