Merge pull request #389 from prometheus/fish-use-const-metrics

Convert remaining collectors to use ConstMetrics
This commit is contained in:
Johannes 'fish' Ziemke 2017-01-03 14:22:58 +01:00 committed by GitHub
commit 079fd701a0
17 changed files with 455 additions and 614 deletions

View file

@ -26,7 +26,7 @@ import (
) )
type bondingCollector struct { type bondingCollector struct {
slaves, active *prometheus.GaugeVec slaves, active typedDesc
} }
func init() { func init() {
@ -37,22 +37,16 @@ func init() {
// It exposes the number of configured and active slave of linux bonding interfaces. // It exposes the number of configured and active slave of linux bonding interfaces.
func NewBondingCollector() (Collector, error) { func NewBondingCollector() (Collector, error) {
return &bondingCollector{ return &bondingCollector{
slaves: prometheus.NewGaugeVec( slaves: typedDesc{prometheus.NewDesc(
prometheus.GaugeOpts{ prometheus.BuildFQName(Namespace, "bonding", "slaves"),
Namespace: Namespace, "Number of configured slaves per bonding interface.",
Name: "net_bonding_slaves", []string{"master"}, nil,
Help: "Number of configured slaves per bonding interface.", ), prometheus.GaugeValue},
}, active: typedDesc{prometheus.NewDesc(
[]string{"master"}, prometheus.BuildFQName(Namespace, "bonding", "active"),
), "Number of active slaves per bonding interface.",
active: prometheus.NewGaugeVec( []string{"master"}, nil,
prometheus.GaugeOpts{ ), prometheus.GaugeValue},
Namespace: Namespace,
Name: "net_bonding_slaves_active",
Help: "Number of active slaves per bonding interface.",
},
[]string{"master"},
),
}, nil }, nil
} }
@ -63,11 +57,9 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) (err error) {
return err return err
} }
for master, status := range bondingStats { for master, status := range bondingStats {
c.slaves.WithLabelValues(master).Set(float64(status[0])) ch <- c.slaves.mustNewConstMetric(float64(status[0]), master)
c.active.WithLabelValues(master).Set(float64(status[1])) ch <- c.active.mustNewConstMetric(float64(status[1]), master)
} }
c.slaves.Collect(ch)
c.active.Collect(ch)
return nil return nil
} }

View file

@ -32,3 +32,12 @@ type Collector interface {
// Get new metrics and expose them via prometheus registry. // Get new metrics and expose them via prometheus registry.
Update(ch chan<- prometheus.Metric) (err error) Update(ch chan<- prometheus.Metric) (err error)
} }
type typedDesc struct {
desc *prometheus.Desc
valueType prometheus.ValueType
}
func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) prometheus.Metric {
return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...)
}

View file

@ -89,14 +89,11 @@ func init() {
// CPU stats. // CPU stats.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewCounterVec( cpu: typedDesc{prometheus.NewDesc(
prometheus.CounterOpts{ prometheus.BuildFQName(Namespace, "cpu", "seconds_total"),
Namespace: Namespace, "Seconds the CPU spent in each mode.",
Name: "cpu_seconds_total", []string{"cpu", "mode"}, nil,
Help: "Seconds the CPU spent in each mode.", ), prometheus.CounterValue},
},
[]string{"cpu", "mode"},
),
}, nil }, nil
} }
@ -118,12 +115,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
return err return err
} }
for cpu, t := range cpuTimes { for cpu, t := range cpuTimes {
c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(cpu), "mode": "user"}).Set(t.user) ch <- c.cpu.mustNewConstMetric(float64(cpuTimes[base_idx+C.CP_USER]), strconv.Itoa(cpu), "user")
c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(cpu), "mode": "nice"}).Set(t.nice) ch <- c.cpu.mustNewConstMetric(float64(cpuTimes[base_idx+C.CP_NICE]), strconv.Itoa(cpu), "nice")
c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(cpu), "mode": "system"}).Set(t.sys) ch <- c.cpu.mustNewConstMetric(float64(cpuTimes[base_idx+C.CP_SYS]), strconv.Itoa(cpu), "system")
c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(cpu), "mode": "interrupt"}).Set(t.intr) ch <- c.cpu.mustNewConstMetric(float64(cpuTimes[base_idx+C.CP_INTR]), strconv.Itoa(cpu), "interrupt")
c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(cpu), "mode": "idle"}).Set(t.idle) ch <- c.cpu.mustNewConstMetric(float64(cpuTimes[base_idx+C.CP_IDLE]), strconv.Itoa(cpu), "idle")
} }
c.cpu.Collect(ch)
return err return err
} }

View file

