country-geo-locations/internal/exporter/collector.go
Tom Neuber d6a411c39b
Some checks failed
ci/woodpecker/push/lint Pipeline failed
ci/woodpecker/push/test unknown status
ci/woodpecker/push/build unknown status
feat(exporter): add prometheus exporter for cache, database & webserver stats
2024-11-28 11:53:40 +01:00

41 lines
1.2 KiB
Go

package exporter
import (
"git.ar21.de/yolokube/country-geo-locations/internal/cache"
"git.ar21.de/yolokube/country-geo-locations/internal/cmd"
"git.ar21.de/yolokube/country-geo-locations/internal/database"
"github.com/prometheus/client_golang/prometheus"
)
type Collector struct {
config *cmd.AppSettings
cache *cache.Cache
db *database.Database
metrics *Metrics
queue *RequestDataQueue
}
func NewCollector(config *cmd.AppSettings, cache *cache.Cache, db *database.Database, queue *RequestDataQueue) *Collector {
return &Collector{
config: config,
cache: cache,
db: db,
metrics: NewMetrics(),
queue: queue,
}
}
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.metrics.metricCacheTTL
ch <- c.metrics.metricCurrentlyCached
ch <- c.metrics.metricDatabaseTimestamp
ch <- c.metrics.metricDatabaseReady
}
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.metrics.collectCacheTTLMetric(ch, c.config.CacheTTL.Seconds())
c.metrics.collectCurrentlyCachedMetric(ch, float64(c.cache.Count()))
c.metrics.collectDatabaseTimestampMetric(ch, c.db)
c.metrics.collectDatabaseReadyMetric(ch, c.db.IsReady())
c.metrics.collectReqeustDataMetrics(ch, c.queue)
}