Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion reporters/kamon-prometheus/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

kamon.prometheus {

# Enable or disable publishing the Prometheus scraping enpoint using a embedded server.
# Enable or disable publishing the Prometheus scraping endpoint using a embedded server.
start-embedded-http-server = yes

# Enable or disable including tags from kamon.environment.tags as labels
Expand Down Expand Up @@ -98,6 +98,13 @@ kamon.prometheus {
]
}

periods {
# Period over which to accumulate snapshots in the reporter.
accumulation = "1825d"
# Period after which metrics are considered stale and are removed from the prometheus exported data.
stale = "1825d"
}

embedded-server {

# Hostname and port used by the embedded web server to publish the scraping enpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ class PrometheusPushgatewayReporter(
) extends MetricReporter {

private val _logger = LoggerFactory.getLogger(classOf[PrometheusPushgatewayReporter])
private val _initialSettings = PrometheusSettings.readSettings(Kamon.config().getConfig(configPath))
private val _snapshotAccumulator =
PeriodSnapshot.accumulator(Duration.ofDays(365 * 5), Duration.ZERO, Duration.ofDays(365 * 5))
PeriodSnapshot.accumulator(
_initialSettings.periodSettings.accumulationPeriod,
Duration.ZERO,
_initialSettings.periodSettings.stalePeriod
)

@volatile private var httpClient: HttpClient = _
@volatile private var settings: PrometheusSettings.Generic = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ class PrometheusReporter(configPath: String = DefaultConfigPath, initialConfig:

private val _logger = LoggerFactory.getLogger(classOf[PrometheusReporter])
private var _embeddedHttpServer: Option[EmbeddedHttpServer] = None
private val _snapshotAccumulator =
PeriodSnapshot.accumulator(Duration.ofDays(365 * 5), Duration.ZERO, Duration.ofDays(365 * 5))

@volatile private var _preparedScrapeData: String =
"# The kamon-prometheus module didn't receive any data just yet.\n"

@volatile private var _config = initialConfig
@volatile private var _reporterSettings = readSettings(initialConfig.getConfig(configPath))

private val _snapshotAccumulator =
PeriodSnapshot.accumulator(
_reporterSettings.generic.periodSettings.accumulationPeriod,
Duration.ZERO,
_reporterSettings.generic.periodSettings.stalePeriod
)

{
startEmbeddedServerIfEnabled()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import kamon.tag.TagSet
import kamon.util.Filter.Glob
import kamon.{Kamon, UtilsOnConfig}

import java.time.Duration

import scala.collection.JavaConverters._

object PrometheusSettings {
Expand All @@ -33,14 +35,20 @@ object PrometheusSettings {
customBuckets: Map[String, Seq[java.lang.Double]],
includeEnvironmentTags: Boolean,
summarySettings: SummarySettings,
gaugeSettings: GaugeSettings
gaugeSettings: GaugeSettings,
periodSettings: PeriodSettings
)

case class SummarySettings(
quantiles: Seq[java.lang.Double],
metricMatchers: Seq[Glob]
)

case class PeriodSettings(
accumulationPeriod: Duration,
stalePeriod: Duration
)

case class GaugeSettings(metricMatchers: Seq[Glob])

def readSettings(prometheusConfig: Config): Generic = {
Expand All @@ -57,6 +65,10 @@ object PrometheusSettings {
),
gaugeSettings = GaugeSettings(
metricMatchers = prometheusConfig.getStringList("gauges.metrics").asScala.map(Glob).toSeq
),
periodSettings = PeriodSettings(
accumulationPeriod = prometheusConfig.getDuration("periods.accumulation"),
stalePeriod = prometheusConfig.getDuration("periods.stale")
)
)
}
Expand Down