mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-26 22:19:44 -08:00
Add diskstats collector for OpenBSD (#1250)
* Add diskstats collector for OpenBSD Tested on i386 and amd64, OpenBSD 6.4 and -current. * Refactor diskstats collectors This moves common descriptors from Linux, Darwin, OpenBSD diskstats collectors into diskstats_common.go Signed-off-by: Ralf Horstmann <ralf+github@ackstorm.de>
This commit is contained in:
parent
d442108d7a
commit
3867ad5ab0
|
@ -15,6 +15,7 @@ The cpufreq metrics now separate the `cpufreq` and `scaling` data based on what
|
||||||
* [FEATURE] Add a flag to disable exporter metrics #1148
|
* [FEATURE] Add a flag to disable exporter metrics #1148
|
||||||
* [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197
|
* [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197
|
||||||
* [FEATURE] Add uname collector for FreeBSD #1239
|
* [FEATURE] Add uname collector for FreeBSD #1239
|
||||||
|
* [FEATURE] Add diskstats collector for OpenBSD #1250
|
||||||
|
|
||||||
## 0.17.0 / 2018-11-30
|
## 0.17.0 / 2018-11-30
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ bonding | Exposes the number of configured and active slaves of Linux bonding in
|
||||||
boottime | Exposes system boot time derived from the `kern.boottime` sysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD, Solaris
|
boottime | Exposes system boot time derived from the `kern.boottime` sysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD, Solaris
|
||||||
conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfilter/` present). | Linux
|
conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfilter/` present). | Linux
|
||||||
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux, Solaris
|
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux, Solaris
|
||||||
diskstats | Exposes disk I/O statistics. | Darwin, Linux
|
diskstats | Exposes disk I/O statistics. | Darwin, Linux, OpenBSD
|
||||||
edac | Exposes error detection and correction statistics. | Linux
|
edac | Exposes error detection and correction statistics. | Linux
|
||||||
entropy | Exposes available entropy. | Linux
|
entropy | Exposes available entropy. | Linux
|
||||||
exec | Exposes execution statistics. | Dragonfly, FreeBSD
|
exec | Exposes execution statistics. | Dragonfly, FreeBSD
|
||||||
|
|
73
collector/diskstats_common.go
Normal file
73
collector/diskstats_common.go
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
// Copyright 2019 The Prometheus Authors
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !nodiskstats
|
||||||
|
// +build openbsd linux darwin
|
||||||
|
|
||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
diskSubsystem = "disk"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
diskLabelNames = []string{"device"}
|
||||||
|
|
||||||
|
readsCompletedDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "reads_completed_total"),
|
||||||
|
"The total number of reads completed successfully.",
|
||||||
|
diskLabelNames, nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
readBytesDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "read_bytes_total"),
|
||||||
|
"The total number of bytes read successfully.",
|
||||||
|
diskLabelNames, nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
writesCompletedDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "writes_completed_total"),
|
||||||
|
"The total number of writes completed successfully.",
|
||||||
|
diskLabelNames, nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
writtenBytesDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "written_bytes_total"),
|
||||||
|
"The total number of bytes written successfully.",
|
||||||
|
diskLabelNames, nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
ioTimeSecondsDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "io_time_seconds_total"),
|
||||||
|
"Total seconds spent doing I/Os.",
|
||||||
|
diskLabelNames, nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
readTimeSecondsDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "read_time_seconds_total"),
|
||||||
|
"The total number of seconds spent by all reads.",
|
||||||
|
diskLabelNames,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
writeTimeSecondsDesc = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, diskSubsystem, "write_time_seconds_total"),
|
||||||
|
"This is the total number of seconds spent by all writes.",
|
||||||
|
diskLabelNames,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
)
|
|
@ -22,10 +22,6 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
diskSubsystem = "disk"
|
|
||||||
)
|
|
||||||
|
|
||||||
type typedDescFunc struct {
|
type typedDescFunc struct {
|
||||||
typedDesc
|
typedDesc
|
||||||
value func(stat *iostat.DriveStats) float64
|
value func(stat *iostat.DriveStats) float64
|
||||||
|
@ -47,12 +43,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
descs: []typedDescFunc{
|
descs: []typedDescFunc{
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: readsCompletedDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "reads_completed_total"),
|
|
||||||
"The total number of reads completed successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
@ -75,12 +66,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: readTimeSecondsDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "read_time_seconds_total"),
|
|
||||||
"The total number of seconds spent by all reads.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
@ -89,12 +75,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: writesCompletedDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "writes_completed_total"),
|
|
||||||
"The total number of writes completed successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
@ -117,12 +98,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: writeTimeSecondsDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "write_time_seconds_total"),
|
|
||||||
"This is the total number of seconds spent by all writes.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
@ -131,12 +107,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: readBytesDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "read_bytes_total"),
|
|
||||||
"The total number of bytes read successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
@ -145,12 +116,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
typedDesc: typedDesc{
|
typedDesc: typedDesc{
|
||||||
desc: prometheus.NewDesc(
|
desc: writtenBytesDesc,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "written_bytes_total"),
|
|
||||||
"The total number of bytes written successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
),
|
|
||||||
valueType: prometheus.CounterValue,
|
valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
value: func(stat *iostat.DriveStats) float64 {
|
value: func(stat *iostat.DriveStats) float64 {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
diskSubsystem = "disk"
|
|
||||||
diskSectorSize = 512
|
diskSectorSize = 512
|
||||||
diskstatsFilename = "diskstats"
|
diskstatsFilename = "diskstats"
|
||||||
)
|
)
|
||||||
|
@ -70,12 +69,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices),
|
ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices),
|
||||||
descs: []typedFactorDesc{
|
descs: []typedFactorDesc{
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: readsCompletedDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "reads_completed_total"),
|
|
||||||
"The total number of reads completed successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: prometheus.NewDesc(
|
||||||
|
@ -86,30 +80,15 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
), valueType: prometheus.CounterValue,
|
), valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: readBytesDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "read_bytes_total"),
|
|
||||||
"The total number of bytes read successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
factor: diskSectorSize,
|
factor: diskSectorSize,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: readTimeSecondsDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "read_time_seconds_total"),
|
|
||||||
"The total number of seconds spent by all reads.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
factor: .001,
|
factor: .001,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: writesCompletedDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "writes_completed_total"),
|
|
||||||
"The total number of writes completed successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: prometheus.NewDesc(
|
||||||
|
@ -120,21 +99,11 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
), valueType: prometheus.CounterValue,
|
), valueType: prometheus.CounterValue,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: writtenBytesDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "written_bytes_total"),
|
|
||||||
"The total number of bytes written successfully.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
factor: diskSectorSize,
|
factor: diskSectorSize,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: writeTimeSecondsDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "write_time_seconds_total"),
|
|
||||||
"This is the total number of seconds spent by all writes.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
factor: .001,
|
factor: .001,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -146,12 +115,7 @@ func NewDiskstatsCollector() (Collector, error) {
|
||||||
), valueType: prometheus.GaugeValue,
|
), valueType: prometheus.GaugeValue,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: prometheus.NewDesc(
|
desc: ioTimeSecondsDesc, valueType: prometheus.CounterValue,
|
||||||
prometheus.BuildFQName(namespace, diskSubsystem, "io_time_seconds_total"),
|
|
||||||
"Total seconds spent doing I/Os.",
|
|
||||||
diskLabelNames,
|
|
||||||
nil,
|
|
||||||
), valueType: prometheus.CounterValue,
|
|
||||||
factor: .001,
|
factor: .001,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
74
collector/diskstats_openbsd.go
Normal file
74
collector/diskstats_openbsd.go
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// Copyright 2019 The Prometheus Authors
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !nodiskstats
|
||||||
|
|
||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/disk.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
type diskstatsCollector struct {
|
||||||
|
rxfer typedDesc
|
||||||
|
rbytes typedDesc
|
||||||
|
wxfer typedDesc
|
||||||
|
wbytes typedDesc
|
||||||
|
time typedDesc
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||||
|
func NewDiskstatsCollector() (Collector, error) {
|
||||||
|
return &diskstatsCollector{
|
||||||
|
rxfer: typedDesc{readsCompletedDesc, prometheus.CounterValue},
|
||||||
|
rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
|
||||||
|
wxfer: typedDesc{writesCompletedDesc, prometheus.CounterValue},
|
||||||
|
wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
|
||||||
|
time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
|
diskstatsb, err := unix.SysctlRaw("hw.diskstats")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ndisks := len(diskstatsb) / C.sizeof_struct_diskstats
|
||||||
|
diskstats := *(*[]C.struct_diskstats)(unsafe.Pointer(&diskstatsb))
|
||||||
|
|
||||||
|
for i := 0; i < ndisks; i++ {
|
||||||
|
diskname := C.GoString(&diskstats[i].ds_name[0])
|
||||||
|
|
||||||
|
ch <- c.rxfer.mustNewConstMetric(float64(diskstats[i].ds_rxfer), diskname)
|
||||||
|
ch <- c.rbytes.mustNewConstMetric(float64(diskstats[i].ds_rbytes), diskname)
|
||||||
|
ch <- c.wxfer.mustNewConstMetric(float64(diskstats[i].ds_wxfer), diskname)
|
||||||
|
ch <- c.wbytes.mustNewConstMetric(float64(diskstats[i].ds_wbytes), diskname)
|
||||||
|
time := float64(diskstats[i].ds_time.tv_sec) + float64(diskstats[i].ds_time.tv_usec)/1000000
|
||||||
|
ch <- c.time.mustNewConstMetric(time, diskname)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue