mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 14:06:38 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3072bb4f3 | ||
|
|
17072bf257 | ||
|
|
d3d8537201 | ||
|
|
2951a9ef80 | ||
|
|
3141fc3ed3 |
@@ -92,6 +92,22 @@ type HyperVCollector struct {
|
||||
AdapterFramesDropped *prometheus.Desc
|
||||
AdapterFramesReceived *prometheus.Desc
|
||||
AdapterFramesSent *prometheus.Desc
|
||||
|
||||
// Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||
VMStorageErrorCount *prometheus.Desc
|
||||
VMStorageQueueLength *prometheus.Desc
|
||||
VMStorageReadBytes *prometheus.Desc
|
||||
VMStorageReadOperations *prometheus.Desc
|
||||
VMStorageWriteBytes *prometheus.Desc
|
||||
VMStorageWriteOperations *prometheus.Desc
|
||||
|
||||
// Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
||||
VMNetworkBytesReceived *prometheus.Desc
|
||||
VMNetworkBytesSent *prometheus.Desc
|
||||
VMNetworkDroppedPacketsIncoming *prometheus.Desc
|
||||
VMNetworkDroppedPacketsOutgoing *prometheus.Desc
|
||||
VMNetworkPacketsReceived *prometheus.Desc
|
||||
VMNetworkPacketsSent *prometheus.Desc
|
||||
}
|
||||
|
||||
// NewHyperVCollector ...
|
||||
@@ -496,6 +512,84 @@ func NewHyperVCollector() (Collector, error) {
|
||||
[]string{"adapter"},
|
||||
nil,
|
||||
),
|
||||
|
||||
//
|
||||
|
||||
VMStorageErrorCount: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "error_count"),
|
||||
"This counter represents the total number of errors that have occurred on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
VMStorageQueueLength: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "queue_length"),
|
||||
"This counter represents the current queue length on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
VMStorageReadBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "bytes_read"),
|
||||
"This counter represents the total number of bytes that have been read per second on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
VMStorageReadOperations: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "operations_read"),
|
||||
"This counter represents the number of read operations that have occurred per second on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
VMStorageWriteBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "bytes_written"),
|
||||
"This counter represents the total number of bytes that have been written per second on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
VMStorageWriteOperations: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_device"), "operations_written"),
|
||||
"This counter represents the number of write operations that have occurred per second on this virtual device",
|
||||
[]string{"vm_device"},
|
||||
nil,
|
||||
),
|
||||
|
||||
//
|
||||
|
||||
VMNetworkBytesReceived: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "bytes_received"),
|
||||
"This counter represents the total number of bytes received per second by the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
VMNetworkBytesSent: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "bytes_sent"),
|
||||
"This counter represents the total number of bytes sent per second by the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
VMNetworkDroppedPacketsIncoming: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "packets_incoming_dropped"),
|
||||
"This counter represents the total number of dropped packets per second in the incoming direction of the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
VMNetworkDroppedPacketsOutgoing: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "packets_outgoing_dropped"),
|
||||
"This counter represents the total number of dropped packets per second in the outgoing direction of the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
VMNetworkPacketsReceived: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "packets_received"),
|
||||
"This counter represents the total number of packets received per second by the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
VMNetworkPacketsSent: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, buildSubsystemName("vm_interface"), "packets_sent"),
|
||||
"This counter represents the total number of packets sent per second by the network adapter",
|
||||
[]string{"vm_interface"},
|
||||
nil,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -541,6 +635,17 @@ func (c *HyperVCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||
log.Error("failed collecting hyperV ethernet metrics:", desc, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if desc, err := c.collectVmStorage(ch); err != nil {
|
||||
log.Error("failed collecting hyperV virtual storage metrics:", desc, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if desc, err := c.collectVmNetwork(ch); err != nil {
|
||||
log.Error("failed collecting hyperV virtual network metrics:", desc, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1168,3 +1273,139 @@ func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prome
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Win32_PerfRawData_Counters_HyperVVirtualStorageDevice ...
|
||||
type Win32_PerfRawData_Counters_HyperVVirtualStorageDevice struct {
|
||||
Name string
|
||||
ErrorCount uint64
|
||||
QueueLength uint32
|
||||
ReadBytesPersec uint64
|
||||
ReadOperationsPerSec uint64
|
||||
WriteBytesPersec uint64
|
||||
WriteOperationsPerSec uint64
|
||||
}
|
||||
|
||||
func (c *HyperVCollector) collectVmStorage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
if strings.Contains(obj.Name, "_Total") {
|
||||
continue
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageErrorCount,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.ErrorCount),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageQueueLength,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.QueueLength),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageReadBytes,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.ReadBytesPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageReadOperations,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.ReadOperationsPerSec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageWriteBytes,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.WriteBytesPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMStorageWriteOperations,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.WriteOperationsPerSec),
|
||||
obj.Name,
|
||||
)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter ...
|
||||
type Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter struct {
|
||||
Name string
|
||||
BytesReceivedPersec uint64
|
||||
BytesSentPersec uint64
|
||||
DroppedPacketsIncomingPersec uint64
|
||||
DroppedPacketsOutgoingPersec uint64
|
||||
PacketsReceivedPersec uint64
|
||||
PacketsSentPersec uint64
|
||||
}
|
||||
|
||||
func (c *HyperVCollector) collectVmNetwork(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
||||
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
if strings.Contains(obj.Name, "_Total") {
|
||||
continue
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkBytesReceived,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.BytesReceivedPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkBytesSent,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.BytesSentPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkDroppedPacketsIncoming,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.DroppedPacketsIncomingPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkDroppedPacketsOutgoing,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.DroppedPacketsOutgoingPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkPacketsReceived,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.PacketsReceivedPersec),
|
||||
obj.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VMNetworkPacketsSent,
|
||||
prometheus.CounterValue,
|
||||
float64(obj.PacketsSentPersec),
|
||||
obj.Name,
|
||||
)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ var (
|
||||
type serviceCollector struct {
|
||||
State *prometheus.Desc
|
||||
StartMode *prometheus.Desc
|
||||
Status *prometheus.Desc
|
||||
|
||||
queryWhereClause string
|
||||
}
|
||||
@@ -56,6 +57,12 @@ func NewserviceCollector() (Collector, error) {
|
||||
[]string{"name", "start_mode"},
|
||||
nil,
|
||||
),
|
||||
Status: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(Namespace, subsystem, "status"),
|
||||
"The status of the service (Status)",
|
||||
[]string{"name", "status"},
|
||||
nil,
|
||||
),
|
||||
queryWhereClause: wc.String(),
|
||||
}, nil
|
||||
}
|
||||
@@ -73,6 +80,7 @@ func (c *serviceCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||
type Win32_Service struct {
|
||||
Name string
|
||||
State string
|
||||
Status string
|
||||
StartMode string
|
||||
}
|
||||
|
||||
@@ -94,6 +102,20 @@ var (
|
||||
"manual",
|
||||
"disabled",
|
||||
}
|
||||
allStatuses = []string{
|
||||
"ok",
|
||||
"error",
|
||||
"degraded",
|
||||
"unknown",
|
||||
"pred fail",
|
||||
"starting",
|
||||
"stopping",
|
||||
"service",
|
||||
"stressed",
|
||||
"nonrecover",
|
||||
"no contact",
|
||||
"lost comm",
|
||||
}
|
||||
)
|
||||
|
||||
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
@@ -131,6 +153,20 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
||||
startMode,
|
||||
)
|
||||
}
|
||||
|
||||
for _, status := range allStatuses {
|
||||
isCurrentStatus := 0.0
|
||||
if status == strings.ToLower(service.Status) {
|
||||
isCurrentStatus = 1.0
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Status,
|
||||
prometheus.GaugeValue,
|
||||
isCurrentStatus,
|
||||
strings.ToLower(service.Name),
|
||||
status,
|
||||
)
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package collector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -185,6 +186,30 @@ func (c *textFileCollector) exportMTimes(mtimes map[string]time.Time, ch chan<-
|
||||
}
|
||||
}
|
||||
|
||||
type carriageReturnFilteringReader struct {
|
||||
r io.Reader
|
||||
}
|
||||
|
||||
// Read returns data from the underlying io.Reader, but with \r filtered out
|
||||
func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
|
||||
buf := make([]byte, len(p))
|
||||
n, err := cr.r.Read(buf)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
return n, err
|
||||
}
|
||||
|
||||
pi := 0
|
||||
for i := 0; i < n; i++ {
|
||||
if buf[i] != '\r' {
|
||||
p[pi] = buf[i]
|
||||
pi++
|
||||
}
|
||||
}
|
||||
|
||||
return pi, err
|
||||
}
|
||||
|
||||
// Update implements the Collector interface.
|
||||
func (c *textFileCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||
error := 0.0
|
||||
@@ -203,6 +228,7 @@ fileLoop:
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(c.path, f.Name())
|
||||
log.Debugf("Processing file %q", path)
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Errorf("Error opening %q: %v", path, err)
|
||||
@@ -210,7 +236,7 @@ fileLoop:
|
||||
continue
|
||||
}
|
||||
var parser expfmt.TextParser
|
||||
parsedFamilies, err := parser.TextToMetricFamilies(file)
|
||||
parsedFamilies, err := parser.TextToMetricFamilies(carriageReturnFilteringReader{r: file})
|
||||
file.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Error parsing %q: %v", path, err)
|
||||
|
||||
20
collector/textfile_test.go
Normal file
20
collector/textfile_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func TestCRFilter(t *testing.T) {
|
||||
sr := strings.NewReader("line 1\r\nline 2")
|
||||
cr := carriageReturnFilteringReader{ r: sr }
|
||||
b, err := ioutil.ReadAll(cr)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if string(b) != "line 1\nline 2" {
|
||||
t.Errorf("Unexpected output %q", b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user