@ -137,12 +137,12 @@ const (
) )
type devstatCollector struct { type devstatCollector struct {
bytes *prometheus.CounterVec bytes typedDesc
bytes_total *prometheus.CounterVec bytes_total typedDesc
transfers *prometheus.CounterVec transfers typedDesc
duration *prometheus.CounterVec duration typedDesc
busyTime *prometheus.CounterVec busyTime typedDesc
blocks *prometheus.CounterVec blocks typedDesc
} }
func init() { func init() {
@ -153,51 +153,31 @@ func init() {
// Device stats. // Device stats.
func NewDevstatCollector() (Collector, error) { func NewDevstatCollector() (Collector, error) {
return &devstatCollector{ return &devstatCollector{
bytes: prometheus.NewCounterVec( bytes: typedDesc{prometheus.NewDesc(
prometheus.CounterOpts{ prometheus.BuildFQName(Namespace, devstatSubsystem, "bytes_total"),
Namespace: Namespace, "The total number of bytes in transactions.",
Subsystem: devstatSubsystem, []string{"device", "type"}, nil,
Name: "bytes_total", ), prometheus.CounterValue},
Help: "The total number of bytes in transactions.", transfers: typedDesc{prometheus.NewDesc(
}, prometheus.BuildFQName(Namespace, devstatSubsystem, "transfers_total"),
[]string{"device", "type"}, "The total number of transactions.",
), []string{"device", "type"}, nil,
transfers: prometheus.NewCounterVec( ), prometheus.CounterValue},
prometheus.CounterOpts{ duration: typedDesc{prometheus.NewDesc(
Namespace: Namespace, prometheus.BuildFQName(Namespace, devstatSubsystem, "duration_seconds_total"),
Subsystem: devstatSubsystem, "The total duration of transactions in seconds.",
Name: "transfers_total", []string{"device", "type"}, nil,
Help: "The total number of transactions.", ), prometheus.CounterValue},
}, busyTime: typedDesc{prometheus.NewDesc(
[]string{"device", "type"}, prometheus.BuildFQName(Namespace, devstatSubsystem, "busy_time_seconds_total"),
), "Total time the device had one or more transactions outstanding in seconds.",
duration: prometheus.NewCounterVec( []string{"device"}, nil,
prometheus.CounterOpts{ ), prometheus.CounterValue},
Namespace: Namespace, blocks: typedDesc{prometheus.NewDesc(
Subsystem: devstatSubsystem, prometheus.BuildFQName(Namespace, devstatSubsystem, "blocks_transferred_total"),
Name: "duration_seconds_total", "The total number of blocks transferred.",
Help: "The total duration of transactions in seconds.", []string{"device"}, nil,
}, ), prometheus.CounterValue},
[]string{"device", "type"},
),
busyTime: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: devstatSubsystem,
Name: "busy_time_seconds_total",
Help: "Total time the device had one or more transactions outstanding in seconds.",
},
[]string{"device"},
),
blocks: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: devstatSubsystem,
Name: "blocks_transferred_total",
Help: "The total number of blocks transferred.",
},
[]string{"device"},
),
}, nil }, nil
} }
@ -213,27 +193,16 @@ func (c *devstatCollector) Update(ch chan<- prometheus.Metric) (err error) {
for i := C.int(0); i < count; i++ { for i := C.int(0); i < count; i++ {
stats := C._get_stats(i) stats := C._get_stats(i)
device := fmt.Sprintf("%s%d", C.GoString(&stats.device[0]), stats.unit) device := fmt.Sprintf("%s%d", C.GoString(&stats.device[0]), stats.unit)
// Free metrics are disabled for now, please see PR #88 for more details. ch <- c.bytes.mustNewConstMetric(float64(stats.bytes.read), device, "read")
c.bytes.With(prometheus.Labels{"device": device, "type": "read"}).Set(float64(stats.bytes.read)) ch <- c.bytes.mustNewConstMetric(float64(stats.bytes.write), device, "write")
c.bytes.With(prometheus.Labels{"device": device, "type": "write"}).Set(float64(stats.bytes.write)) ch <- c.transfers.mustNewConstMetric(float64(stats.transfers.other), device, "other")
//c.bytes.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.bytes.free)) ch <- c.transfers.mustNewConstMetric(float64(stats.transfers.read), device, "read")
c.transfers.With(prometheus.Labels{"device": device, "type": "other"}).Set(float64(stats.transfers.other)) ch <- c.transfers.mustNewConstMetric(float64(stats.transfers.write), device, "write")
c.transfers.With(prometheus.Labels{"device": device, "type": "read"}).Set(float64(stats.transfers.read)) ch <- c.duration.mustNewConstMetric(float64(stats.duration.other), device, "other")
c.transfers.With(prometheus.Labels{"device": device, "type": "write"}).Set(float64(stats.transfers.write)) ch <- c.duration.mustNewConstMetric(float64(stats.duration.read), device, "read")
//c.transfers.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.transfers.free)) ch <- c.duration.mustNewConstMetric(float64(stats.duration.write), device, "write")
c.duration.With(prometheus.Labels{"device": device, "type": "other"}).Set(float64(stats.duration.other)) ch <- c.busyTime.mustNewConstMetric(float64(stats.busyTime), device)
c.duration.With(prometheus.Labels{"device": device, "type": "read"}).Set(float64(stats.duration.read)) ch <- c.blocks.mustNewConstMetric(float64(stats.blocks), device)
c.duration.With(prometheus.Labels{"device": device, "type": "write"}).Set(float64(stats.duration.write))
//c.duration.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.duration.free))
c.busyTime.With(prometheus.Labels{"device": device}).Set(float64(stats.busyTime))
c.blocks.With(prometheus.Labels{"device": device}).Set(float64(stats.blocks))
} }
c.bytes.Collect(ch)
c.transfers.Collect(ch)
c.duration.Collect(ch)
c.busyTime.Collect(ch)
c.blocks.Collect(ch)
return err return err
} }

View file

