mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-10 06:56:38 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bad1e7f7b0 | ||
|
|
c868c00e89 | ||
|
|
5035e97369 | ||
|
|
144715e3d2 | ||
|
|
a20cf1274a | ||
|
|
626a25cd00 | ||
|
|
96dd456bb1 | ||
|
|
af1b8bf4d0 | ||
|
|
d83615a818 | ||
|
|
fe4c61a70e | ||
|
|
143705bbf6 | ||
|
|
e8ffb736d0 | ||
|
|
21e0f926a3 | ||
|
|
8ea862a3da | ||
|
|
bb67658853 | ||
|
|
aecd90dcf1 | ||
|
|
cd365c6a3b | ||
|
|
667d06116d |
@@ -9,15 +9,16 @@ Prometheus exporter for Windows machines, using the WMI (Windows Management Inst
|
|||||||
|
|
||||||
Name | Description | Enabled by default
|
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) | ✓
|
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 |
|
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) | ✓
|
||||||
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) | ✓
|
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) |
|
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) | ✓
|
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | ✓
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
|
|||||||
|
|
||||||
func (c *ADCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *ADCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
|
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ type Win32_PerfRawData_Counters_ProcessorInformation struct {
|
|||||||
|
|
||||||
func (c *CPUCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *CPUCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfOS_Processor
|
var dst []Win32_PerfRawData_PerfOS_Processor
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ type Win32_ComputerSystem struct {
|
|||||||
|
|
||||||
func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_ComputerSystem
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ type Win32_PerfRawData_DNS_DNS struct {
|
|||||||
|
|
||||||
func (c *DNSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *DNSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_DNS_DNS
|
var dst []Win32_PerfRawData_DNS_DNS
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ type HyperVCollector struct {
|
|||||||
|
|
||||||
// Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
// Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||||
VMStorageErrorCount *prometheus.Desc
|
VMStorageErrorCount *prometheus.Desc
|
||||||
VMStorageQueueLength *prometheus.Desc
|
VMStorageQueueLength *prometheus.Desc
|
||||||
VMStorageReadBytes *prometheus.Desc
|
VMStorageReadBytes *prometheus.Desc
|
||||||
VMStorageReadOperations *prometheus.Desc
|
VMStorageReadOperations *prometheus.Desc
|
||||||
VMStorageWriteBytes *prometheus.Desc
|
VMStorageWriteBytes *prometheus.Desc
|
||||||
@@ -657,7 +657,8 @@ type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmHealth(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmHealth(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,7 +690,8 @@ type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmVid(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmVid(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,7 +754,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -889,7 +892,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisor struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmProcessor(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmProcessor(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisor
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,7 +927,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectHostCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectHostCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +988,8 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1060,7 +1066,8 @@ type Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1218,7 +1225,8 @@ type Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1287,7 +1295,8 @@ type Win32_PerfRawData_Counters_HyperVVirtualStorageDevice struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmStorage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmStorage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||||
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
q := queryAll(&dst)
|
||||||
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1355,7 +1364,8 @@ type Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter struct {
|
|||||||
|
|
||||||
func (c *HyperVCollector) collectVmNetwork(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *HyperVCollector) collectVmNetwork(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
||||||
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
q := queryAll(&dst)
|
||||||
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
391
collector/iis.go
391
collector/iis.go
@@ -20,7 +20,6 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Factories["iis"] = NewIISCollector
|
Factories["iis"] = NewIISCollector
|
||||||
iis_version = getIISVersion()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type simple_version struct {
|
type simple_version struct {
|
||||||
@@ -60,8 +59,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()
|
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()
|
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()
|
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 {
|
type IISCollector struct {
|
||||||
@@ -188,13 +185,15 @@ type IISCollector struct {
|
|||||||
|
|
||||||
appWhitelistPattern *regexp.Regexp
|
appWhitelistPattern *regexp.Regexp
|
||||||
appBlacklistPattern *regexp.Regexp
|
appBlacklistPattern *regexp.Regexp
|
||||||
|
|
||||||
|
iis_version simple_version
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIISCollector ...
|
// NewIISCollector ...
|
||||||
func NewIISCollector() (Collector, error) {
|
func NewIISCollector() (Collector, error) {
|
||||||
const subsystem = "iis"
|
const subsystem = "iis"
|
||||||
|
|
||||||
return &IISCollector{
|
buildIIS := &IISCollector{
|
||||||
// Websites
|
// Websites
|
||||||
// Gauges
|
// Gauges
|
||||||
CurrentAnonymousUsers: prometheus.NewDesc(
|
CurrentAnonymousUsers: prometheus.NewDesc(
|
||||||
@@ -808,7 +807,11 @@ func NewIISCollector() (Collector, error) {
|
|||||||
|
|
||||||
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
|
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
|
||||||
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
|
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
buildIIS.iis_version = getIISVersion()
|
||||||
|
|
||||||
|
return buildIIS, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -995,7 +998,7 @@ var workerProcessNameExtractor = regexp.MustCompile(`^(\d+)_(.+)$`)
|
|||||||
|
|
||||||
func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_W3SVC_WebService
|
var dst []Win32_PerfRawData_W3SVC_WebService
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1248,7 +1251,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dst2 []Win32_PerfRawData_APPPOOLCountersProvider_APPPOOLWAS
|
var dst2 []Win32_PerfRawData_APPPOOLCountersProvider_APPPOOLWAS
|
||||||
q2 := wmi.CreateQuery(&dst2, "")
|
q2 := queryAll(&dst2)
|
||||||
if err := wmi.Query(q2, &dst2); err != nil {
|
if err := wmi.Query(q2, &dst2); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1365,7 +1368,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dst_worker []Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP
|
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 {
|
if err := wmi.Query(q, &dst_worker); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1645,9 +1648,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
|
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 {
|
if err := wmi.Query(q, &dst_worker_iis8); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1730,219 +1733,221 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dst_cache []Win32_PerfRawData_W3SVC_WebServiceCache
|
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 {
|
if err := wmi.Query(q, &dst_cache); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
if len(dst_cache) > 0 {
|
||||||
c.ServiceCache_ActiveFlushedEntries,
|
ch <- prometheus.MustNewConstMetric(
|
||||||
prometheus.GaugeValue,
|
c.ServiceCache_ActiveFlushedEntries,
|
||||||
float64(dst_cache[0].ActiveFlushedEntries),
|
prometheus.GaugeValue,
|
||||||
)
|
float64(dst_cache[0].ActiveFlushedEntries),
|
||||||
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FileCacheMemoryUsage,
|
c.ServiceCache_FileCacheMemoryUsage,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst_cache[0].CurrentFileCacheMemoryUsage),
|
float64(dst_cache[0].CurrentFileCacheMemoryUsage),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MaximumFileCacheMemoryUsage,
|
c.ServiceCache_MaximumFileCacheMemoryUsage,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].MaximumFileCacheMemoryUsage),
|
float64(dst_cache[0].MaximumFileCacheMemoryUsage),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FileCacheFlushesTotal,
|
c.ServiceCache_FileCacheFlushesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedFiles),
|
float64(dst_cache[0].TotalFlushedFiles),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FileCacheQueriesTotal,
|
c.ServiceCache_FileCacheQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].FileCacheHits+dst_cache[0].FileCacheMisses),
|
float64(dst_cache[0].FileCacheHits+dst_cache[0].FileCacheMisses),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FileCacheHitsTotal,
|
c.ServiceCache_FileCacheHitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].FileCacheHits),
|
float64(dst_cache[0].FileCacheHits),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FilesCached,
|
c.ServiceCache_FilesCached,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst_cache[0].CurrentFilesCached),
|
float64(dst_cache[0].CurrentFilesCached),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FilesCachedTotal,
|
c.ServiceCache_FilesCachedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFilesCached),
|
float64(dst_cache[0].TotalFilesCached),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_FilesFlushedTotal,
|
c.ServiceCache_FilesFlushedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedFiles),
|
float64(dst_cache[0].TotalFlushedFiles),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheFlushesTotal,
|
c.ServiceCache_URICacheFlushesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedURIs),
|
float64(dst_cache[0].TotalFlushedURIs),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheFlushesTotal,
|
c.ServiceCache_URICacheFlushesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].KernelTotalFlushedURIs),
|
float64(dst_cache[0].KernelTotalFlushedURIs),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheQueriesTotal,
|
c.ServiceCache_URICacheQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].URICacheHits+dst_cache[0].URICacheMisses),
|
float64(dst_cache[0].URICacheHits+dst_cache[0].URICacheMisses),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheQueriesTotal,
|
c.ServiceCache_URICacheQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].KernelURICacheHits+dst_cache[0].KernelURICacheMisses),
|
float64(dst_cache[0].KernelURICacheHits+dst_cache[0].KernelURICacheMisses),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheHitsTotal,
|
c.ServiceCache_URICacheHitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].URICacheHits),
|
float64(dst_cache[0].URICacheHits),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URICacheHitsTotal,
|
c.ServiceCache_URICacheHitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].KernelURICacheHits),
|
float64(dst_cache[0].KernelURICacheHits),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsCached,
|
c.ServiceCache_URIsCached,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst_cache[0].CurrentURIsCached),
|
float64(dst_cache[0].CurrentURIsCached),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsCached,
|
c.ServiceCache_URIsCached,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst_cache[0].KernelCurrentURIsCached),
|
float64(dst_cache[0].KernelCurrentURIsCached),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsCachedTotal,
|
c.ServiceCache_URIsCachedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalURIsCached),
|
float64(dst_cache[0].TotalURIsCached),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsCachedTotal,
|
c.ServiceCache_URIsCachedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].KernelTotalURIsCached),
|
float64(dst_cache[0].KernelTotalURIsCached),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsFlushedTotal,
|
c.ServiceCache_URIsFlushedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedURIs),
|
float64(dst_cache[0].TotalFlushedURIs),
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_URIsFlushedTotal,
|
c.ServiceCache_URIsFlushedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].KernelTotalFlushedURIs),
|
float64(dst_cache[0].KernelTotalFlushedURIs),
|
||||||
"kernel",
|
"kernel",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataCached,
|
c.ServiceCache_MetadataCached,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst_cache[0].CurrentMetadataCached),
|
float64(dst_cache[0].CurrentMetadataCached),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataCacheFlushes,
|
c.ServiceCache_MetadataCacheFlushes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedMetadata),
|
float64(dst_cache[0].TotalFlushedMetadata),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataCacheQueriesTotal,
|
c.ServiceCache_MetadataCacheQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].MetadataCacheHits+dst_cache[0].MetadataCacheMisses),
|
float64(dst_cache[0].MetadataCacheHits+dst_cache[0].MetadataCacheMisses),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataCacheHitsTotal,
|
c.ServiceCache_MetadataCacheHitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].MetadataCacheHits),
|
float64(dst_cache[0].MetadataCacheHits),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataCachedTotal,
|
c.ServiceCache_MetadataCachedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalMetadataCached),
|
float64(dst_cache[0].TotalMetadataCached),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_MetadataFlushedTotal,
|
c.ServiceCache_MetadataFlushedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].TotalFlushedMetadata),
|
float64(dst_cache[0].TotalFlushedMetadata),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheActiveFlushedItems,
|
c.ServiceCache_OutputCacheActiveFlushedItems,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheCurrentFlushedItems),
|
float64(dst_cache[0].OutputCacheCurrentFlushedItems),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheItems,
|
c.ServiceCache_OutputCacheItems,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheCurrentItems),
|
float64(dst_cache[0].OutputCacheCurrentItems),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheMemoryUsage,
|
c.ServiceCache_OutputCacheMemoryUsage,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheCurrentMemoryUsage),
|
float64(dst_cache[0].OutputCacheCurrentMemoryUsage),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheQueriesTotal,
|
c.ServiceCache_OutputCacheQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheTotalHits+dst_cache[0].OutputCacheTotalMisses),
|
float64(dst_cache[0].OutputCacheTotalHits+dst_cache[0].OutputCacheTotalMisses),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheHitsTotal,
|
c.ServiceCache_OutputCacheHitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheTotalHits),
|
float64(dst_cache[0].OutputCacheTotalHits),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheFlushedItemsTotal,
|
c.ServiceCache_OutputCacheFlushedItemsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheTotalFlushedItems),
|
float64(dst_cache[0].OutputCacheTotalFlushedItems),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ServiceCache_OutputCacheFlushesTotal,
|
c.ServiceCache_OutputCacheFlushesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst_cache[0].OutputCacheTotalFlushes),
|
float64(dst_cache[0].OutputCacheTotalFlushes),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
|
|||||||
|
|
||||||
func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
|
var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
"github.com/StackExchange/wmi"
|
||||||
@@ -34,10 +33,7 @@ type Win32_PerfRawData_MSMQ_MSMQQueueCollector struct {
|
|||||||
func NewMSMQCollector() (Collector, error) {
|
func NewMSMQCollector() (Collector, error) {
|
||||||
const subsystem = "msmq"
|
const subsystem = "msmq"
|
||||||
|
|
||||||
var wc bytes.Buffer
|
|
||||||
if *msmqWhereClause != "" {
|
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!")
|
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"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
queryWhereClause: wc.String(),
|
queryWhereClause: *msmqWhereClause,
|
||||||
}, nil
|
}, 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) {
|
func (c *Win32_PerfRawData_MSMQ_MSMQQueueCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_MSMQ_MSMQQueue
|
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 {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
3535
collector/mssql.go
Normal file
3535
collector/mssql.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -169,7 +169,7 @@ type Win32_PerfRawData_Tcpip_NetworkInterface struct {
|
|||||||
func (c *NetworkCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NetworkCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_Tcpip_NetworkInterface
|
var dst []Win32_PerfRawData_Tcpip_NetworkInterface
|
||||||
|
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ type Win32_PerfRawData_NETFramework_NETCLRExceptions struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRExceptionsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRExceptionsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRInteropCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRInteropCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ type Win32_PerfRawData_NETFramework_NETCLRJit struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRJitCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRJitCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLoading struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRLoadingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRLoadingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRLocksAndThreadsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRLocksAndThreadsCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ type Win32_PerfRawData_NETFramework_NETCLRMemory struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRMemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRMemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ type Win32_PerfRawData_NETFramework_NETCLRRemoting struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRRemotingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRRemotingCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ type Win32_PerfRawData_NETFramework_NETCLRSecurity struct {
|
|||||||
|
|
||||||
func (c *NETFramework_NETCLRSecurityCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *NETFramework_NETCLRSecurityCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ type Win32_OperatingSystem struct {
|
|||||||
|
|
||||||
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_OperatingSystem
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -47,11 +46,7 @@ type ProcessCollector struct {
|
|||||||
func NewProcessCollector() (Collector, error) {
|
func NewProcessCollector() (Collector, error) {
|
||||||
const subsystem = "process"
|
const subsystem = "process"
|
||||||
|
|
||||||
var wc bytes.Buffer
|
if *processWhereClause == "" {
|
||||||
if *processWhereClause != "" {
|
|
||||||
wc.WriteString("WHERE ")
|
|
||||||
wc.WriteString(*processWhereClause)
|
|
||||||
} else {
|
|
||||||
log.Warn("No where-clause specified for process collector. This will generate a very large number of metrics!")
|
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"},
|
[]string{"process", "process_id", "creating_process_id"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
queryWhereClause: wc.String(),
|
queryWhereClause: *processWhereClause,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,13 +177,22 @@ type Win32_PerfRawData_PerfProc_Process struct {
|
|||||||
WorkingSetPrivate uint64
|
WorkingSetPrivate uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WorkerProcess struct {
|
||||||
|
AppPoolName string
|
||||||
|
ProcessId uint32
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfProc_Process
|
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 {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dst_wp []WorkerProcess
|
||||||
|
q_wp := queryAll(&dst_wp)
|
||||||
|
wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration")
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Total" {
|
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)
|
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
|
||||||
cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 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(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StartTime,
|
c.StartTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
"github.com/StackExchange/wmi"
|
||||||
@@ -36,11 +35,7 @@ type serviceCollector struct {
|
|||||||
func NewserviceCollector() (Collector, error) {
|
func NewserviceCollector() (Collector, error) {
|
||||||
const subsystem = "service"
|
const subsystem = "service"
|
||||||
|
|
||||||
var wc bytes.Buffer
|
if *serviceWhereClause == "" {
|
||||||
if *serviceWhereClause != "" {
|
|
||||||
wc.WriteString("WHERE ")
|
|
||||||
wc.WriteString(*serviceWhereClause)
|
|
||||||
} else {
|
|
||||||
log.Warn("No where-clause specified for service collector. This will generate a very large number of metrics!")
|
log.Warn("No where-clause specified for service collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +58,7 @@ func NewserviceCollector() (Collector, error) {
|
|||||||
[]string{"name", "status"},
|
[]string{"name", "status"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
queryWhereClause: wc.String(),
|
queryWhereClause: *serviceWhereClause,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +115,7 @@ var (
|
|||||||
|
|
||||||
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_Service
|
var dst []Win32_Service
|
||||||
q := wmi.CreateQuery(&dst, c.queryWhereClause)
|
q := queryAllWhere(&dst, c.queryWhereClause)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ type Win32_PerfRawData_PerfOS_System struct {
|
|||||||
|
|
||||||
func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfOS_System
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ type Win32_PerfRawData_Tcpip_TCPv4 struct {
|
|||||||
func (c *TCPCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *TCPCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_Tcpip_TCPv4
|
var dst []Win32_PerfRawData_Tcpip_TCPv4
|
||||||
|
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ type Win32_PerfRawData_vmGuestLib_VCPU struct {
|
|||||||
|
|
||||||
func (c *VmwareCollector) collectMem(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *VmwareCollector) collectMem(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@ func mbToBytes(mb uint64) float64 {
|
|||||||
|
|
||||||
func (c *VmwareCollector) collectCpu(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *VmwareCollector) collectCpu(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"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)
|
Collect(ch chan<- prometheus.Metric) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is adapted from StackExchange/wmi/wmi.go, and lets us change the class
|
func className(src interface{}) string {
|
||||||
// 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 ")
|
|
||||||
s := reflect.Indirect(reflect.ValueOf(src))
|
s := reflect.Indirect(reflect.ValueOf(src))
|
||||||
t := s.Type()
|
t := s.Type()
|
||||||
if s.Kind() == reflect.Slice {
|
if s.Kind() == reflect.Slice {
|
||||||
t = t.Elem()
|
t = t.Elem()
|
||||||
}
|
}
|
||||||
if t.Kind() != reflect.Struct {
|
return t.Name()
|
||||||
return ""
|
}
|
||||||
}
|
|
||||||
var fields []string
|
func queryAll(src interface{}) string {
|
||||||
for i := 0; i < t.NumField(); i++ {
|
var b bytes.Buffer
|
||||||
fields = append(fields, t.Field(i).Name)
|
b.WriteString("SELECT * FROM ")
|
||||||
}
|
b.WriteString(className(src))
|
||||||
b.WriteString(strings.Join(fields, ", "))
|
|
||||||
b.WriteString(" FROM ")
|
log.Debugf("Generated WMI query %s", b.String())
|
||||||
b.WriteString(class)
|
return b.String()
|
||||||
b.WriteString(" " + where)
|
}
|
||||||
|
|
||||||
|
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()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|||||||
115
collector/wmi_test.go
Normal file
115
collector/wmi_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,7 +47,7 @@ var (
|
|||||||
|
|
||||||
// This can be removed when client_golang exposes this on Windows
|
// This can be removed when client_golang exposes this on Windows
|
||||||
// (See https://github.com/prometheus/client_golang/issues/376)
|
// (See https://github.com/prometheus/client_golang/issues/376)
|
||||||
startTime = float64(time.Now().Unix())
|
startTime = float64(time.Now().Unix())
|
||||||
startTimeDesc = prometheus.NewDesc(
|
startTimeDesc = prometheus.NewDesc(
|
||||||
"process_start_time_seconds",
|
"process_start_time_seconds",
|
||||||
"Start time of the process since unix epoch in seconds.",
|
"Start time of the process since unix epoch in seconds.",
|
||||||
@@ -169,6 +169,7 @@ func initWbem() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
wmi.DefaultClient.AllowMissingFields = true
|
||||||
wmi.DefaultClient.SWbemServicesClient = s
|
wmi.DefaultClient.SWbemServicesClient = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type {{ .Class }} struct {
|
|||||||
}
|
}
|
||||||
func (c *{{ .CollectorName }}Collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *{{ .CollectorName }}Collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []{{ .Class }}
|
var dst []{{ .Class }}
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user