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
}