@ -40,7 +40,7 @@ var (
type diskstatsCollector struct { type diskstatsCollector struct {
ignoredDevicesPattern *regexp.Regexp ignoredDevicesPattern *regexp.Regexp
metrics []prometheus.Collector descs []typedDesc
} }
func init() { func init() {
@ -55,129 +55,116 @@ func NewDiskstatsCollector() (Collector, error) {
return &diskstatsCollector{ return &diskstatsCollector{
ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices), ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices),
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt // Docs from https://www.kernel.org/doc/Documentation/iostats.txt
metrics: []prometheus.Collector{ descs: []typedDesc{
prometheus.NewCounterVec( {
prometheus.CounterOpts{ desc: prometheus.NewDesc(
Namespace: Namespace, prometheus.BuildFQName(Namespace, diskSubsystem, "reads_completed"),
Subsystem: diskSubsystem, "The total number of reads completed successfully.",
Name: "reads_completed",
Help: "The total number of reads completed successfully.",
},
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "reads_merged",
Help: "The number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "reads_merged"),
"The total number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "sectors_read",
Help: "The total number of sectors read successfully.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "sectors_read"),
"The total number of sectors read successfully.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "read_time_ms",
Help: "The total number of milliseconds spent by all reads.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "read_time_ms"),
"The total number of milliseconds spent by all reads.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "writes_completed",
Help: "The total number of writes completed successfully.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "writes_completed"),
"The total number of writes completed successfully.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "writes_merged",
Help: "The number of writes merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "writes_merged"),
"The number of writes merged. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "sectors_written",
Help: "The total number of sectors written successfully.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "sectors_written"),
"The total number of sectors written successfully.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "write_time_ms",
Help: "This is the total number of milliseconds spent by all writes.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "write_time_ms"),
"This is the total number of milliseconds spent by all writes.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewGaugeVec( ), valueType: prometheus.CounterValue,
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "io_now",
Help: "The number of I/Os currently in progress.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_now"),
"The number of I/Os currently in progress.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.GaugeValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "io_time_ms",
Help: "Milliseconds spent doing I/Os.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_time_ms"),
"Total Milliseconds spent doing I/Os.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "io_time_weighted",
Help: "The weighted # of milliseconds spent doing I/Os. See https://www.kernel.org/doc/Documentation/iostats.txt.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "io_time_weighted"),
"The weighted # of milliseconds spent doing I/Os. See https://www.kernel.org/doc/Documentation/iostats.txt.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "bytes_read",
Help: "The total number of bytes read successfully.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "bytes_read"),
"The total number of bytes read successfully.",
diskLabelNames, diskLabelNames,
), nil,
prometheus.NewCounterVec( ), valueType: prometheus.CounterValue,
prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: diskSubsystem,
Name: "bytes_written",
Help: "The total number of bytes written successfully.",
}, },
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, diskSubsystem, "bytes_written"),
"The total number of bytes written successfully.",
diskLabelNames, diskLabelNames,
), nil,
), valueType: prometheus.CounterValue,
},
}, },
}, nil }, nil
} }
func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) { func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
procDiskStats := procFilePath("diskstats") procDiskStats := procFilePath("diskstats")
diskStats, err := getDiskStats() diskStats, err := getDiskStats()
if err != nil { if err != nil {
@ -190,29 +177,19 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
continue continue
} }
if len(stats) != len(c.metrics) { if len(stats) != len(c.descs) {
return fmt.Errorf("invalid line for %s for %s", procDiskStats, dev) return fmt.Errorf("invalid line for %s for %s", procDiskStats, dev)
} }
for k, value := range stats { for i, value := range stats {
v, err := strconv.ParseFloat(value, 64) v, err := strconv.ParseFloat(value, 64)
if err != nil { if err != nil {
return fmt.Errorf("invalid value %s in diskstats: %s", value, err) return fmt.Errorf("invalid value %s in diskstats: %s", value, err)
} }
ch <- c.descs[i].mustNewConstMetric(v, dev)
if counter, ok := c.metrics[k].(*prometheus.CounterVec); ok {
counter.WithLabelValues(dev).Set(v)
} else if gauge, ok := c.metrics[k].(*prometheus.GaugeVec); ok {
gauge.WithLabelValues(dev).Set(v)
} else {
return fmt.Errorf("unexpected collector %d", k)
} }
} }
} return nil
for _, c := range c.metrics {
c.Collect(ch)
}
return err
} }
func getDiskStats() (map[string]map[int]string, error) { func getDiskStats() (map[string]map[int]string, error) {

View file

@ -12,73 +12,73 @@ go_gc_duration_seconds_count 0
go_goroutines 13 go_goroutines 13
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge # TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.236968e+06 go_memstats_alloc_bytes 1.196768e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed. # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter # TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.236968e+06 go_memstats_alloc_bytes_total 1.196768e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge # TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 2717 go_memstats_buck_hash_sys_bytes 1.442915e+06
# HELP go_memstats_frees_total Total number of frees. # HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter # TYPE go_memstats_frees_total counter
go_memstats_frees_total 265 go_memstats_frees_total 385
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata. # HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge # TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 65536 go_memstats_gc_sys_bytes 98304
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use. # HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge # TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 1.236968e+06 go_memstats_heap_alloc_bytes 1.196768e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used. # HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge # TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 139264 go_memstats_heap_idle_bytes 884736
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use. # HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge # TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 1.630208e+06 go_memstats_heap_inuse_bytes 1.867776e+06
# HELP go_memstats_heap_objects Number of allocated objects. # HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge # TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 8119 go_memstats_heap_objects 8934
# HELP go_memstats_heap_released_bytes_total Total number of heap bytes released to OS. # HELP go_memstats_heap_released_bytes_total Total number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes_total counter # TYPE go_memstats_heap_released_bytes_total counter
go_memstats_heap_released_bytes_total 0 go_memstats_heap_released_bytes_total 0
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system. # HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge # TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 1.769472e+06 go_memstats_heap_sys_bytes 2.752512e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection. # HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge # TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 9 go_memstats_last_gc_time_seconds 0
# HELP go_memstats_lookups_total Total number of pointer lookups. # HELP go_memstats_lookups_total Total number of pointer lookups.
# TYPE go_memstats_lookups_total counter # TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 9 go_memstats_lookups_total 9
# HELP go_memstats_mallocs_total Total number of mallocs. # HELP go_memstats_mallocs_total Total number of mallocs.
# TYPE go_memstats_mallocs_total counter # TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 8384 go_memstats_mallocs_total 9319
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures. # HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.
# TYPE go_memstats_mcache_inuse_bytes gauge # TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 9600 go_memstats_mcache_inuse_bytes 4800
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system. # HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.
# TYPE go_memstats_mcache_sys_bytes gauge # TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16384 go_memstats_mcache_sys_bytes 16384
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures. # HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.
# TYPE go_memstats_mspan_inuse_bytes gauge # TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 16080 go_memstats_mspan_inuse_bytes 19920
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system. # HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.
# TYPE go_memstats_mspan_sys_bytes gauge # TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 16384 go_memstats_mspan_sys_bytes 32768
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place. # HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.
# TYPE go_memstats_next_gc_bytes gauge # TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.194304e+06 go_memstats_next_gc_bytes 4.194304e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations. # HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.
# TYPE go_memstats_other_sys_bytes gauge # TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 558435 go_memstats_other_sys_bytes 803989
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator. # HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.
# TYPE go_memstats_stack_inuse_bytes gauge # TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 327680 go_memstats_stack_inuse_bytes 393216
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator. # HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.
# TYPE go_memstats_stack_sys_bytes gauge # TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 327680 go_memstats_stack_sys_bytes 393216
# HELP go_memstats_sys_bytes Number of bytes obtained by system. Sum of all system allocations. # HELP go_memstats_sys_bytes Number of bytes obtained by system. Sum of all system allocations.
# TYPE go_memstats_sys_bytes gauge # TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 2.756608e+06 go_memstats_sys_bytes 5.540088e+06
# HELP http_request_duration_microseconds The HTTP request latencies in microseconds. # HELP http_request_duration_microseconds The HTTP request latencies in microseconds.
# TYPE http_request_duration_microseconds summary # TYPE http_request_duration_microseconds summary
http_request_duration_microseconds{handler="prometheus",quantile="0.5"} NaN http_request_duration_microseconds{handler="prometheus",quantile="0.5"} NaN
@ -100,6 +100,16 @@ http_response_size_bytes{handler="prometheus",quantile="0.9"} NaN
http_response_size_bytes{handler="prometheus",quantile="0.99"} NaN http_response_size_bytes{handler="prometheus",quantile="0.99"} NaN
http_response_size_bytes_sum{handler="prometheus"} 0 http_response_size_bytes_sum{handler="prometheus"} 0
http_response_size_bytes_count{handler="prometheus"} 0 http_response_size_bytes_count{handler="prometheus"} 0
# HELP node_bonding_active Number of active slaves per bonding interface.
# TYPE node_bonding_active gauge
node_bonding_active{master="bond0"} 0
node_bonding_active{master="dmz"} 2
node_bonding_active{master="int"} 1
# HELP node_bonding_slaves Number of configured slaves per bonding interface.
# TYPE node_bonding_slaves gauge
node_bonding_slaves{master="bond0"} 0
node_bonding_slaves{master="dmz"} 2
node_bonding_slaves{master="int"} 2
# HELP node_boot_time Node boot time, in unixtime. # HELP node_boot_time Node boot time, in unixtime.
# TYPE node_boot_time gauge # TYPE node_boot_time gauge
node_boot_time 1.418183276e+09 node_boot_time 1.418183276e+09
@ -225,7 +235,7 @@ node_disk_io_now{device="nvme0n1"} 0
node_disk_io_now{device="sda"} 0 node_disk_io_now{device="sda"} 0
node_disk_io_now{device="sr0"} 0 node_disk_io_now{device="sr0"} 0
node_disk_io_now{device="vda"} 0 node_disk_io_now{device="vda"} 0
# HELP node_disk_io_time_ms Milliseconds spent doing I/Os. # HELP node_disk_io_time_ms Total Milliseconds spent doing I/Os.
# TYPE node_disk_io_time_ms counter # TYPE node_disk_io_time_ms counter
node_disk_io_time_ms{device="dm-0"} 1.1325968e+07 node_disk_io_time_ms{device="dm-0"} 1.1325968e+07
node_disk_io_time_ms{device="dm-1"} 76 node_disk_io_time_ms{device="dm-1"} 76
@ -285,7 +295,7 @@ node_disk_reads_completed{device="nvme0n1"} 47114
node_disk_reads_completed{device="sda"} 2.5354637e+07 node_disk_reads_completed{device="sda"} 2.5354637e+07
node_disk_reads_completed{device="sr0"} 0 node_disk_reads_completed{device="sr0"} 0
node_disk_reads_completed{device="vda"} 1.775784e+06 node_disk_reads_completed{device="vda"} 1.775784e+06
# HELP node_disk_reads_merged The number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt. # HELP node_disk_reads_merged The total number of reads merged. See https://www.kernel.org/doc/Documentation/iostats.txt.
# TYPE node_disk_reads_merged counter # TYPE node_disk_reads_merged counter
node_disk_reads_merged{device="dm-0"} 0 node_disk_reads_merged{device="dm-0"} 0
node_disk_reads_merged{device="dm-1"} 0 node_disk_reads_merged{device="dm-1"} 0
@ -427,98 +437,108 @@ node_drbd_remote_unacknowledged{device="drbd1"} 12347
node_entropy_available_bits 1337 node_entropy_available_bits 1337
# HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built. # HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built.
# TYPE node_exporter_build_info gauge # TYPE node_exporter_build_info gauge
node_exporter_build_info{branch="",goversion="go1.6.2",revision="",version=""} 1 node_exporter_build_info{branch="master",goversion="go1.6.1",revision="10e525ff0258b2d18119f0327cc9c7ff86e53375",version="0.13.0"} 1
# HELP node_exporter_scrape_duration_seconds node_exporter: Duration of a scrape job. # HELP node_exporter_scrape_duration_seconds node_exporter: Duration of a scrape job.
# TYPE node_exporter_scrape_duration_seconds summary # TYPE node_exporter_scrape_duration_seconds summary
node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.5"} 0.00016681900000000002 node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.5"} 0.000727146
node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.9"} 0.00016681900000000002 node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.9"} 0.000727146
node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.99"} 0.00016681900000000002 node_exporter_scrape_duration_seconds{collector="bonding",result="success",quantile="0.99"} 0.000727146
node_exporter_scrape_duration_seconds_sum{collector="bonding",result="success"} 0.00016681900000000002 node_exporter_scrape_duration_seconds_sum{collector="bonding",result="success"} 0.000727146
node_exporter_scrape_duration_seconds_count{collector="bonding",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="bonding",result="success"} 1
node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.5"} 7.791e-05 node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.5"} 0.00031236
node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.9"} 7.791e-05 node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.9"} 0.00031236
node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.99"} 7.791e-05 node_exporter_scrape_duration_seconds{collector="conntrack",result="success",quantile="0.99"} 0.00031236
node_exporter_scrape_duration_seconds_sum{collector="conntrack",result="success"} 7.791e-05 node_exporter_scrape_duration_seconds_sum{collector="conntrack",result="success"} 0.00031236
node_exporter_scrape_duration_seconds_count{collector="conntrack",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="conntrack",result="success"} 1
node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.5"} 0.005133268000000001 node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.5"} 0.020673309
node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.9"} 0.005133268000000001 node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.9"} 0.020673309
node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.99"} 0.005133268000000001 node_exporter_scrape_duration_seconds{collector="diskstats",result="success",quantile="0.99"} 0.020673309
node_exporter_scrape_duration_seconds_sum{collector="diskstats",result="success"} 0.005133268000000001 node_exporter_scrape_duration_seconds_sum{collector="diskstats",result="success"} 0.020673309
node_exporter_scrape_duration_seconds_count{collector="diskstats",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="diskstats",result="success"} 1
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.5"} 0.000170072 node_exporter_scrape_duration_seconds{collector="drbd",result="success",quantile="0.5"} 0.006692643000000001
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.9"} 0.000170072 node_exporter_scrape_duration_seconds{collector="drbd",result="success",quantile="0.9"} 0.006692643000000001
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.99"} 0.000170072 node_exporter_scrape_duration_seconds{collector="drbd",result="success",quantile="0.99"} 0.006692643000000001
node_exporter_scrape_duration_seconds_sum{collector="entropy",result="success"} 0.000170072 node_exporter_scrape_duration_seconds_sum{collector="drbd",result="success"} 0.006692643000000001
node_exporter_scrape_duration_seconds_count{collector="drbd",result="success"} 1
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.5"} 0.000102584
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.9"} 0.000102584
node_exporter_scrape_duration_seconds{collector="entropy",result="success",quantile="0.99"} 0.000102584
node_exporter_scrape_duration_seconds_sum{collector="entropy",result="success"} 0.000102584
node_exporter_scrape_duration_seconds_count{collector="entropy",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="entropy",result="success"} 1
node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.5"} 8.825900000000001e-05 node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.5"} 0.0006287700000000001
node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.9"} 8.825900000000001e-05 node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.9"} 0.0006287700000000001
node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.99"} 8.825900000000001e-05 node_exporter_scrape_duration_seconds{collector="filefd",result="success",quantile="0.99"} 0.0006287700000000001
node_exporter_scrape_duration_seconds_sum{collector="filefd",result="success"} 8.825900000000001e-05 node_exporter_scrape_duration_seconds_sum{collector="filefd",result="success"} 0.0006287700000000001
node_exporter_scrape_duration_seconds_count{collector="filefd",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="filefd",result="success"} 1
node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.5"} 0.0076871280000000005 node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.5"} 0.020271281000000002
node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.9"} 0.0076871280000000005 node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.9"} 0.020271281000000002
node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.99"} 0.0076871280000000005 node_exporter_scrape_duration_seconds{collector="hwmon",result="success",quantile="0.99"} 0.020271281000000002
node_exporter_scrape_duration_seconds_sum{collector="hwmon",result="success"} 0.0076871280000000005 node_exporter_scrape_duration_seconds_sum{collector="hwmon",result="success"} 0.020271281000000002
node_exporter_scrape_duration_seconds_count{collector="hwmon",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="hwmon",result="success"} 1
node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.5"} 0.001088926 node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.5"} 0.005877574
node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.9"} 0.001088926 node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.9"} 0.005877574
node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.99"} 0.001088926 node_exporter_scrape_duration_seconds{collector="ksmd",result="success",quantile="0.99"} 0.005877574
node_exporter_scrape_duration_seconds_sum{collector="ksmd",result="success"} 0.001088926 node_exporter_scrape_duration_seconds_sum{collector="ksmd",result="success"} 0.005877574
node_exporter_scrape_duration_seconds_count{collector="ksmd",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="ksmd",result="success"} 1
node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.5"} 0.000189222 node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.5"} 0.0009549230000000001
node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.9"} 0.000189222 node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.9"} 0.0009549230000000001
node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.99"} 0.000189222 node_exporter_scrape_duration_seconds{collector="loadavg",result="success",quantile="0.99"} 0.0009549230000000001
node_exporter_scrape_duration_seconds_sum{collector="loadavg",result="success"} 0.000189222 node_exporter_scrape_duration_seconds_sum{collector="loadavg",result="success"} 0.0009549230000000001
node_exporter_scrape_duration_seconds_count{collector="loadavg",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="loadavg",result="success"} 1
node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.5"} 0.0030327270000000003 node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.5"} 0.001143003
node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.9"} 0.0030327270000000003 node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.9"} 0.001143003
node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.99"} 0.0030327270000000003 node_exporter_scrape_duration_seconds{collector="mdadm",result="success",quantile="0.99"} 0.001143003
node_exporter_scrape_duration_seconds_sum{collector="mdadm",result="success"} 0.0030327270000000003 node_exporter_scrape_duration_seconds_sum{collector="mdadm",result="success"} 0.001143003
node_exporter_scrape_duration_seconds_count{collector="mdadm",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="mdadm",result="success"} 1
node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.5"} 0.010434629 node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.5"} 0.027908419
node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.9"} 0.010434629 node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.9"} 0.027908419
node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.99"} 0.010434629 node_exporter_scrape_duration_seconds{collector="megacli",result="success",quantile="0.99"} 0.027908419
node_exporter_scrape_duration_seconds_sum{collector="megacli",result="success"} 0.010434629 node_exporter_scrape_duration_seconds_sum{collector="megacli",result="success"} 0.027908419
node_exporter_scrape_duration_seconds_count{collector="megacli",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="megacli",result="success"} 1
node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.5"} 0.000966604 node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.5"} 0.0061671370000000005
node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.9"} 0.000966604 node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.9"} 0.0061671370000000005
node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.99"} 0.000966604 node_exporter_scrape_duration_seconds{collector="meminfo",result="success",quantile="0.99"} 0.0061671370000000005
node_exporter_scrape_duration_seconds_sum{collector="meminfo",result="success"} 0.000966604 node_exporter_scrape_duration_seconds_sum{collector="meminfo",result="success"} 0.0061671370000000005
node_exporter_scrape_duration_seconds_count{collector="meminfo",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="meminfo",result="success"} 1
node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.5"} 0.0017954980000000002 node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.5"} 0.002422029
node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.9"} 0.0017954980000000002 node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.9"} 0.002422029
node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.99"} 0.0017954980000000002 node_exporter_scrape_duration_seconds{collector="meminfo_numa",result="success",quantile="0.99"} 0.002422029
node_exporter_scrape_duration_seconds_sum{collector="meminfo_numa",result="success"} 0.0017954980000000002 node_exporter_scrape_duration_seconds_sum{collector="meminfo_numa",result="success"} 0.002422029
node_exporter_scrape_duration_seconds_count{collector="meminfo_numa",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="meminfo_numa",result="success"} 1
node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.5"} 0.000512374 node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.5"} 0.0007559820000000001
node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.9"} 0.000512374 node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.9"} 0.0007559820000000001
node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.99"} 0.000512374 node_exporter_scrape_duration_seconds{collector="mountstats",result="success",quantile="0.99"} 0.0007559820000000001
node_exporter_scrape_duration_seconds_sum{collector="mountstats",result="success"} 0.000512374 node_exporter_scrape_duration_seconds_sum{collector="mountstats",result="success"} 0.0007559820000000001
node_exporter_scrape_duration_seconds_count{collector="mountstats",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="mountstats",result="success"} 1
node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.5"} 0.000495389 node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.5"} 0.001059188
node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.9"} 0.000495389 node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.9"} 0.001059188
node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.99"} 0.000495389 node_exporter_scrape_duration_seconds{collector="netdev",result="success",quantile="0.99"} 0.001059188
node_exporter_scrape_duration_seconds_sum{collector="netdev",result="success"} 0.000495389 node_exporter_scrape_duration_seconds_sum{collector="netdev",result="success"} 0.001059188
node_exporter_scrape_duration_seconds_count{collector="netdev",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="netdev",result="success"} 1
node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.5"} 0.004669412 node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.5"} 0.007826913000000001
node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.9"} 0.004669412 node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.9"} 0.007826913000000001
node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.99"} 0.004669412 node_exporter_scrape_duration_seconds{collector="netstat",result="success",quantile="0.99"} 0.007826913000000001
node_exporter_scrape_duration_seconds_sum{collector="netstat",result="success"} 0.004669412 node_exporter_scrape_duration_seconds_sum{collector="netstat",result="success"} 0.007826913000000001
node_exporter_scrape_duration_seconds_count{collector="netstat",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="netstat",result="success"} 1
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.5"} 0.000185951 node_exporter_scrape_duration_seconds{collector="nfs",result="success",quantile="0.5"} 0.0006455
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.9"} 0.000185951 node_exporter_scrape_duration_seconds{collector="nfs",result="success",quantile="0.9"} 0.0006455
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.99"} 0.000185951 node_exporter_scrape_duration_seconds{collector="nfs",result="success",quantile="0.99"} 0.0006455
node_exporter_scrape_duration_seconds_sum{collector="sockstat",result="success"} 0.000185951 node_exporter_scrape_duration_seconds_sum{collector="nfs",result="success"} 0.0006455
node_exporter_scrape_duration_seconds_count{collector="nfs",result="success"} 1
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.5"} 0.007697428
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.9"} 0.007697428
node_exporter_scrape_duration_seconds{collector="sockstat",result="success",quantile="0.99"} 0.007697428
node_exporter_scrape_duration_seconds_sum{collector="sockstat",result="success"} 0.007697428
node_exporter_scrape_duration_seconds_count{collector="sockstat",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="sockstat",result="success"} 1
node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.5"} 0.00029448200000000004 node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.5"} 0.006157345000000001
node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.9"} 0.00029448200000000004 node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.9"} 0.006157345000000001
node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.99"} 0.00029448200000000004 node_exporter_scrape_duration_seconds{collector="stat",result="success",quantile="0.99"} 0.006157345000000001
node_exporter_scrape_duration_seconds_sum{collector="stat",result="success"} 0.00029448200000000004 node_exporter_scrape_duration_seconds_sum{collector="stat",result="success"} 0.006157345000000001
node_exporter_scrape_duration_seconds_count{collector="stat",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="stat",result="success"} 1
node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.5"} 5.180000000000001e-07 node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.5"} 7.63e-07
node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.9"} 5.180000000000001e-07 node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.9"} 7.63e-07
node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.99"} 5.180000000000001e-07 node_exporter_scrape_duration_seconds{collector="textfile",result="success",quantile="0.99"} 7.63e-07
node_exporter_scrape_duration_seconds_sum{collector="textfile",result="success"} 5.180000000000001e-07 node_exporter_scrape_duration_seconds_sum{collector="textfile",result="success"} 7.63e-07
node_exporter_scrape_duration_seconds_count{collector="textfile",result="success"} 1 node_exporter_scrape_duration_seconds_count{collector="textfile",result="success"} 1
# HELP node_filefd_allocated File descriptor statistics: allocated. # HELP node_filefd_allocated File descriptor statistics: allocated.
# TYPE node_filefd_allocated gauge # TYPE node_filefd_allocated gauge
@ -1219,16 +1239,6 @@ node_mountstats_nfs_write_bytes_total{export="192.168.1.1:/srv/test"} 0
# HELP node_mountstats_nfs_write_pages_total Number of pages written directly via mmap()'d files. # HELP node_mountstats_nfs_write_pages_total Number of pages written directly via mmap()'d files.
# TYPE node_mountstats_nfs_write_pages_total counter # TYPE node_mountstats_nfs_write_pages_total counter
node_mountstats_nfs_write_pages_total{export="192.168.1.1:/srv/test"} 0 node_mountstats_nfs_write_pages_total{export="192.168.1.1:/srv/test"} 0
# HELP node_net_bonding_slaves Number of configured slaves per bonding interface.
# TYPE node_net_bonding_slaves gauge
node_net_bonding_slaves{master="bond0"} 0
node_net_bonding_slaves{master="dmz"} 2
node_net_bonding_slaves{master="int"} 2
# HELP node_net_bonding_slaves_active Number of active slaves per bonding interface.
# TYPE node_net_bonding_slaves_active gauge
node_net_bonding_slaves_active{master="bond0"} 0
node_net_bonding_slaves_active{master="dmz"} 2
node_net_bonding_slaves_active{master="int"} 1
# HELP node_netstat_IcmpMsg_InType3 Protocol IcmpMsg statistic InType3. # HELP node_netstat_IcmpMsg_InType3 Protocol IcmpMsg statistic InType3.
# TYPE node_netstat_IcmpMsg_InType3 untyped # TYPE node_netstat_IcmpMsg_InType3 untyped
node_netstat_IcmpMsg_InType3 104 node_netstat_IcmpMsg_InType3 104
@ -2048,14 +2058,14 @@ node_sockstat_UDP_mem_bytes 0
node_sockstat_sockets_used 229 node_sockstat_sockets_used 229
# HELP node_textfile_mtime Unixtime mtime of textfiles successfully read. # HELP node_textfile_mtime Unixtime mtime of textfiles successfully read.
# TYPE node_textfile_mtime gauge # TYPE node_textfile_mtime gauge
node_textfile_mtime{file="metrics1.prom"} 1.463773694e+09 node_textfile_mtime{file="metrics1.prom"} 1.4611075321691382e+09
node_textfile_mtime{file="metrics2.prom"} 1.463773694e+09 node_textfile_mtime{file="metrics2.prom"} 1.4611075321691382e+09
# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise # HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
# TYPE node_textfile_scrape_error gauge # TYPE node_textfile_scrape_error gauge
node_textfile_scrape_error 0 node_textfile_scrape_error 0
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter # TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0 process_cpu_seconds_total 0.02
# HELP process_max_fds Maximum number of open file descriptors. # HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge # TYPE process_max_fds gauge
process_max_fds 1024 process_max_fds 1024
@ -2064,13 +2074,13 @@ process_max_fds 1024
process_open_fds 8 process_open_fds 8
# HELP process_resident_memory_bytes Resident memory size in bytes. # HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge # TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.1108352e+07 process_resident_memory_bytes 1.1751424e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge # TYPE process_start_time_seconds gauge
process_start_time_seconds 1.47509459587e+09 process_start_time_seconds 1.48293316896e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes. # HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge # TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2.0549632e+08 process_virtual_memory_bytes 2.7445248e+08
# HELP testmetric1_1 Metric read from collector/fixtures/textfile/two_metric_files/metrics1.prom # HELP testmetric1_1 Metric read from collector/fixtures/textfile/two_metric_files/metrics1.prom
# TYPE testmetric1_1 untyped # TYPE testmetric1_1 untyped
testmetric1_1{foo="bar"} 10 testmetric1_1{foo="bar"} 10

