feat(exporter): add prometheus exporter for cache, database & webserver stats
This commit is contained in:
parent
95a3a16fdc
commit
4bbda96dc7
8 changed files with 405 additions and 18 deletions
46
internal/exporter/collector.go
Normal file
46
internal/exporter/collector.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue