mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-26 14:46:35 +00:00
Use perflib for logical_disk collector
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
@@ -27,7 +26,7 @@ var (
|
|||||||
).Default("").String()
|
).Default("").String()
|
||||||
)
|
)
|
||||||
|
|
||||||
// A LogicalDiskCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfDisk_LogicalDisk metrics
|
// A LogicalDiskCollector is a Prometheus collector for perflib logicalDisk metrics
|
||||||
type LogicalDiskCollector struct {
|
type LogicalDiskCollector struct {
|
||||||
RequestsQueued *prometheus.Desc
|
RequestsQueued *prometheus.Desc
|
||||||
ReadBytesTotal *prometheus.Desc
|
ReadBytesTotal *prometheus.Desc
|
||||||
@@ -159,7 +158,7 @@ func NewLogicalDiskCollector() (Collector, error) {
|
|||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *LogicalDiskCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *LogicalDiskCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if desc, err := c.collect(ch); err != nil {
|
if desc, err := c.collect(ctx, ch); err != nil {
|
||||||
log.Error("failed collecting logical_disk metrics:", desc, err)
|
log.Error("failed collecting logical_disk metrics:", desc, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -169,28 +168,27 @@ func (c *LogicalDiskCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.
|
|||||||
// Win32_PerfRawData_PerfDisk_LogicalDisk docs:
|
// Win32_PerfRawData_PerfDisk_LogicalDisk docs:
|
||||||
// - https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
|
// - https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
|
||||||
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference
|
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference
|
||||||
type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
|
type logicalDisk struct {
|
||||||
Name string
|
Name string
|
||||||
CurrentDiskQueueLength uint32
|
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
|
||||||
DiskReadBytesPerSec uint64
|
DiskReadBytesPerSec float64 `perflib:"Disk Read Bytes/sec"`
|
||||||
DiskReadsPerSec uint32
|
DiskReadsPerSec float64 `perflib:"Disk Reads/sec"`
|
||||||
DiskWriteBytesPerSec uint64
|
DiskWriteBytesPerSec float64 `perflib:"Disk Write Bytes/sec"`
|
||||||
DiskWritesPerSec uint32
|
DiskWritesPerSec float64 `perflib:"Disk Writes/sec"`
|
||||||
PercentDiskReadTime uint64
|
PercentDiskReadTime float64 `perflib:"% Disk Read Time"`
|
||||||
PercentDiskWriteTime uint64
|
PercentDiskWriteTime float64 `perflib:"% Disk Write Time"`
|
||||||
PercentFreeSpace uint32
|
PercentFreeSpace float64 `perflib:"% Free Space_Base"`
|
||||||
PercentFreeSpace_Base uint32
|
PercentFreeSpace_Base float64 `perflib:"Free Megabytes"`
|
||||||
PercentIdleTime uint64
|
PercentIdleTime float64 `perflib:"% Idle Time"`
|
||||||
SplitIOPerSec uint32
|
SplitIOPerSec float64 `perflib:"Split IO/Sec"`
|
||||||
AvgDiskSecPerRead uint64
|
AvgDiskSecPerRead float64 `perflib:"Avg. Disk sec/Read"`
|
||||||
AvgDiskSecPerWrite uint64
|
AvgDiskSecPerWrite float64 `perflib:"Avg. Disk sec/Write"`
|
||||||
AvgDiskSecPerTransfer uint64
|
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *LogicalDiskCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
|
var dst []logicalDisk
|
||||||
q := queryAll(&dst)
|
if err := unmarshalObject(ctx.perfObjects["LogicalDisk"], &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,98 +202,98 @@ func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus
|
|||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestsQueued,
|
c.RequestsQueued,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(volume.CurrentDiskQueueLength),
|
volume.CurrentDiskQueueLength,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadBytesTotal,
|
c.ReadBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.DiskReadBytesPerSec),
|
volume.DiskReadBytesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadsTotal,
|
c.ReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.DiskReadsPerSec),
|
volume.DiskReadsPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteBytesTotal,
|
c.WriteBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.DiskWriteBytesPerSec),
|
volume.DiskWriteBytesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WritesTotal,
|
c.WritesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.DiskWritesPerSec),
|
volume.DiskWritesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadTime,
|
c.ReadTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.PercentDiskReadTime)*ticksToSecondsScaleFactor,
|
volume.PercentDiskReadTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteTime,
|
c.WriteTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.PercentDiskWriteTime)*ticksToSecondsScaleFactor,
|
volume.PercentDiskWriteTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeSpace,
|
c.FreeSpace,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(volume.PercentFreeSpace)*1024*1024,
|
volume.PercentFreeSpace_Base*1024*1024,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalSpace,
|
c.TotalSpace,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(volume.PercentFreeSpace_Base)*1024*1024,
|
volume.PercentFreeSpace*1024*1024,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IdleTime,
|
c.IdleTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.PercentIdleTime)*ticksToSecondsScaleFactor,
|
volume.PercentIdleTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SplitIOs,
|
c.SplitIOs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.SplitIOPerSec),
|
volume.SplitIOPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadLatency,
|
c.ReadLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.AvgDiskSecPerRead),
|
volume.AvgDiskSecPerRead,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteLatency,
|
c.WriteLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.AvgDiskSecPerWrite),
|
volume.AvgDiskSecPerWrite,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadWriteLatency,
|
c.ReadWriteLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(volume.AvgDiskSecPerTransfer),
|
volume.AvgDiskSecPerTransfer,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user