mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-11 07:26:37 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3072bb4f3 | ||
|
|
17072bf257 | ||
|
|
d3d8537201 | ||
|
|
2951a9ef80 | ||
|
|
3141fc3ed3 | ||
|
|
a0333ee256 | ||
|
|
c9fc76de4c | ||
|
|
3752a547d5 | ||
|
|
0ab6c191be | ||
|
|
467e83722a | ||
|
|
7fe8ca8554 | ||
|
|
4b3d1d60d9 | ||
|
|
1358123482 | ||
|
|
ec79488478 | ||
|
|
c3b227a4f2 | ||
|
|
c241513d56 | ||
|
|
5a538d7682 | ||
|
|
a0ec1e2da6 | ||
|
|
353de09798 | ||
|
|
afa17b2a1b | ||
|
|
3b88460eb5 |
@@ -13,6 +13,7 @@ ad | [Win32_PerfRawData_DirectoryServices_DirectoryServices](https://msdn.micros
|
|||||||
cpu | [Win32_PerfRawData_PerfOS_Processor](https://msdn.microsoft.com/en-us/library/aa394317(v=vs.90).aspx) metrics (cpu usage) | ✓
|
cpu | [Win32_PerfRawData_PerfOS_Processor](https://msdn.microsoft.com/en-us/library/aa394317(v=vs.90).aspx) metrics (cpu usage) | ✓
|
||||||
cs | [Win32_ComputerSystem](https://msdn.microsoft.com/en-us/library/aa394102) metrics (system properties, num cpus/total memory) | ✓
|
cs | [Win32_ComputerSystem](https://msdn.microsoft.com/en-us/library/aa394102) metrics (system properties, num cpus/total memory) | ✓
|
||||||
dns | [Win32_PerfRawData_DNS_DNS](https://technet.microsoft.com/en-us/library/cc977686.aspx) metrics (DNS Server) |
|
dns | [Win32_PerfRawData_DNS_DNS](https://technet.microsoft.com/en-us/library/cc977686.aspx) metrics (DNS Server) |
|
||||||
|
hyperv | Performance counters for Hyper-V hosts |
|
||||||
iis | [Win32_PerfRawData_W3SVC_WebService](https://msdn.microsoft.com/en-us/library/aa394345) IIS metrics |
|
iis | [Win32_PerfRawData_W3SVC_WebService](https://msdn.microsoft.com/en-us/library/aa394345) IIS metrics |
|
||||||
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
||||||
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
||||||
|
|||||||
1411
collector/hyperv.go
Normal file
1411
collector/hyperv.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@ var (
|
|||||||
type serviceCollector struct {
|
type serviceCollector struct {
|
||||||
State *prometheus.Desc
|
State *prometheus.Desc
|
||||||
StartMode *prometheus.Desc
|
StartMode *prometheus.Desc
|
||||||
|
Status *prometheus.Desc
|
||||||
|
|
||||||
queryWhereClause string
|
queryWhereClause string
|
||||||
}
|
}
|
||||||
@@ -56,6 +57,12 @@ func NewserviceCollector() (Collector, error) {
|
|||||||
[]string{"name", "start_mode"},
|
[]string{"name", "start_mode"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
Status: prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(Namespace, subsystem, "status"),
|
||||||
|
"The status of the service (Status)",
|
||||||
|
[]string{"name", "status"},
|
||||||
|
nil,
|
||||||
|
),
|
||||||
queryWhereClause: wc.String(),
|
queryWhereClause: wc.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -73,6 +80,7 @@ func (c *serviceCollector) Collect(ch chan<- prometheus.Metric) error {
|
|||||||
type Win32_Service struct {
|
type Win32_Service struct {
|
||||||
Name string
|
Name string
|
||||||
State string
|
State string
|
||||||
|
Status string
|
||||||
StartMode string
|
StartMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +102,20 @@ var (
|
|||||||
"manual",
|
"manual",
|
||||||
"disabled",
|
"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) {
|
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,
|
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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,37 +30,37 @@ func NewSystemCollector() (Collector, error) {
|
|||||||
return &SystemCollector{
|
return &SystemCollector{
|
||||||
ContextSwitchesTotal: prometheus.NewDesc(
|
ContextSwitchesTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "context_switches_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "context_switches_total"),
|
||||||
"PerfOS_System.ContextSwitchesPersec",
|
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ExceptionDispatchesTotal: prometheus.NewDesc(
|
ExceptionDispatchesTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "exception_dispatches_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "exception_dispatches_total"),
|
||||||
"PerfOS_System.ExceptionDispatchesPersec",
|
"Total number of exceptions dispatched (WMI source: PerfOS_System.ExceptionDispatchesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ProcessorQueueLength: prometheus.NewDesc(
|
ProcessorQueueLength: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "processor_queue_length"),
|
prometheus.BuildFQName(Namespace, subsystem, "processor_queue_length"),
|
||||||
"PerfOS_System.ProcessorQueueLength",
|
"Length of processor queue (WMI source: PerfOS_System.ProcessorQueueLength)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SystemCallsTotal: prometheus.NewDesc(
|
SystemCallsTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "system_calls_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "system_calls_total"),
|
||||||
"PerfOS_System.SystemCallsPersec",
|
"Total number of system calls (WMI source: PerfOS_System.SystemCallsPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SystemUpTime: prometheus.NewDesc(
|
SystemUpTime: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "system_up_time"),
|
prometheus.BuildFQName(Namespace, subsystem, "system_up_time"),
|
||||||
"SystemUpTime/Frequency_Object",
|
"System boot time (WMI source: PerfOS_System.SystemUpTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
Threads: prometheus.NewDesc(
|
Threads: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "threads"),
|
prometheus.BuildFQName(Namespace, subsystem, "threads"),
|
||||||
"PerfOS_System.Threads",
|
"Current number of threads (WMI source: PerfOS_System.Threads)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
@@ -96,12 +96,12 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
|
|||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextSwitchesTotal,
|
c.ContextSwitchesTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ContextSwitchesPersec),
|
float64(dst[0].ContextSwitchesPersec),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ExceptionDispatchesTotal,
|
c.ExceptionDispatchesTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ExceptionDispatchesPersec),
|
float64(dst[0].ExceptionDispatchesPersec),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
@@ -111,7 +111,7 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
|
|||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemCallsTotal,
|
c.SystemCallsTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].SystemCallsPersec),
|
float64(dst[0].SystemCallsPersec),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"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.
|
// Update implements the Collector interface.
|
||||||
func (c *textFileCollector) Collect(ch chan<- prometheus.Metric) error {
|
func (c *textFileCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||||
error := 0.0
|
error := 0.0
|
||||||
@@ -203,6 +228,7 @@ fileLoop:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path := filepath.Join(c.path, f.Name())
|
path := filepath.Join(c.path, f.Name())
|
||||||
|
log.Debugf("Processing file %q", path)
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error opening %q: %v", path, err)
|
log.Errorf("Error opening %q: %v", path, err)
|
||||||
@@ -210,7 +236,7 @@ fileLoop:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var parser expfmt.TextParser
|
var parser expfmt.TextParser
|
||||||
parsedFamilies, err := parser.TextToMetricFamilies(file)
|
parsedFamilies, err := parser.TextToMetricFamilies(carriageReturnFilteringReader{r: file})
|
||||||
file.Close()
|
file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error parsing %q: %v", path, err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
16
exporter.go
16
exporter.go
@@ -44,6 +44,16 @@ var (
|
|||||||
[]string{"collector"},
|
[]string{"collector"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// This can be removed when client_golang exposes this on Windows
|
||||||
|
// (See https://github.com/prometheus/client_golang/issues/376)
|
||||||
|
startTime = float64(time.Now().Unix())
|
||||||
|
startTimeDesc = prometheus.NewDesc(
|
||||||
|
"process_start_time_seconds",
|
||||||
|
"Start time of the process since unix epoch in seconds.",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Describe sends all the descriptors of the collectors included to
|
// Describe sends all the descriptors of the collectors included to
|
||||||
@@ -65,6 +75,12 @@ func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
}(name, c)
|
}(name, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
startTimeDesc,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
startTime,
|
||||||
|
)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user