mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 12:16:36 +00:00
refactor: rename namespace to 'collector'
This commit is contained in:
504
collector/iis.go
Normal file
504
collector/iis.go
Normal file
@@ -0,0 +1,504 @@
|
||||
// returns data points from Win32_PerfRawData_W3SVC_WebService
|
||||
// https://msdn.microsoft.com/en-us/library/aa394345.aspx - Win32_OperatingSystem class
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
siteWhitelist = flag.String("collector.iis.site-whitelist", ".+", "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.")
|
||||
siteBlacklist = flag.String("collector.iis.site-blacklist", "", "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.")
|
||||
)
|
||||
|
||||
// A IISCollector is a Prometheus collector for WMI Win32_PerfRawData_W3SVC_WebService metrics
|
||||
type IISCollector struct {
|
||||
CurrentAnonymousUsers *prometheus.Desc
|
||||
CurrentBlockedAsyncIORequests *prometheus.Desc
|
||||
CurrentCGIRequests *prometheus.Desc
|
||||
CurrentConnections *prometheus.Desc
|
||||
CurrentISAPIExtensionRequests *prometheus.Desc
|
||||
CurrentNonAnonymousUsers *prometheus.Desc
|
||||
|
||||
TotalBytesReceived *prometheus.Desc
|
||||
TotalBytesSent *prometheus.Desc
|
||||
TotalAnonymousUsers *prometheus.Desc
|
||||
TotalBlockedAsyncIORequests *prometheus.Desc
|
||||
TotalCGIRequests *prometheus.Desc
|
||||
TotalConnectionAttemptsAllInstances *prometheus.Desc
|
||||
TotalRequests *prometheus.Desc
|
||||
TotalFilesReceived *prometheus.Desc
|
||||
TotalFilesSent *prometheus.Desc
|
||||
TotalISAPIExtensionRequests *prometheus.Desc
|
||||
TotalLockedErrors *prometheus.Desc
|
||||
TotalLogonAttempts *prometheus.Desc
|
||||
TotalNonAnonymousUsers *prometheus.Desc
|
||||
TotalNotFoundErrors *prometheus.Desc
|
||||
TotalRejectedAsyncIORequests *prometheus.Desc
|
||||
|
||||
siteWhitelistPattern *regexp.Regexp
|
||||
siteBlacklistPattern *regexp.Regexp
|
||||
}
|
||||
|
||||
// NewIISCollector ...
|
||||
func NewIISCollector() *IISCollector {
|
||||
const subsystem = "iis"
|
||||
|
||||
return &IISCollector{
|
||||
// Gauges
|
||||
CurrentAnonymousUsers: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_anonymous_users"),
|
||||
"Number of users who currently have an anonymous connection using the Web service (WebService.CurrentAnonymousUsers)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
CurrentBlockedAsyncIORequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_blocked_async_io_requests"),
|
||||
"Current requests temporarily blocked due to bandwidth throttling settings (WebService.CurrentBlockedAsyncIORequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
CurrentCGIRequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_cgi_requests"),
|
||||
"Current number of CGI requests being simultaneously processed by the Web service (WebService.CurrentCGIRequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
CurrentConnections: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_connections"),
|
||||
"Current number of connections established with the Web service (WebService.CurrentConnections)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
CurrentISAPIExtensionRequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_isapi_extension_requests"),
|
||||
"Current number of ISAPI requests being simultaneously processed by the Web service (WebService.CurrentISAPIExtensionRequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
CurrentNonAnonymousUsers: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "current_non_anonymous_users"),
|
||||
"Number of users who currently have a non-anonymous connection using the Web service (WebService.CurrentNonAnonymousUsers)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
|
||||
// Counters
|
||||
TotalBytesReceived: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "received_bytes_total"),
|
||||
"Number of data bytes that have been received by the Web service (WebService.TotalBytesReceived)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalBytesSent: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "sent_bytes_total"),
|
||||
"Number of data bytes that have been sent by the Web service (WebService.TotalBytesSent)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalAnonymousUsers: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "anonymous_users_total"),
|
||||
"Total number of users who established an anonymous connection with the Web service (WebService.TotalAnonymousUsers)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalBlockedAsyncIORequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "blocked_async_io_requests_total"),
|
||||
"Total requests temporarily blocked due to bandwidth throttling settings (WebService.TotalBlockedAsyncIORequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalCGIRequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "cgi_requests_total"),
|
||||
"Total CGI requests is the total number of CGI requests (WebService.TotalCGIRequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalConnectionAttemptsAllInstances: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "connection_attempts_all_instances_total"),
|
||||
"Number of connections that have been attempted using the Web service (WebService.TotalConnectionAttemptsAllInstances)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalRequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "requests_total"),
|
||||
"Number of HTTP requests (WebService.TotalRequests)",
|
||||
[]string{"site", "method"},
|
||||
nil,
|
||||
),
|
||||
TotalFilesReceived: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "files_received_total"),
|
||||
"Number of files received by the Web service (WebService.TotalFilesReceived)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalFilesSent: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "files_sent_total"),
|
||||
"Number of files sent by the Web service (WebService.TotalFilesSent)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalISAPIExtensionRequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "ipapi_extension_requests_total"),
|
||||
"ISAPI Extension Requests received (WebService.TotalISAPIExtensionRequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalLockedErrors: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "locked_errors_total"),
|
||||
"Number of requests that couldn't be satisfied by the server because the requested resource was locked (WebService.TotalLockedErrors)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalLogonAttempts: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "logon_attempts_total"),
|
||||
"Number of logons attempts to the Web Service (WebService.TotalLogonAttempts)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalNonAnonymousUsers: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "non_anonymous_users_total"),
|
||||
"Number of users who established a non-anonymous connection with the Web service (WebService.TotalNonAnonymousUsers)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalNotFoundErrors: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "not_found_errors_total"),
|
||||
"Number of requests that couldn't be satisfied by the server because the requested document could not be found (WebService.TotalNotFoundErrors)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
TotalRejectedAsyncIORequests: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "rejected_async_io_requests_total"),
|
||||
"Requests rejected due to bandwidth throttling settings (WebService.TotalRejectedAsyncIORequests)",
|
||||
[]string{"site"},
|
||||
nil,
|
||||
),
|
||||
|
||||
siteWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
|
||||
siteBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
|
||||
}
|
||||
}
|
||||
|
||||
// Collect sends the metric values for each metric
|
||||
// to the provided prometheus Metric channel.
|
||||
func (c *IISCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
if desc, err := c.collect(ch); err != nil {
|
||||
log.Println("[ERROR] failed collecting iis metrics:", desc, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Describe sends the descriptors of each metric over to the provided channel.
|
||||
// The corresponding metric values are sent separately.
|
||||
func (c *IISCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_W3SVC_WebService struct {
|
||||
Name string
|
||||
|
||||
CurrentAnonymousUsers uint32
|
||||
CurrentBlockedAsyncIORequests uint32
|
||||
CurrentCGIRequests uint32
|
||||
CurrentConnections uint32
|
||||
CurrentISAPIExtensionRequests uint32
|
||||
CurrentNonAnonymousUsers uint32
|
||||
|
||||
TotalBytesSent uint64
|
||||
TotalBytesReceived uint64
|
||||
TotalAnonymousUsers uint32
|
||||
TotalBlockedAsyncIORequests uint32
|
||||
TotalCGIRequests uint32
|
||||
TotalConnectionAttemptsAllInstances uint32
|
||||
TotalCopyRequests uint32
|
||||
TotalDeleteRequests uint32
|
||||
TotalFilesReceived uint32
|
||||
TotalFilesSent uint32
|
||||
TotalGetRequests uint32
|
||||
TotalHeadRequests uint32
|
||||
TotalISAPIExtensionRequests uint32
|
||||
TotalLockedErrors uint32
|
||||
TotalLockRequests uint32
|
||||
TotalLogonAttempts uint32
|
||||
TotalMethodRequests uint32
|
||||
TotalMethodRequestsPerSec uint32
|
||||
TotalMkcolRequests uint32
|
||||
TotalMoveRequests uint32
|
||||
TotalNonAnonymousUsers uint32
|
||||
TotalNotFoundErrors uint32
|
||||
TotalOptionsRequests uint32
|
||||
TotalOtherRequestMethods uint32
|
||||
TotalPostRequests uint32
|
||||
TotalPropfindRequests uint32
|
||||
TotalProppatchRequests uint32
|
||||
TotalPutRequests uint32
|
||||
TotalRejectedAsyncIORequests uint32
|
||||
TotalSearchRequests uint32
|
||||
TotalTraceRequests uint32
|
||||
TotalUnlockRequests uint32
|
||||
}
|
||||
|
||||
func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
var dst []Win32_PerfRawData_W3SVC_WebService
|
||||
q := wmi.CreateQuery(&dst, "")
|
||||
if err := wmi.Query(q, &dst); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, site := range dst {
|
||||
if site.Name == "_Total" ||
|
||||
c.siteBlacklistPattern.MatchString(site.Name) ||
|
||||
!c.siteWhitelistPattern.MatchString(site.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Gauges
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentAnonymousUsers,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentAnonymousUsers),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentBlockedAsyncIORequests,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentBlockedAsyncIORequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentCGIRequests,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentCGIRequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentConnections,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentConnections),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentISAPIExtensionRequests,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentISAPIExtensionRequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.CurrentNonAnonymousUsers,
|
||||
prometheus.GaugeValue,
|
||||
float64(site.CurrentNonAnonymousUsers),
|
||||
site.Name,
|
||||
)
|
||||
|
||||
// Counters
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalBytesReceived,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalBytesReceived),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalBytesSent,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalBytesSent),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalAnonymousUsers,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalAnonymousUsers),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalBlockedAsyncIORequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalBlockedAsyncIORequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRejectedAsyncIORequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalRejectedAsyncIORequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalCGIRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalCGIRequests),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalConnectionAttemptsAllInstances,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalConnectionAttemptsAllInstances),
|
||||
site.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalFilesReceived,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalFilesReceived),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalFilesSent,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalFilesSent),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalLockedErrors,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalLockedErrors),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalLogonAttempts,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalLogonAttempts),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalNonAnonymousUsers,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalNonAnonymousUsers),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalNotFoundErrors,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalNotFoundErrors),
|
||||
site.Name,
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalISAPIExtensionRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalISAPIExtensionRequests),
|
||||
site.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalOtherRequestMethods),
|
||||
site.Name,
|
||||
"other",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalCopyRequests),
|
||||
site.Name,
|
||||
"COPY",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalDeleteRequests),
|
||||
site.Name,
|
||||
"DELETE",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalGetRequests),
|
||||
site.Name,
|
||||
"GET",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalHeadRequests),
|
||||
site.Name,
|
||||
"HEAD",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalLockRequests),
|
||||
site.Name,
|
||||
"LOCK",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalMkcolRequests),
|
||||
site.Name,
|
||||
"MKCOL",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalMoveRequests),
|
||||
site.Name,
|
||||
"MOVE",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalOptionsRequests),
|
||||
site.Name,
|
||||
"OPTIONS",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalPostRequests),
|
||||
site.Name,
|
||||
"POST",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalPropfindRequests),
|
||||
site.Name,
|
||||
"PROPFIND",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalProppatchRequests),
|
||||
site.Name,
|
||||
"PROPPATCH",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalPutRequests),
|
||||
site.Name,
|
||||
"PUT",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalSearchRequests),
|
||||
site.Name,
|
||||
"SEARCH",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalTraceRequests),
|
||||
site.Name,
|
||||
"TRACE",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalRequests,
|
||||
prometheus.CounterValue,
|
||||
float64(site.TotalUnlockRequests),
|
||||
site.Name,
|
||||
"UNLOCK",
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
265
collector/logical_disk.go
Normal file
265
collector/logical_disk.go
Normal file
@@ -0,0 +1,265 @@
|
||||
// returns data points from Win32_PerfRawData_PerfDisk_LogicalDisk
|
||||
// https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
|
||||
// https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
ticksToSecondsScaleFactor = 1 / 1e7
|
||||
)
|
||||
|
||||
var (
|
||||
volumeWhitelist = flag.String("collector.logical_disk.volume-whitelist", ".+", "Regexp of volumes to whitelist. Volume name must both match whitelist and not match blacklist to be included.")
|
||||
volumeBlacklist = flag.String("collector.logical_disk.volume-blacklist", "", "Regexp of volumes to blacklist. Volume name must both match whitelist and not match blacklist to be included.")
|
||||
)
|
||||
|
||||
// A LogicalDiskCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfDisk_LogicalDisk metrics
|
||||
type LogicalDiskCollector struct {
|
||||
RequestsQueued *prometheus.Desc
|
||||
ReadBytesTotal *prometheus.Desc
|
||||
ReadsTotal *prometheus.Desc
|
||||
WriteBytesTotal *prometheus.Desc
|
||||
WritesTotal *prometheus.Desc
|
||||
ReadTime *prometheus.Desc
|
||||
WriteTime *prometheus.Desc
|
||||
TotalSpace *prometheus.Desc
|
||||
FreeSpace *prometheus.Desc
|
||||
IdleTime *prometheus.Desc
|
||||
SplitIOs *prometheus.Desc
|
||||
|
||||
volumeWhitelistPattern *regexp.Regexp
|
||||
volumeBlacklistPattern *regexp.Regexp
|
||||
}
|
||||
|
||||
// NewLogicalDiskCollector ...
|
||||
func NewLogicalDiskCollector() *LogicalDiskCollector {
|
||||
const subsystem = "logical_disk"
|
||||
|
||||
return &LogicalDiskCollector{
|
||||
RequestsQueued: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "requests_queued"),
|
||||
"The number of requests queued to the disk (LogicalDisk.CurrentDiskQueueLength)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
ReadBytesTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "read_bytes_total"),
|
||||
"The number of bytes transferred from the disk during read operations (LogicalDisk.DiskReadBytesPerSec)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
ReadsTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "reads_total"),
|
||||
"The number of read operations on the disk (LogicalDisk.DiskReadsPerSec)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
WriteBytesTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "write_bytes_total"),
|
||||
"The number of bytes transferred to the disk during write operations (LogicalDisk.DiskWriteBytesPerSec)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
WritesTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "writes_total"),
|
||||
"The number of write operations on the disk (LogicalDisk.DiskWritesPerSec)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
ReadTime: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "read_seconds_total"),
|
||||
"Seconds that the disk was busy servicing read requests (LogicalDisk.PercentDiskReadTime)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
WriteTime: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "write_seconds_total"),
|
||||
"Seconds that the disk was busy servicing write requests (LogicalDisk.PercentDiskWriteTime)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
FreeSpace: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "free_bytes"),
|
||||
"Free space in bytes (LogicalDisk.PercentFreeSpace)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
TotalSpace: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "size_bytes"),
|
||||
"Total space in bytes (LogicalDisk.PercentFreeSpace_Base)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
IdleTime: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "idle_seconds_total"),
|
||||
"Seconds that the disk was idle (LogicalDisk.PercentIdleTime)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
SplitIOs: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, subsystem, "split_ios_total"),
|
||||
"The number of I/Os to the disk were split into multiple I/Os (LogicalDisk.SplitIOPerSec)",
|
||||
[]string{"volume"},
|
||||
nil,
|
||||
),
|
||||
|
||||
volumeWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeWhitelist)),
|
||||
volumeBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeBlacklist)),
|
||||
}
|
||||
}
|
||||
|
||||
// Collect sends the metric values for each metric
|
||||
// to the provided prometheus Metric channel.
|
||||
func (c *LogicalDiskCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
if desc, err := c.collect(ch); err != nil {
|
||||
log.Println("[ERROR] failed collecting logical_disk metrics:", desc, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Describe sends the descriptors of each metric over to the provided channel.
|
||||
// The corresponding metric values are sent separately.
|
||||
func (c *LogicalDiskCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
|
||||
ch <- c.RequestsQueued
|
||||
ch <- c.ReadBytesTotal
|
||||
ch <- c.ReadsTotal
|
||||
ch <- c.WriteBytesTotal
|
||||
ch <- c.WritesTotal
|
||||
ch <- c.ReadTime
|
||||
ch <- c.WriteTime
|
||||
ch <- c.FreeSpace
|
||||
ch <- c.TotalSpace
|
||||
ch <- c.IdleTime
|
||||
ch <- c.SplitIOs
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
|
||||
Name string
|
||||
CurrentDiskQueueLength uint32
|
||||
DiskReadBytesPerSec uint64
|
||||
DiskReadsPerSec uint32
|
||||
DiskWriteBytesPerSec uint64
|
||||
DiskWritesPerSec uint32
|
||||
PercentDiskReadTime uint64
|
||||
PercentDiskWriteTime uint64
|
||||
PercentFreeSpace uint32
|
||||
PercentFreeSpace_Base uint32
|
||||
PercentIdleTime uint64
|
||||
SplitIOPerSec uint32
|
||||
}
|
||||
|
||||
func (c *LogicalDiskCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
|
||||
q := wmi.CreateQuery(&dst, "")
|
||||
if err := wmi.Query(q, &dst); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, volume := range dst {
|
||||
if volume.Name == "_Total" ||
|
||||
c.volumeBlacklistPattern.MatchString(volume.Name) ||
|
||||
!c.volumeWhitelistPattern.MatchString(volume.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.RequestsQueued,
|
||||
prometheus.GaugeValue,
|
||||
float64(volume.CurrentDiskQueueLength),
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ReadBytesTotal,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.DiskReadBytesPerSec),
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ReadsTotal,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.DiskReadsPerSec),
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.WriteBytesTotal,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.DiskWriteBytesPerSec),
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.WritesTotal,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.DiskWritesPerSec),
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ReadTime,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.PercentDiskReadTime)*ticksToSecondsScaleFactor,
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.WriteTime,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.PercentDiskWriteTime)*ticksToSecondsScaleFactor,
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.FreeSpace,
|
||||
prometheus.GaugeValue,
|
||||
float64(volume.PercentFreeSpace)*1024*1024,
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.TotalSpace,
|
||||
prometheus.GaugeValue,
|
||||
float64(volume.PercentFreeSpace_Base)*1024*1024,
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.IdleTime,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.PercentIdleTime)*ticksToSecondsScaleFactor,
|
||||
volume.Name,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.SplitIOs,
|
||||
prometheus.CounterValue,
|
||||
float64(volume.SplitIOPerSec),
|
||||
volume.Name,
|
||||
)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
210
collector/os.go
Normal file
210
collector/os.go
Normal file
@@ -0,0 +1,210 @@
|
||||
// returns data points from Win32_OperatingSystem
|
||||
// https://msdn.microsoft.com/en-us/library/aa394239 - Win32_OperatingSystem class
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// A OSCollector is a Prometheus collector for WMI Win32_OperatingSystem metrics
|
||||
type OSCollector struct {
|
||||
PhysicalMemoryFreeBytes *prometheus.Desc
|
||||
PagingFreeBytes *prometheus.Desc
|
||||
VirtualMemoryFreeBytes *prometheus.Desc
|
||||
ProcessesMax *prometheus.Desc
|
||||
ProcessMemoryMaxBytes *prometheus.Desc
|
||||
Processes *prometheus.Desc
|
||||
Users *prometheus.Desc
|
||||
PagingMaxBytes *prometheus.Desc
|
||||
VirtualMemoryBytes *prometheus.Desc
|
||||
VisibleMemoryBytes *prometheus.Desc
|
||||
}
|
||||
|
||||
// NewOSCollector ...
|
||||
func NewOSCollector() *OSCollector {
|
||||
|
||||
return &OSCollector{
|
||||
|
||||
PagingMaxBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "paging_max_bytes"),
|
||||
"SizeStoredInPagingFiles",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
PagingFreeBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "paging_free_bytes"),
|
||||
"FreeSpaceInPagingFiles",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
PhysicalMemoryFreeBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "physical_memory_free_bytes"),
|
||||
"FreePhysicalMemory",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
Processes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "processes"),
|
||||
"NumberOfProcesses",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
ProcessesMax: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "processes_max"),
|
||||
"MaxNumberOfProcesses",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
ProcessMemoryMaxBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "process_memory_max_bytes"),
|
||||
"MaxProcessMemorySize",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
Users: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "users"),
|
||||
"NumberOfUsers",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
VirtualMemoryBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "virtual_memory_bytes"),
|
||||
"TotalVirtualMemorySize",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
VisibleMemoryBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "visible_memory_bytes"),
|
||||
"TotalVisibleMemorySize",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
|
||||
VirtualMemoryFreeBytes: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(wmiNamespace, "os", "virtual_memory_free_bytes"),
|
||||
"FreeVirtualMemory",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Collect sends the metric values for each metric
|
||||
// to the provided prometheus Metric channel.
|
||||
func (c *OSCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
if desc, err := c.collect(ch); err != nil {
|
||||
log.Println("[ERROR] failed collecting os metrics:", desc, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Describe sends the descriptors of each metric over to the provided channel.
|
||||
// The corresponding metric values are sent separately.
|
||||
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
|
||||
ch <- c.PhysicalMemoryFreeBytes
|
||||
ch <- c.PagingFreeBytes
|
||||
ch <- c.VirtualMemoryFreeBytes
|
||||
ch <- c.ProcessesMax
|
||||
ch <- c.ProcessMemoryMaxBytes
|
||||
ch <- c.Processes
|
||||
ch <- c.Users
|
||||
ch <- c.PagingMaxBytes
|
||||
ch <- c.VirtualMemoryBytes
|
||||
ch <- c.VisibleMemoryBytes
|
||||
}
|
||||
|
||||
type Win32_OperatingSystem struct {
|
||||
FreePhysicalMemory uint64
|
||||
FreeSpaceInPagingFiles uint64
|
||||
FreeVirtualMemory uint64
|
||||
MaxNumberOfProcesses uint32
|
||||
MaxProcessMemorySize uint64
|
||||
NumberOfProcesses uint32
|
||||
NumberOfUsers uint32
|
||||
SizeStoredInPagingFiles uint64
|
||||
TotalVirtualMemorySize uint64
|
||||
TotalVisibleMemorySize uint64
|
||||
}
|
||||
|
||||
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||
var dst []Win32_OperatingSystem
|
||||
q := wmi.CreateQuery(&dst, "")
|
||||
if err := wmi.Query(q, &dst); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.PhysicalMemoryFreeBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].FreePhysicalMemory*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.PagingFreeBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].FreeSpaceInPagingFiles*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VirtualMemoryFreeBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].FreeVirtualMemory*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ProcessesMax,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].MaxNumberOfProcesses),
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ProcessMemoryMaxBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].MaxProcessMemorySize*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Processes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].NumberOfProcesses),
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Users,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].NumberOfUsers),
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.PagingMaxBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].SizeStoredInPagingFiles*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VirtualMemoryBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].TotalVirtualMemorySize*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.VisibleMemoryBytes,
|
||||
prometheus.GaugeValue,
|
||||
float64(dst[0].TotalVisibleMemorySize*1024), // KiB -> bytes
|
||||
)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
5
collector/wmi.go
Normal file
5
collector/wmi.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package collector
|
||||
|
||||
const (
|
||||
wmiNamespace = "wmi"
|
||||
)
|
||||
Reference in New Issue
Block a user