Compare commits

...

27 Commits

Author SHA1 Message Date
Calle Pettersson
fe7e5cb4d8 Merge pull request #241 from szook/protect-against-empty-result-set
protect against empty wmi query result sets
2018-08-08 09:14:27 +02:00
Steve Zook
c156f2bcbe protect against emtpy wmi query result sets
If an WMI query were to return an empty result set, trying to access the
first element in the result set would result in a `panic: runtime error:
index out of range` error.

add logic to explicitly check if the result set size is 0 and return an
error rather.

Fixes https://github.com/martinlindhe/wmi_exporter/issues/240
2018-08-07 15:47:39 -04:00
Calle Pettersson
832771b4a2 Merge pull request #238 from bbigras/patch-1
fix typo in exporter.go
2018-08-06 11:41:43 +02:00
Bruno Bigras
16fecfbc67 fix typo in exporter.go 2018-08-05 21:39:43 -04:00
Calle Pettersson
bad1e7f7b0 Merge pull request #237 from szook/fix-mssql-for-non-default-instances
fix mssql for non-default sql instances
2018-08-04 08:33:23 +02:00
Steve Zook
c868c00e89 fix mssql for non-default sql instances
the only sql servers I have access to are using the default
`MSSQLSERVER` instance names.  I was contacted by someone using a
different instance name and it was failing.

Found 2 bugs in the code:

1) I was returning the default `MSSQLSERVER` as an instance even if it wasn't found in the registry

2) learned that the WMI class naming scheme for non-default instances
was not what I had coded. Changed to incorproate new knowledge.
2018-08-03 16:31:19 -04:00
Calle Pettersson
5035e97369 Merge pull request #236 from szook/add-mssql-accessmethod-class
add mssql accessmethod class
2018-08-03 22:16:08 +02:00
Steve Zook
144715e3d2 remove persec from variable names
removed persec from variable names