View file

@ -19,7 +19,7 @@ package collector
import "github.com/prometheus/client_golang/prometheus" import "github.com/prometheus/client_golang/prometheus"
type interruptsCollector struct { type interruptsCollector struct {
metric *prometheus.CounterVec desc typedDesc
} }
func init() { func init() {
@ -30,13 +30,10 @@ func init() {
// interrupts stats // interrupts stats
func NewInterruptsCollector() (Collector, error) { func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{ return &interruptsCollector{
metric: prometheus.NewCounterVec( desc: typedDesc{prometheus.NewDesc(
prometheus.CounterOpts{ Namespace+"_interrupts",
Namespace: Namespace, "Interrupt details.",
Name: "interrupts", interruptLabelNames, nil,
Help: "Interrupt details.", ), prometheus.CounterValue},
},
interruptLabelNames,
),
}, nil }, nil
} }

View file

@ -42,16 +42,9 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) {
if err != nil { if err != nil {
return fmt.Errorf("invalid value %s in interrupts: %s", value, err) return fmt.Errorf("invalid value %s in interrupts: %s", value, err)
} }
labels := prometheus.Labels{ ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices)
"CPU": strconv.Itoa(cpuNo),
"type": name,
"info": interrupt.info,
"devices": interrupt.devices,
}
c.metric.With(labels).Set(fv)
} }
} }
c.metric.Collect(ch)
return err return err
} }

