in otelcollector/fluent-bit/src/prometheus_collector_health.go [89:147]
func ExposePrometheusCollectorHealthMetrics() {
// A new registry excludes go_* and promhttp_* metrics for the endpoint
r := prometheus.NewRegistry()
r.MustRegister(timeseriesReceivedMetric)
r.MustRegister(timeseriesSentMetric)
r.MustRegister(bytesSentMetric)
r.MustRegister(invalidCustomConfigMetric)
r.MustRegister(exportingFailedMetric)
handler := promhttp.HandlerFor(r, promhttp.HandlerOpts{})
http.Handle("/metrics", handler)
go func() {
TimeseriesVolumeTicker = time.NewTicker(time.Second * time.Duration(prometheusCollectorHealthInterval))
lastTickerStart := time.Now()
for ; true; <-TimeseriesVolumeTicker.C {
elapsed := time.Since(lastTickerStart)
timePassedInMinutes := (float64(elapsed) / float64(time.Second)) / float64(prometheusCollectorHealthInterval)
TimeseriesVolumeMutex.Lock()
timeseriesReceivedRate := math.Round(TimeseriesReceivedTotal / timePassedInMinutes)
timeseriesSentRate := math.Round(TimeseriesSentTotal / timePassedInMinutes)
bytesSentRate := math.Round(BytesSentTotal / timePassedInMinutes)
timeseriesReceivedMetric.With(prometheus.Labels{"computer":CommonProperties["computer"], "release":CommonProperties["helmreleasename"], "controller_type":CommonProperties["controllertype"]}).Set(timeseriesReceivedRate)
timeseriesSentMetric.With(prometheus.Labels{"computer":CommonProperties["computer"], "release":CommonProperties["helmreleasename"], "controller_type":CommonProperties["controllertype"]}).Set(timeseriesSentRate)
bytesSentMetric.With(prometheus.Labels{"computer":CommonProperties["computer"], "release":CommonProperties["helmreleasename"], "controller_type":CommonProperties["controllertype"]}).Set(bytesSentRate)
TimeseriesReceivedTotal = 0.0
TimeseriesSentTotal = 0.0
BytesSentTotal = 0.0
TimeseriesVolumeMutex.Unlock()
isInvalidCustomConfig := 0
invalidConfigErrorString := ""
if os.Getenv("AZMON_INVALID_CUSTOM_PROMETHEUS_CONFIG") == "true" {
isInvalidCustomConfig = 1
invalidConfigErrorString = os.Getenv("INVALID_CONFIG_FATAL_ERROR")
}
invalidCustomConfigMetric.With(prometheus.Labels{"computer":CommonProperties["computer"], "release":CommonProperties["helmreleasename"], "controller_type":CommonProperties["controllertype"], "error":invalidConfigErrorString}).Set(float64(isInvalidCustomConfig))
ExportingFailedMutex.Lock()
exportingFailedMetric.With(prometheus.Labels{"computer":CommonProperties["computer"], "release":CommonProperties["helmreleasename"], "controller_type":CommonProperties["controllertype"]}).Add(float64(OtelCollectorExportingFailedCount))
OtelCollectorExportingFailedCount = 0
ExportingFailedMutex.Unlock()
lastTickerStart = time.Now()
}
}()
err := http.ListenAndServe(prometheusCollectorHealthPort, nil)
if err != nil {
Log("Error for Prometheus Collector Health endpoint: %s", err.Error())
exception := appinsights.NewExceptionTelemetry(err.Error())
TelemetryClient.Track(exception)
}
}