but when I did that, there was some variable name collisions, so I went
through and name-spaced the class variables.
1
2018-08-03 15:39:26 -04:00
Steve Zook
a20cf1274a add mssql accessmethod class
in the process of trying to build a grafana dashboard with "useful"
mssql metrics, I was looking around for what metrics might be useful and
came across an article of [15 SQL Server Performace Counters to Monitor](https://blogs.sentryone.com/allenwhite/sql-server-performance-counters-to-monitor/)

two of the suggested metrics are provided by the AccessMethod
class, which I was not yet capturing.

So I added metrics for the
Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods class.
2018-08-03 13:45:51 -04:00
Calle Pettersson
626a25cd00 Merge pull request #235 from szook/reorder-functions
reorder functions
2018-08-03 16:42:32 +02:00
Calle Pettersson
96dd456bb1 Merge pull request #234 from szook/fix-mssql-metric-name-typo
fix mssql metric name type
2018-08-03 16:27:40 +02:00
Steve Zook
af1b8bf4d0 fix mssql metric name type
found that I had one metric with an extra `s` in `_genstatss_`, making it
inconsistent with it's siblings.
2018-08-03 09:52:15 -04:00
Steve Zook
d83615a818 reorder functions
so that the two functions that list available child collectors are next
to each other - should make less likely to not miss editing one of those
when adding additional wmi classes

also removed the 'filter' from the `mssqlFilterAvailableClassCollectors`
function as it's not filtering anyting.
2018-08-03 09:48:32 -04:00
szook
fe4c61a70e Add mssql collector (#230)
add mssql collector
2018-08-02 08:42:02 +02:00
Calle Pettersson
143705bbf6 Merge pull request #227 from szook/add-worker-process-name-to-w3wp-processes
append IIS worker process name to corresponding w3wp processes
2018-07-23 16:20:07 +02:00
Steve Zook
e8ffb736d0 add worker process name to w3wp processes
modify the `process` collector so that the IIS worker process name is
appended to the corresponding `w3wp` process.

before:
```
wmi_process_private_bytes{creating_process_id="2068",process="w3wp",process_id="12308"} 7.18204928e+08
```

after:
```
wmi_process_private_bytes{creating_process_id="2068",process="w3wp_our.website.com",process_id="12308"} 7.18204928e+08
```

reason:
We have some IIS servers hosting many .NET applications. When there is
resource contention on one of those servers, it's nice to know which IIS
application pool is the culprit.  Having only the process_id to
differentiate between w3wp processes requires additional work to figure
out which is which.  Also it does not allow for historial trending as
the process_id can change across restarts.
2018-07-23 07:53:50 -04:00
Calle Pettersson
21e0f926a3 Merge pull request #226 from szook/fix-iis-collector-panic
fix iis collector panic
2018-07-19 11:27:26 -07:00
Steve Zook
8ea862a3da fix iis collector panic
If the `dst_cache` slice is empty, the program panics when trying to access `dst_cache[0]`

added a `if len(dst_cache) > 0 {}` block around the use of that variable to prevent that panic.
2018-07-19 13:42:00 -04:00
Mark D
bb67658853 Fix IIS warning when IIS collector is NOT in use (#212)
changing IIS code to only error if used
Only tries to read registry if collector is initialized
2018-06-10 07:52:20 -07:00
Calle Pettersson
aecd90dcf1 Merge pull request #209 from martinlindhe/wmi-query-wildcard
* Refactor wmi query generator to use wildcard selector
2018-06-06 03:23:17 -07:00
Calle Pettersson
cd365c6a3b Harmonize query call layout 2018-06-06 11:35:13 +02:00
Calle Pettersson
667d06116d Refactor wmi query generator to use wildcard selector 2018-06-06 10:38:36 +02:00
tunaman
f3072bb4f3 Add extra HyperV VM classes (#202)
add two extra new HyperV VM classes
2018-05-17 23:46:13 -07:00
Calle Pettersson
17072bf257 Merge pull request #198 from martinlindhe/service-status
Add status metric for service-collector
2018-05-17 11:05:07 -07:00
Calle Pettersson
d3d8537201 Merge pull request #200 from martinlindhe/textfile-carriage-return
Strip carriage-returns from textfile input
2018-05-16 05:18:54 -07:00
Calle Pettersson
2951a9ef80 Strip carriage-returns from textfile input 2018-05-15 20:58:58 +02:00
Calle Pettersson
3141fc3ed3 Add status metric for service-collector 2018-05-12 09:49:29 +02:00
31 changed files with 4160 additions and 87 deletions

View File

@@ -9,15 +9,16 @@ Prometheus exporter for Windows machines, using the WMI (Windows Management Inst
Name | Description | Enabled by default
---------|-------------|--------------------
ad | [Win32_PerfRawData_DirectoryServices_DirectoryServices](https://msdn.microsoft.com/en-us/library/ms803980.aspx) Active Directory |
ad | [Win32_PerfRawData_DirectoryServices_DirectoryServices](https://msdn.microsoft.com/en-us/library/ms803980.aspx) Active Directory |
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) | ✓
dns | [Win32_PerfRawData_DNS_DNS](https://technet.microsoft.com/en-us/library/cc977686.aspx) metrics (DNS Server) |
hyperv | Performance counters for Hyper-V hosts |
hyperv | Performance counters for Hyper-V hosts |
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) | ✓
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
msmq | [Win32_PerfRawData_MSMQ_MSMQQueue](http://wutils.com/wmi/root/cimv2/win32_perfrawdata_msmq_msmqqueue/) metrics (MSMQ/journal count) |
msmq | [Win32_PerfRawData_MSMQ_MSMQQueue](http://wutils.com/wmi/root/cimv2/win32_perfrawdata_msmq_msmqqueue/) metrics (MSMQ/journal count) |
mssql | various [SQL Server Performance Objects](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/use-sql-server-objects#SQLServerPOs) metrics |
os | [Win32_OperatingSystem](https://msdn.microsoft.com/en-us/library/aa394239) metrics (memory, processes, users) | ✓
process | [Win32_PerfRawData_PerfProc_Process](https://msdn.microsoft.com/en-us/library/aa394323(v=vs.85).aspx) metrics (per-process stats) |
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | ✓

View File

@@ -3,6 +3,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -612,10 +614,13 @@ type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
func (c *ADCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.AddressBookOperationsTotal,

View File

@@ -117,7 +117,7 @@ type Win32_PerfRawData_Counters_ProcessorInformation struct {
func (c *CPUCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfOS_Processor
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -4,6 +4,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -56,9 +58,13 @@ type Win32_ComputerSystem struct {
func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_ComputerSystem
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.LogicalProcessors,

View File

@@ -4,6 +4,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -233,10 +235,13 @@ type Win32_PerfRawData_DNS_DNS struct {
func (c *DNSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_DNS_DNS
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ZoneTransferRequestsReceived,

View File

@@ -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
}
@@ -552,7 +657,8 @@ type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
func (c *HyperVCollector) collectVmHealth(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -584,7 +690,8 @@ type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct {
func (c *HyperVCollector) collectVmVid(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -647,7 +754,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition struct {
func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -784,7 +892,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisor struct {
func (c *HyperVCollector) collectVmProcessor(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_HvStats_HyperVHypervisor
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -818,7 +927,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct {
func (c *HyperVCollector) collectHostCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -878,7 +988,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor struct {
func (c *HyperVCollector) collectVmCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -955,7 +1066,8 @@ type Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch struct {
func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -1113,7 +1225,8 @@ type Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter struct {
func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -1168,3 +1281,141 @@ 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
q := queryAll(&dst)
if err := wmi.Query(q, &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
q := queryAll(&dst)
if err := wmi.Query(q, &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
}

View File

@@ -7,6 +7,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
@@ -20,7 +21,6 @@ import (
func init() {
Factories["iis"] = NewIISCollector
iis_version = getIISVersion()
}
type simple_version struct {
@@ -60,8 +60,6 @@ var (
siteBlacklist = kingpin.Flag("collector.iis.site-blacklist", "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String()
appWhitelist = kingpin.Flag("collector.iis.app-whitelist", "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
appBlacklist = kingpin.Flag("collector.iis.app-blacklist", "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
iis_version = simple_version{}
)
type IISCollector struct {
@@ -188,13 +186,15 @@ type IISCollector struct {
appWhitelistPattern *regexp.Regexp
appBlacklistPattern *regexp.Regexp
iis_version simple_version
}
// NewIISCollector ...
func NewIISCollector() (Collector, error) {
const subsystem = "iis"
return &IISCollector{
buildIIS := &IISCollector{
// Websites
// Gauges
CurrentAnonymousUsers: prometheus.NewDesc(
@@ -808,7 +808,11 @@ func NewIISCollector() (Collector, error) {
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
}, nil
}
buildIIS.iis_version = getIISVersion()
return buildIIS, nil
}
// Collect sends the metric values for each metric
@@ -995,7 +999,7 @@ var workerProcessNameExtractor = regexp.MustCompile(`^(\d+)_(.+)$`)
func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_W3SVC_WebService
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -1248,7 +1252,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
}
var dst2 []Win32_PerfRawData_APPPOOLCountersProvider_APPPOOLWAS
q2 := wmi.CreateQuery(&dst2, "")
q2 := queryAll(&dst2)
if err := wmi.Query(q2, &dst2); err != nil {
return nil, err
}
@@ -1365,7 +1369,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
}
var dst_worker []Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP
q = wmi.CreateQuery(&dst_worker, "")
q = queryAll(&dst_worker)
if err := wmi.Query(q, &dst_worker); err != nil {
return nil, err
}
@@ -1645,9 +1649,9 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
)
}
if iis_version.major >= 8 {
if c.iis_version.major >= 8 {
var dst_worker_iis8 []Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP_IIS8
q = createQuery(&dst_worker_iis8, "Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP", "")
q = queryAllForClass(&dst_worker_iis8, "Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP")
if err := wmi.Query(q, &dst_worker_iis8); err != nil {
return nil, err
}
@@ -1730,11 +1734,15 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
}
var dst_cache []Win32_PerfRawData_W3SVC_WebServiceCache
q = wmi.CreateQuery(&dst_cache, "")
q = queryAll(&dst_cache)
if err := wmi.Query(q, &dst_cache); err != nil {
return nil, err
}
if len(dst_cache) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_ActiveFlushedEntries,
prometheus.GaugeValue,

View File

@@ -161,7 +161,7 @@ type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -3,7 +3,6 @@
package collector
import (
"bytes"
"strings"
"github.com/StackExchange/wmi"
@@ -34,10 +33,7 @@ type Win32_PerfRawData_MSMQ_MSMQQueueCollector struct {
func NewMSMQCollector() (Collector, error) {
const subsystem = "msmq"
var wc bytes.Buffer
if *msmqWhereClause != "" {
wc.WriteString("WHERE ")
wc.WriteString(*msmqWhereClause)
log.Warn("No where-clause specified for msmq collector. This will generate a very large number of metrics!")
}
@@ -66,7 +62,7 @@ func NewMSMQCollector() (Collector, error) {
[]string{"name"},
nil,
),
queryWhereClause: wc.String(),
queryWhereClause: *msmqWhereClause,
}, nil
}
@@ -91,7 +87,7 @@ type Win32_PerfRawData_MSMQ_MSMQQueue struct {
func (c *Win32_PerfRawData_MSMQ_MSMQQueueCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_MSMQ_MSMQQueue
q := wmi.CreateQuery(&dst, c.queryWhereClause)
q := queryAllWhere(&dst, c.queryWhereClause)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

3546
collector/mssql.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -169,7 +169,7 @@ type Win32_PerfRawData_Tcpip_NetworkInterface struct {
func (c *NetworkCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_Tcpip_NetworkInterface
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -73,7 +73,7 @@ type Win32_PerfRawData_NETFramework_NETCLRExceptions struct {
func (c *NETFramework_NETCLRExceptionsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -66,7 +66,7 @@ type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
func (c *NETFramework_NETCLRInteropCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -75,7 +75,7 @@ type Win32_PerfRawData_NETFramework_NETCLRJit struct {
func (c *NETFramework_NETCLRJitCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -119,7 +119,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLoading struct {
func (c *NETFramework_NETCLRLoadingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -99,7 +99,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads struct {
func (c *NETFramework_NETCLRLocksAndThreadsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -151,7 +151,7 @@ type Win32_PerfRawData_NETFramework_NETCLRMemory struct {
func (c *NETFramework_NETCLRMemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -89,7 +89,7 @@ type Win32_PerfRawData_NETFramework_NETCLRRemoting struct {
func (c *NETFramework_NETCLRRemotingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -74,7 +74,7 @@ type Win32_PerfRawData_NETFramework_NETCLRSecurity struct {
func (c *NETFramework_NETCLRSecurityCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"time"
"github.com/StackExchange/wmi"
@@ -137,10 +138,15 @@ type Win32_OperatingSystem struct {
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_OperatingSystem
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.PhysicalMemoryFreeBytes,
prometheus.GaugeValue,

View File

@@ -3,7 +3,6 @@
package collector
import (
"bytes"
"strconv"
"strings"
@@ -47,11 +46,7 @@ type ProcessCollector struct {
func NewProcessCollector() (Collector, error) {
const subsystem = "process"
var wc bytes.Buffer
if *processWhereClause != "" {
wc.WriteString("WHERE ")
wc.WriteString(*processWhereClause)
} else {
if *processWhereClause == "" {
log.Warn("No where-clause specified for process collector. This will generate a very large number of metrics!")
}
@@ -134,7 +129,7 @@ func NewProcessCollector() (Collector, error) {
[]string{"process", "process_id", "creating_process_id"},
nil,
),
queryWhereClause: wc.String(),
queryWhereClause: *processWhereClause,
}, nil
}
@@ -182,13 +177,22 @@ type Win32_PerfRawData_PerfProc_Process struct {
WorkingSetPrivate uint64
}
type WorkerProcess struct {
AppPoolName string
ProcessId uint32
}
func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfProc_Process
q := wmi.CreateQuery(&dst, c.queryWhereClause)
q := queryAllWhere(&dst, c.queryWhereClause)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
var dst_wp []WorkerProcess
q_wp := queryAll(&dst_wp)
wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration")
for _, process := range dst {
if process.Name == "_Total" {
@@ -199,6 +203,13 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10)
for _, wp := range dst_wp {
if wp.ProcessId == process.IDProcess {
processName = strings.Join([]string{processName, wp.AppPoolName}, "_")
break
}
}
ch <- prometheus.MustNewConstMetric(
c.StartTime,
prometheus.GaugeValue,

View File

@@ -3,7 +3,6 @@
package collector
import (
"bytes"
"strings"
"github.com/StackExchange/wmi"
@@ -27,6 +26,7 @@ var (
type serviceCollector struct {
State *prometheus.Desc
StartMode *prometheus.Desc
Status *prometheus.Desc
queryWhereClause string
}
@@ -35,11 +35,7 @@ type serviceCollector struct {
func NewserviceCollector() (Collector, error) {
const subsystem = "service"
var wc bytes.Buffer
if *serviceWhereClause != "" {
wc.WriteString("WHERE ")
wc.WriteString(*serviceWhereClause)
} else {
if *serviceWhereClause == "" {
log.Warn("No where-clause specified for service collector. This will generate a very large number of metrics!")
}
@@ -56,7 +52,13 @@ func NewserviceCollector() (Collector, error) {
[]string{"name", "start_mode"},
nil,
),
queryWhereClause: wc.String(),
Status: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "status"),
"The status of the service (Status)",
[]string{"name", "status"},
nil,
),
queryWhereClause: *serviceWhereClause,
}, nil
}
@@ -73,6 +75,7 @@ func (c *serviceCollector) Collect(ch chan<- prometheus.Metric) error {
type Win32_Service struct {
Name string
State string
Status string
StartMode string
}
@@ -94,11 +97,25 @@ 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) {
var dst []Win32_Service
q := wmi.CreateQuery(&dst, c.queryWhereClause)
q := queryAllWhere(&dst, c.queryWhereClause)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
@@ -131,6 +148,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
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -90,9 +91,13 @@ type Win32_PerfRawData_PerfOS_System struct {
func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfOS_System
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ContextSwitchesTotal,

View File

@@ -5,6 +5,7 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -114,10 +115,13 @@ type Win32_PerfRawData_Tcpip_TCPv4 struct {
func (c *TCPCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_Tcpip_TCPv4
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
// Counters
ch <- prometheus.MustNewConstMetric(

View File

@@ -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)

View 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)
}
}

View File

@@ -2,6 +2,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -197,10 +199,13 @@ type Win32_PerfRawData_vmGuestLib_VCPU struct {
func (c *VmwareCollector) collectMem(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_vmGuestLib_VMem
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.MemActive,
@@ -283,10 +288,13 @@ func mbToBytes(mb uint64) float64 {
func (c *VmwareCollector) collectCpu(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_vmGuestLib_VCPU
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.CpuLimitMHz,

View File

@@ -3,9 +3,9 @@ package collector
import (
"bytes"
"reflect"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
)
// ...
@@ -25,29 +25,57 @@ type Collector interface {
Collect(ch chan<- prometheus.Metric) (err error)
}
// This is adapted from StackExchange/wmi/wmi.go, and lets us change the class
// name being queried for:
// CreateQuery returns a WQL query string that queries all columns of src. where
// is an optional string that is appended to the query, to be used with WHERE
// clauses. In such a case, the "WHERE" string should appear at the beginning.
func createQuery(src interface{}, class, where string) string {
var b bytes.Buffer
b.WriteString("SELECT ")
func className(src interface{}) string {
s := reflect.Indirect(reflect.ValueOf(src))
t := s.Type()
if s.Kind() == reflect.Slice {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
return ""
}
var fields []string
for i := 0; i < t.NumField(); i++ {
fields = append(fields, t.Field(i).Name)
}
b.WriteString(strings.Join(fields, ", "))
b.WriteString(" FROM ")
b.WriteString(class)
b.WriteString(" " + where)
return t.Name()
}
func queryAll(src interface{}) string {
var b bytes.Buffer
b.WriteString("SELECT * FROM ")
b.WriteString(className(src))
log.Debugf("Generated WMI query %s", b.String())
return b.String()
}
func queryAllForClass(src interface{}, class string) string {
var b bytes.Buffer
b.WriteString("SELECT * FROM ")
b.WriteString(class)
log.Debugf("Generated WMI query %s", b.String())
return b.String()
}
func queryAllWhere(src interface{}, where string) string {
var b bytes.Buffer
b.WriteString("SELECT * FROM ")
b.WriteString(className(src))
if where != "" {
b.WriteString(" WHERE ")
b.WriteString(where)
}
log.Debugf("Generated WMI query %s", b.String())
return b.String()
}
func queryAllForClassWhere(src interface{}, class string, where string) string {
var b bytes.Buffer
b.WriteString("SELECT * FROM ")
b.WriteString(class)
if where != "" {
b.WriteString(" WHERE ")
b.WriteString(where)
}
log.Debugf("Generated WMI query %s", b.String())
return b.String()
}

115
collector/wmi_test.go Normal file
View File

@@ -0,0 +1,115 @@
package collector
import (
"testing"
)
type fakeWmiClass struct {
Name string
SomeProperty int
}
var (
mapQueryAll = func(src interface{}, class string, where string) string {
return queryAll(src)
}
mapQueryAllWhere = func(src interface{}, class string, where string) string {
return queryAllWhere(src, where)
}
mapQueryAllForClass = func(src interface{}, class string, where string) string {
return queryAllForClass(src, class)
}
mapQueryAllForClassWhere = func(src interface{}, class string, where string) string {
return queryAllForClassWhere(src, class, where)
}
)
type queryFunc func(src interface{}, class string, where string) string
func TestCreateQuery(t *testing.T) {
cases := []struct {
desc string
dst interface{}
class string
where string
queryFunc queryFunc
expected string
}{
{
desc: "queryAll on single instance",
dst: fakeWmiClass{},
queryFunc: mapQueryAll,
expected: "SELECT * FROM fakeWmiClass",
},
{
desc: "queryAll on slice",
dst: []fakeWmiClass{},
queryFunc: mapQueryAll,
expected: "SELECT * FROM fakeWmiClass",
},
{
desc: "queryAllWhere on single instance",
dst: fakeWmiClass{},
where: "foo = bar",
queryFunc: mapQueryAllWhere,
expected: "SELECT * FROM fakeWmiClass WHERE foo = bar",
},
{
desc: "queryAllWhere on slice",
dst: []fakeWmiClass{},
where: "foo = bar",
queryFunc: mapQueryAllWhere,
expected: "SELECT * FROM fakeWmiClass WHERE foo = bar",
},
{
desc: "queryAllWhere on single instance with empty where",
dst: fakeWmiClass{},
queryFunc: mapQueryAllWhere,
expected: "SELECT * FROM fakeWmiClass",
},
{
desc: "queryAllForClass on single instance",
dst: fakeWmiClass{},
class: "someClass",
queryFunc: mapQueryAllForClass,
expected: "SELECT * FROM someClass",
},
{
desc: "queryAllForClass on slice",
dst: []fakeWmiClass{},
class: "someClass",
queryFunc: mapQueryAllForClass,
expected: "SELECT * FROM someClass",
},
{
desc: "queryAllForClassWhere on single instance",
dst: fakeWmiClass{},
class: "someClass",
where: "foo = bar",
queryFunc: mapQueryAllForClassWhere,
expected: "SELECT * FROM someClass WHERE foo = bar",
},
{
desc: "queryAllForClassWhere on slice",
dst: []fakeWmiClass{},
class: "someClass",
where: "foo = bar",
queryFunc: mapQueryAllForClassWhere,
expected: "SELECT * FROM someClass WHERE foo = bar",
},
{
desc: "queryAllForClassWhere on single instance with empty where",
dst: fakeWmiClass{},
class: "someClass",
queryFunc: mapQueryAllForClassWhere,
expected: "SELECT * FROM someClass",
},
}
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
if q := c.queryFunc(c.dst, c.class, c.where); q != c.expected {
t.Errorf("Case %q failed: Expected %q, got %q", c.desc, c.expected, q)
}
})
}
}

View File

@@ -47,7 +47,7 @@ var (
// 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())
startTime = float64(time.Now().Unix())
startTimeDesc = prometheus.NewDesc(
"process_start_time_seconds",
"Start time of the process since unix epoch in seconds.",
@@ -169,6 +169,7 @@ func initWbem() {
if err != nil {
log.Fatal(err)
}
wmi.DefaultClient.AllowMissingFields = true
wmi.DefaultClient.SWbemServicesClient = s
}
@@ -184,7 +185,7 @@ func main() {
).Default("/metrics").String()
enabledCollectors = kingpin.Flag(
"collectors.enabled",
"Comma-separated list of collectors to use. Use '[default]' as a placeholder for all the collectors enabled by default.").
"Comma-separated list of collectors to use. Use '[defaults]' as a placeholder for all the collectors enabled by default.").
Default(filterAvailableCollectors(defaultCollectors)).String()
printCollectors = kingpin.Flag(
"collectors.print",

View File

@@ -46,7 +46,7 @@ type {{ .Class }} struct {
}
func (c *{{ .CollectorName }}Collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []{{ .Class }}
q := wmi.CreateQuery(&dst, "")
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}