View file

@ -98,23 +98,22 @@ var (
interruptLabelNames = []string{"CPU", "type", "devices"} interruptLabelNames = []string{"CPU", "type", "devices"}
) )
func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error {
interrupts, err := getInterrupts() interrupts, err := getInterrupts()
if err != nil { if err != nil {
return fmt.Errorf("couldn't get interrupts: %s", err) return fmt.Errorf("couldn't get interrupts: %s", err)
} }
for dev, interrupt := range interrupts { for dev, interrupt := range interrupts {
for cpuNo, value := range interrupt.values { for cpuNo, value := range interrupt.values {
labels := prometheus.Labels{ ch <- c.desc.mustNewConstMetric(
"CPU": strconv.Itoa(cpuNo), value,
"type": fmt.Sprintf("%d", interrupt.vector), strconv.Itoa(cpuNo),
"devices": dev, fmt.Sprintf("%d", interrupt.vector),
} dev,
c.metric.With(labels).Set(value) )
} }
} }
c.metric.Collect(ch) return nil
return err
} }
type interrupt struct { type interrupt struct {

View file

@ -26,8 +26,8 @@ import (
type ipvsCollector struct { type ipvsCollector struct {
Collector Collector
fs procfs.FS fs procfs.FS
backendConnectionsActive, backendConnectionsInact, backendWeight *prometheus.GaugeVec backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc
connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes prometheus.Counter connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc
} }
func init() { func init() {
@ -59,74 +59,46 @@ func newIPVSCollector() (*ipvsCollector, error) {
return nil, err return nil, err
} }
c.connections = prometheus.NewCounter( c.connections = typedDesc{prometheus.NewDesc(
prometheus.CounterOpts{ prometheus.BuildFQName(Namespace, subsystem, "connections_total"),
Namespace: Namespace, "The total number of connections made.",
Subsystem: subsystem, nil, nil,
Name: "connections_total", ), prometheus.CounterValue}
Help: "The total number of connections made.", c.incomingPackets = typedDesc{prometheus.NewDesc(
}, prometheus.BuildFQName(Namespace, subsystem, "incoming_packets_total"),
) "The total number of incoming packets.",
c.incomingPackets = prometheus.NewCounter( nil, nil,
prometheus.CounterOpts{ ), prometheus.CounterValue}
Namespace: Namespace, c.outgoingPackets = typedDesc{prometheus.NewDesc(
Subsystem: subsystem, prometheus.BuildFQName(Namespace, subsystem, "outgoing_packets_total"),
Name: "incoming_packets_total", "The total number of outgoing packets.",
Help: "The total number of incoming packets.", nil, nil,
}, ), prometheus.CounterValue}
) c.incomingBytes = typedDesc{prometheus.NewDesc(
c.outgoingPackets = prometheus.NewCounter( prometheus.BuildFQName(Namespace, subsystem, "incoming_bytes_total"),
prometheus.CounterOpts{ "The total amount of incoming data.",
Namespace: Namespace, nil, nil,
Subsystem: subsystem, ), prometheus.CounterValue}
Name: "outgoing_packets_total", c.outgoingBytes = typedDesc{prometheus.NewDesc(
Help: "The total number of outgoing packets.", prometheus.BuildFQName(Namespace, subsystem, "outgoing_bytes_total"),
}, "The total amount of outgoing data.",
) nil, nil,
c.incomingBytes = prometheus.NewCounter( ), prometheus.CounterValue}
prometheus.CounterOpts{ c.backendConnectionsActive = typedDesc{prometheus.NewDesc(
Namespace: Namespace, prometheus.BuildFQName(Namespace, subsystem, "backend_connections_active"),
Subsystem: subsystem, "The current active connections by local and remote address.",
Name: "incoming_bytes_total", ipvsBackendLabelNames, nil,
Help: "The total amount of incoming data.", ), prometheus.GaugeValue}
}, c.backendConnectionsInact = typedDesc{prometheus.NewDesc(
) prometheus.BuildFQName(Namespace, subsystem, "backend_connections_inactive"),
c.outgoingBytes = prometheus.NewCounter( "The current inactive connections by local and remote address.",
prometheus.CounterOpts{ ipvsBackendLabelNames, nil,
Namespace: Namespace, ), prometheus.GaugeValue}
Subsystem: subsystem, c.backendWeight = typedDesc{prometheus.NewDesc(
Name: "outgoing_bytes_total", prometheus.BuildFQName(Namespace, subsystem, "backend_weight"),
Help: "The total amount of outgoing data.", "The current backend weight by local and remote address.",
}, ipvsBackendLabelNames, nil,
) ), prometheus.GaugeValue}
c.backendConnectionsActive = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: subsystem,
Name: "backend_connections_active",
Help: "The current active connections by local and remote address.",
},
ipvsBackendLabelNames,
)
c.backendConnectionsInact = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: subsystem,
Name: "backend_connections_inactive",
Help: "The current inactive connections by local and remote address.",
},
ipvsBackendLabelNames,
)
c.backendWeight = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: subsystem,
Name: "backend_weight",
Help: "The current backend weight by local and remote address.",
},
ipvsBackendLabelNames,
)
return &c, nil return &c, nil
} }
@ -136,18 +108,11 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil { if err != nil {
return fmt.Errorf("could not get IPVS stats: %s", err) return fmt.Errorf("could not get IPVS stats: %s", err)
} }
ch <- c.connections.mustNewConstMetric(float64(ipvsStats.Connections))
c.connections.Set(float64(ipvsStats.Connections)) ch <- c.incomingPackets.mustNewConstMetric(float64(ipvsStats.IncomingPackets))
c.incomingPackets.Set(float64(ipvsStats.IncomingPackets)) ch <- c.outgoingPackets.mustNewConstMetric(float64(ipvsStats.OutgoingPackets))
c.outgoingPackets.Set(float64(ipvsStats.OutgoingPackets)) ch <- c.incomingBytes.mustNewConstMetric(float64(ipvsStats.IncomingBytes))
c.incomingBytes.Set(float64(ipvsStats.IncomingBytes)) ch <- c.outgoingBytes.mustNewConstMetric(float64(ipvsStats.OutgoingBytes))
c.outgoingBytes.Set(float64(ipvsStats.OutgoingBytes))
c.connections.Collect(ch)
c.incomingPackets.Collect(ch)
c.outgoingPackets.Collect(ch)
c.incomingBytes.Collect(ch)
c.outgoingBytes.Collect(ch)
backendStats, err := c.fs.NewIPVSBackendStatus() backendStats, err := c.fs.NewIPVSBackendStatus()
if err != nil { if err != nil {
@ -162,14 +127,9 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
strconv.FormatUint(uint64(backend.RemotePort), 10), strconv.FormatUint(uint64(backend.RemotePort), 10),
backend.Proto, backend.Proto,
} }
c.backendConnectionsActive.WithLabelValues(labelValues...).Set(float64(backend.ActiveConn)) ch <- c.backendConnectionsActive.mustNewConstMetric(float64(backend.ActiveConn), labelValues...)
c.backendConnectionsInact.WithLabelValues(labelValues...).Set(float64(backend.InactConn)) ch <- c.backendConnectionsInact.mustNewConstMetric(float64(backend.InactConn), labelValues...)
c.backendWeight.WithLabelValues(labelValues...).Set(float64(backend.Weight)) ch <- c.backendWeight.mustNewConstMetric(float64(backend.Weight), labelValues...)
} }
c.backendConnectionsActive.Collect(ch)
c.backendConnectionsInact.Collect(ch)
c.backendWeight.Collect(ch)
return nil return nil
} }

