func New(cfg Config) (*Collector, error) { sensorCfgs := map[int]SensorConfig{} for sensorIdStr, sensorCfg := range cfg.Sensor { sensorId, err := strconv.Atoi(sensorIdStr) if err != nil || sensorId < 0 { return nil, fmt.Errorf("bad sensor ID %q - must be an integer >= 0", sensorId) } sensorCfgs[sensorId] = sensorCfg } var metrics util.MetricCollection c := &Collector{ cfg: cfg, sensorCfgs: sensorCfgs, histSensorsSeen: map[int]struct{}{}, lastSeenDsb: -1, realtimeUpdates: metrics.NewCounterVec( promm.CounterOpts{ Namespace: namespace, Name: "realtime_by_sensor_count", Help: "Count of realtime updates received, by sensor. (count)", ConstLabels: cfg.Labels, }, []string{"sensor"}, ), historyUpdates: metrics.NewCounter( promm.CounterOpts{ Namespace: namespace, Name: "history_count", Help: "Count of historical updates received. (count)", ConstLabels: cfg.Labels, }, ), temperature: metrics.NewGauge(promm.GaugeOpts{ Namespace: namespace, Name: "temperature_degc", Help: "Instananeous measured temperature at the monitor. (degrees celcius)", ConstLabels: cfg.Labels, }), powerDraw: metrics.NewGaugeVec( promm.GaugeOpts{ Namespace: namespace, Name: "power_draw_watts", Help: "Instananeous power drawn measured by sensor. (watts)", ConstLabels: cfg.Labels, }, []string{"sensor", "channel"}, ), powerUsage: metrics.NewCounterVec( promm.CounterOpts{ Namespace: namespace, Name: "power_usage_kwhr", Help: "Cumulative (sum of all channels) power usage measured by sensor. " + "This is accumulated from the latest 2-hourly historical data, so the " + "timeseries resolution is coarse. (kilowatt hours)", ConstLabels: cfg.Labels, }, []string{"sensor"}, ), } c.metrics = metrics return c, nil }