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) }