mirror of
https://github.com/hikhvar/mqtt2prometheus.git
synced 2026-05-06 00:26:35 +00:00
Merge pull request #53 from chr4/chore/fix-cache-config
Chore/fix cache config
This commit is contained in:
@@ -5,8 +5,8 @@ mqtt:
|
||||
metric_per_topic_config:
|
||||
metric_name_regex: "shellies/(?P<deviceid>.*)/sensor/(?P<metricname>.*)"
|
||||
qos: 0
|
||||
cache:
|
||||
timeout: 24h
|
||||
cache:
|
||||
timeout: 24h
|
||||
metrics:
|
||||
- prom_name: temperature
|
||||
# The name of the metric in a MQTT JSON message
|
||||
@@ -40,4 +40,4 @@ metrics:
|
||||
# A map of string to string for constant labels. This labels will be attached to every prometheus metric
|
||||
const_labels:
|
||||
sensor_type: shelly
|
||||
# The name of the metric in prometheus
|
||||
# The name of the metric in prometheus
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const DefaultTimeout = 0
|
||||
|
||||
type Collector interface {
|
||||
prometheus.Collector
|
||||
Observe(deviceID string, collection MetricCollection)
|
||||
@@ -32,7 +30,7 @@ type Metric struct {
|
||||
|
||||
type CacheItem struct {
|
||||
DeviceID string
|
||||
Metric Metric
|
||||
Metric Metric
|
||||
}
|
||||
|
||||
type MetricCollection []Metric
|
||||
@@ -52,10 +50,10 @@ func NewCollector(defaultTimeout time.Duration, possibleMetrics []config.MetricC
|
||||
func (c *MemoryCachedCollector) Observe(deviceID string, collection MetricCollection) {
|
||||
for _, m := range collection {
|
||||
item := CacheItem{
|
||||
DeviceID: deviceID,
|
||||
Metric: m,
|
||||
DeviceID: deviceID,
|
||||
Metric: m,
|
||||
}
|
||||
c.cache.Set(fmt.Sprintf("%s-%s", deviceID, m.Description.String()), item, DefaultTimeout)
|
||||
c.cache.Set(fmt.Sprintf("%s-%s", deviceID, m.Description.String()), item, gocache.DefaultExpiration)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user