View file

@ -19,7 +19,6 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strconv"
"strings" "strings"
"testing" "testing"
@ -129,36 +128,23 @@ func TestIPVSCollector(t *testing.T) {
} }
sink := make(chan prometheus.Metric) sink := make(chan prometheus.Metric)
go func() { go func() {
for {
<-sink
}
}()
err = collector.Update(sink) err = collector.Update(sink)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
}()
for _, expect := range expectedIPVSBackendStatuses { for expected, got := range map[string]string{
labels := prometheus.Labels{ prometheus.NewDesc("node_ipvs_connections_total", "The total number of connections made.", nil, nil).String(): (<-sink).Desc().String(),
"local_address": expect.LocalAddress.String(), prometheus.NewDesc("node_ipvs_incoming_packets_total", "The total number of incoming packets.", nil, nil).String(): (<-sink).Desc().String(),
"local_port": strconv.FormatUint(uint64(expect.LocalPort), 10), prometheus.NewDesc("node_ipvs_outgoing_packets_total", "The total number of outgoing packets.", nil, nil).String(): (<-sink).Desc().String(),
"remote_address": expect.RemoteAddress.String(), prometheus.NewDesc("node_ipvs_incoming_bytes_total", "The total amount of incoming data.", nil, nil).String(): (<-sink).Desc().String(),
"remote_port": strconv.FormatUint(uint64(expect.RemotePort), 10), prometheus.NewDesc("node_ipvs_outgoing_bytes_total", "The total amount of outgoing data.", nil, nil).String(): (<-sink).Desc().String(),
"proto": expect.Proto, prometheus.NewDesc("node_ipvs_backend_connections_active", "The current active connections by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
} prometheus.NewDesc("node_ipvs_backend_connections_inactive", "The current inactive connections by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
// TODO: Pending prometheus/client_golang#58, check the actual numbers prometheus.NewDesc("node_ipvs_backend_weight", "The current backend weight by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
_, err = collector.backendConnectionsActive.GetMetricWith(labels) } {
if err != nil { if expected != got {
t.Errorf("Missing active connections metric for label combination: %+v", labels) t.Fatalf("Expected '%s' but got '%s'", expected, got)
}
_, err = collector.backendConnectionsInact.GetMetricWith(labels)
if err != nil {
t.Errorf("Missing inactive connections metric for label combination: %+v", labels)
}
_, err = collector.backendWeight.GetMetricWith(labels)
if err != nil {
t.Errorf("Missing weight metric for label combination: %+v", labels)
} }
} }
} }

