Example #1
0
File: linux.go Project: huin/warren
func New(cfg Config) (*Collector, error) {
	fsLabelNames := []string{"mount"}
	var metrics util.MetricCollection
	if cpuCollector, err := newCpuCollector(cfg.Cpu, cfg.Labels); err != nil {
		return nil, err
	} else {
		metrics.Add(cpuCollector)
	}
	lc := &Collector{
		cfg: cfg,
		// Meta-metrics:
		fsStatOps: metrics.NewCounterVec(
			promm.CounterOpts{
				Namespace: namespace, Name: "fs_stat_ops_count",
				Help:        "Statfs calls by mount and result (call count).",
				ConstLabels: cfg.Labels,
			},
			[]string{"mount", "result"},
		),
		// Filesystem metrics:
		fsSizeBytes: metrics.NewGaugeVec(
			promm.GaugeOpts{
				Namespace: namespace, Name: "fs_size_bytes",
				Help:        "Filesystem capacity (bytes).",
				ConstLabels: cfg.Labels,
			},
			fsLabelNames,
		),
		fsFreeBytes: metrics.NewGaugeVec(
			promm.GaugeOpts{
				Namespace: namespace, Name: "fs_free_bytes",
				Help:        "Filesystem free space (bytes).",
				ConstLabels: cfg.Labels,
			},
			fsLabelNames,
		),
		fsUnprivFreeBytes: metrics.NewGaugeVec(
			promm.GaugeOpts{
				Namespace: namespace, Name: "fs_unpriv_free_bytes",
				Help:        "Filesystem unpriviledged free space (bytes).",
				ConstLabels: cfg.Labels,
			},
			fsLabelNames,
		),
		fsFiles: metrics.NewGaugeVec(
			promm.GaugeOpts{
				Namespace: namespace, Name: "fs_files",
				Help:        "File count (files).",
				ConstLabels: cfg.Labels,
			},
			fsLabelNames,
		),
		fsFilesFree: metrics.NewGaugeVec(
			promm.GaugeOpts{
				Namespace: namespace, Name: "fs_free_files",
				Help:        "File free count (files).",
				ConstLabels: cfg.Labels,
			},
			fsLabelNames,
		),
		// Network metrics:
		ifaceTxBytes: metrics.NewCounterVec(
			promm.CounterOpts{
				Namespace: namespace, Name: "net_tx_bytes",
				Help:        "Count of bytes transmitted by network interface (bytes).",
				ConstLabels: cfg.Labels,
			},
			[]string{"interface"},
		),
		ifaceRxBytes: metrics.NewCounterVec(
			promm.CounterOpts{
				Namespace: namespace, Name: "net_rx_bytes",
				Help:        "Count of bytes received by network interface (bytes).",
				ConstLabels: cfg.Labels,
			},
			[]string{"interface"},
		),
	}
	lc.metrics = metrics
	return lc, nil
}
Example #2
0
File: cc.go Project: huin/warren
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
}