View file

@ -24,7 +24,7 @@ import (
) )
type loadavgCollector struct { type loadavgCollector struct {
metric []prometheus.Gauge metric []typedDesc
} }
func init() { func init() {
@ -34,22 +34,10 @@ func init() {
// Take a prometheus registry and return a new Collector exposing load average. // Take a prometheus registry and return a new Collector exposing load average.
func NewLoadavgCollector() (Collector, error) { func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{ return &loadavgCollector{
metric: []prometheus.Gauge{ metric: []typedDesc{
prometheus.NewGauge(prometheus.GaugeOpts{ {prometheus.NewDesc(Namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
Namespace: Namespace, {prometheus.NewDesc(Namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue},
Name: "load1", {prometheus.NewDesc(Namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue},
Help: "1m load average.",
}),
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load5",
Help: "5m load average.",
}),
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load15",
Help: "15m load average.",
}),
}, },
}, nil }, nil
} }
@ -60,9 +48,8 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
return fmt.Errorf("couldn't get load: %s", err) return fmt.Errorf("couldn't get load: %s", err)
} }
for i, load := range loads { for i, load := range loads {
log.Debugf("Set load %d: %f", i, load) log.Debugf("return load %d: %f", i, load)
c.metric[i].Set(load) ch <- c.metric[i].mustNewConstMetric(load)
c.metric[i].Collect(ch)
} }
return err return err
} }

View file

@ -30,8 +30,7 @@ var (
) )
type ntpCollector struct { type ntpCollector struct {
drift prometheus.Gauge drift, stratum typedDesc
stratum prometheus.Gauge
} }
func init() { func init() {
@ -50,16 +49,16 @@ func NewNtpCollector() (Collector, error) {
} }
return &ntpCollector{ return &ntpCollector{
drift: prometheus.NewGauge(prometheus.GaugeOpts{ drift: typedDesc{prometheus.NewDesc(
Namespace: Namespace, prometheus.BuildFQName(Namespace, "ntp", "drift_seconds"),
Name: "ntp_drift_seconds", "Time between system time and ntp time.",
Help: "Time between system time and ntp time.", nil, nil,
}), ), prometheus.GaugeValue},
stratum: prometheus.NewGauge(prometheus.GaugeOpts{ stratum: typedDesc{prometheus.NewDesc(
Namespace: Namespace, prometheus.BuildFQName(Namespace, "ntp", "stratum"),
Name: "ntp_stratum", "NTP server stratum.",
Help: "NTP server stratum.", nil, nil,
}), ), prometheus.GaugeValue},
}, nil }, nil
} }
@ -70,12 +69,10 @@ func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) {
} }
driftSeconds := resp.ClockOffset.Seconds() driftSeconds := resp.ClockOffset.Seconds()
log.Debugf("Set ntp_drift_seconds: %f", driftSeconds) log.Debugf("Set ntp_drift_seconds: %f", driftSeconds)
c.drift.Set(driftSeconds) ch <- c.drift.mustNewConstMetric(driftSeconds)
c.drift.Collect(ch)
stratum := float64(resp.Stratum) stratum := float64(resp.Stratum)
log.Debugf("Set ntp_stratum: %f", stratum) log.Debugf("Set ntp_stratum: %f", stratum)
c.stratum.Set(stratum) ch <- c.stratum.mustNewConstMetric(stratum)
c.stratum.Collect(ch)
return nil return nil
} }

View file

@ -29,7 +29,7 @@ var runitServiceDir = flag.String(
"Path to runit service directory.") "Path to runit service directory.")
type runitCollector struct { type runitCollector struct {
state, stateDesired, stateNormal, stateTimestamp *prometheus.GaugeVec state, stateDesired, stateNormal, stateTimestamp typedDesc
} }
func init() { func init() {
@ -44,46 +44,26 @@ func NewRunitCollector() (Collector, error) {
) )
return &runitCollector{ return &runitCollector{
state: prometheus.NewGaugeVec( state: typedDesc{prometheus.NewDesc(
prometheus.GaugeOpts{ prometheus.BuildFQName(Namespace, subsystem, "state"),
Namespace: Namespace, "State of runit service.",
Subsystem: subsystem, labelNames, constLabels,
Name: "state", ), prometheus.GaugeValue},
Help: "State of runit service.", stateDesired: typedDesc{prometheus.NewDesc(
ConstLabels: constLabels, prometheus.BuildFQName(Namespace, subsystem, "desired_state"),
}, "Desired state of runit service.",
labelNames, labelNames, constLabels,
), ), prometheus.GaugeValue},
stateDesired: prometheus.NewGaugeVec( stateNormal: typedDesc{prometheus.NewDesc(
prometheus.GaugeOpts{ prometheus.BuildFQName(Namespace, subsystem, "normal_state"),
Namespace: Namespace, "Normal state of runit service.",
Subsystem: subsystem, labelNames, constLabels,
Name: "desired_state", ), prometheus.GaugeValue},
Help: "Desired state of runit service.", stateTimestamp: typedDesc{prometheus.NewDesc(
ConstLabels: constLabels, prometheus.BuildFQName(Namespace, subsystem, "state_last_change_timestamp_seconds"),
}, "Unix timestamp of the last runit service state change.",
labelNames, labelNames, constLabels,
), ), prometheus.GaugeValue},
stateNormal: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: subsystem,
Name: "normal_state",
Help: "Normal state of runit service.",
ConstLabels: constLabels,
},
labelNames,
),
stateTimestamp: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: subsystem,
Name: "state_last_change_timestamp_seconds",
Help: "Unix timestamp of the last runit service state change.",
ConstLabels: constLabels,
},
labelNames,
),
}, nil }, nil
} }
@ -101,19 +81,14 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
} }
log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration) log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
c.state.WithLabelValues(service.Name).Set(float64(status.State)) ch <- c.state.mustNewConstMetric(float64(status.State), service.Name)
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want)) ch <- c.stateDesired.mustNewConstMetric(float64(status.Want), service.Name)
c.stateTimestamp.WithLabelValues(service.Name).Set(float64(status.Timestamp.Unix())) ch <- c.stateTimestamp.mustNewConstMetric(float64(status.Timestamp.Unix()), service.Name)
if status.NormallyUp { if status.NormallyUp {
c.stateNormal.WithLabelValues(service.Name).Set(1) ch <- c.stateNormal.mustNewConstMetric(1, service.Name)
} else { } else {
c.stateNormal.WithLabelValues(service.Name).Set(0) ch <- c.stateNormal.mustNewConstMetric(0, service.Name)
} }
} }
c.state.Collect(ch)
c.stateDesired.Collect(ch)
c.stateNormal.Collect(ch)
c.stateTimestamp.Collect(ch)
return nil return nil
} }

View file

@ -43,7 +43,7 @@ const (
) )
type tcpStatCollector struct { type tcpStatCollector struct {
metric *prometheus.GaugeVec desc typedDesc
} }
func init() { func init() {
@ -54,14 +54,11 @@ func init() {
// a new Collector exposing network stats. // a new Collector exposing network stats.
func NewTCPStatCollector() (Collector, error) { func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{ return &tcpStatCollector{
metric: prometheus.NewGaugeVec( desc: typedDesc{prometheus.NewDesc(
prometheus.GaugeOpts{ prometheus.BuildFQName(Namespace, "tcp", "connection_states"),
Namespace: Namespace, "Number of connection states.",
Name: "tcp_connection_states", []string{"state"}, nil,
Help: "Number of connection states.", ), prometheus.GaugeValue},
},
[]string{"state"},
),
}, nil }, nil
} }
@ -85,10 +82,8 @@ func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
} }
for st, value := range tcpStats { for st, value := range tcpStats {
c.metric.WithLabelValues(st.String()).Set(value) ch <- c.desc.mustNewConstMetric(value, st.String())
} }
c.metric.Collect(ch)
return err return err
} }

View file

@ -23,7 +23,7 @@ import (
) )
type timeCollector struct { type timeCollector struct {
metric prometheus.Counter desc *prometheus.Desc
} }
func init() { func init() {
@ -34,18 +34,17 @@ func init() {
// the current system time in seconds since epoch. // the current system time in seconds since epoch.
func NewTimeCollector() (Collector, error) { func NewTimeCollector() (Collector, error) {
return &timeCollector{ return &timeCollector{
metric: prometheus.NewCounter(prometheus.CounterOpts{ desc: prometheus.NewDesc(
Namespace: Namespace, Namespace+"_time",
Name: "time", "System time in seconds since epoch (1970).",
Help: "System time in seconds since epoch (1970).", nil, nil,
}), ),
}, nil }, nil
} }
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) { func (c *timeCollector) Update(ch chan<- prometheus.Metric) error {
now := float64(time.Now().Unix()) now := float64(time.Now().Unix())
log.Debugf("Set time: %f", now) log.Debugf("Return time: %f", now)
c.metric.Set(now) ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, now)
c.metric.Collect(ch) return nil
return err
} }

View file

@ -56,14 +56,14 @@ func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
return err return err
} }
metric := prometheus.NewUntyped(prometheus.UntypedOpts{ ch <- prometheus.MustNewConstMetric(
Namespace: Namespace, prometheus.NewDesc(
Subsystem: vmStatSubsystem, prometheus.BuildFQName(Namespace, vmStatSubsystem, parts[0]),
Name: parts[0], fmt.Sprintf("/proc/vmstat information field %s.", parts[0]),
Help: fmt.Sprintf("/proc/vmstat information field %s.", parts[0]), nil, nil),
}) prometheus.UntypedValue,
metric.Set(value) value,
metric.Collect(ch) )
} }
return err return err
} }