mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-01 08:06:38 +00:00
os: export values in bytes, improve naming of labels
This commit is contained in:
@@ -16,6 +16,12 @@ os | Exposes Win32_OperatingSystem metrics (memory, processes, users)
|
|||||||
perf | Exposes Win32_PerfRawData_PerfDisk_LogicalDisk metrics (disk I/O)
|
perf | Exposes Win32_PerfRawData_PerfDisk_LogicalDisk metrics (disk I/O)
|
||||||
|
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
* expose Win32_Process
|
||||||
|
* improve naming in accordance with https://prometheus.io/docs/instrumenting/writing_exporters/#naming
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Under [MIT](LICENSE)
|
Under [MIT](LICENSE)
|
||||||
|
|||||||
128
collectors/os.go
128
collectors/os.go
@@ -13,88 +13,88 @@ import (
|
|||||||
|
|
||||||
// A OSCollector is a Prometheus collector for WMI Win32_OperatingSystem metrics
|
// A OSCollector is a Prometheus collector for WMI Win32_OperatingSystem metrics
|
||||||
type OSCollector struct {
|
type OSCollector struct {
|
||||||
FreePhysicalMemory *prometheus.Desc
|
FreePhysicalMemoryBytes *prometheus.Desc
|
||||||
FreeSpaceInPagingFiles *prometheus.Desc
|
FreeSpaceInPagingFilesBytes *prometheus.Desc
|
||||||
FreeVirtualMemory *prometheus.Desc
|
FreeVirtualMemoryBytes *prometheus.Desc
|
||||||
MaxNumberOfProcesses *prometheus.Desc
|
ProcessesMax *prometheus.Desc
|
||||||
MaxProcessMemorySize *prometheus.Desc
|
ProcessMemoryBytesBytes *prometheus.Desc
|
||||||
NumberOfProcesses *prometheus.Desc
|
Processes *prometheus.Desc
|
||||||
NumberOfUsers *prometheus.Desc
|
Users *prometheus.Desc
|
||||||
SizeStoredInPagingFiles *prometheus.Desc
|
SizeStoredInPagingFilesBytes *prometheus.Desc
|
||||||
TotalVirtualMemorySize *prometheus.Desc
|
VirtualMemoryBytesTotal *prometheus.Desc
|
||||||
TotalVisibleMemorySize *prometheus.Desc
|
VisibleMemoryBytesTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOSCollector ...
|
// NewOSCollector ...
|
||||||
func NewOSCollector() *OSCollector {
|
func NewOSCollector() *OSCollector {
|
||||||
|
|
||||||
return &OSCollector{
|
return &OSCollector{
|
||||||
FreePhysicalMemory: prometheus.NewDesc(
|
FreePhysicalMemoryBytes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory"),
|
prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory_bytes"),
|
||||||
"Number, in kilobytes, of physical memory currently unused and available.",
|
"Physical memory currently unused and available.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
FreeSpaceInPagingFiles: prometheus.NewDesc(
|
FreeSpaceInPagingFilesBytes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files"),
|
prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files_bytes"),
|
||||||
"Number, in kilobytes, that can be mapped into the operating system paging files without causing any other pages to be swapped out.",
|
"Number of bytes that can be mapped into the operating system paging files without causing any other pages to be swapped out.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
FreeVirtualMemory: prometheus.NewDesc(
|
FreeVirtualMemoryBytes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory"),
|
prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory_bytes"),
|
||||||
"Number, in kilobytes, of virtual memory currently unused and available.",
|
"Virtual memory currently unused and available.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
MaxNumberOfProcesses: prometheus.NewDesc(
|
ProcessesMax: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "max_number_of_processes"),
|
prometheus.BuildFQName(wmiNamespace, "os", "processes_max"),
|
||||||
"Maximum number of process contexts the operating system can support.",
|
"Maximum number of process contexts the operating system can support.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
MaxProcessMemorySize: prometheus.NewDesc(
|
ProcessMemoryBytesBytes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "max_process_memory_size"),
|
prometheus.BuildFQName(wmiNamespace, "os", "process_memory_bytes_max"),
|
||||||
"Maximum number, in kilobytes, of memory that can be allocated to a process.",
|
"Maximum bytes of memory that can be allocated to a process.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
NumberOfProcesses: prometheus.NewDesc(
|
Processes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "number_of_processes"),
|
prometheus.BuildFQName(wmiNamespace, "os", "processes"),
|
||||||
"Number of process contexts currently loaded or running on the operating system.",
|
"Number of process contexts currently loaded or running on the operating system.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
NumberOfUsers: prometheus.NewDesc(
|
Users: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "number_of_users"),
|
prometheus.BuildFQName(wmiNamespace, "os", "users"),
|
||||||
"Number of user sessions for which the operating system is storing state information currently.",
|
"Number of user sessions for which the operating system is storing state information currently.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
SizeStoredInPagingFiles: prometheus.NewDesc(
|
SizeStoredInPagingFilesBytes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "size_stored_in_paging_files"),
|
prometheus.BuildFQName(wmiNamespace, "os", "size_stored_in_paging_files_bytes"),
|
||||||
"Total number of kilobytes that can be stored in the operating system paging files.",
|
"Total number of bytes that can be stored in the operating system paging files.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
TotalVirtualMemorySize: prometheus.NewDesc(
|
VirtualMemoryBytesTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "total_virtual_memory_size"),
|
prometheus.BuildFQName(wmiNamespace, "os", "virtual_memory_bytes_total"),
|
||||||
"Number, in kilobytes, of virtual memory.",
|
"Total amount of virtual memory.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
||||||
TotalVisibleMemorySize: prometheus.NewDesc(
|
VisibleMemoryBytesTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(wmiNamespace, "os", "total_visible_memory_size"),
|
prometheus.BuildFQName(wmiNamespace, "os", "visible_memory_bytes_total"),
|
||||||
"Total amount, in kilobytes, of physical memory available to the operating system.",
|
"Total amount of physical memory available to the operating system.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
@@ -114,16 +114,16 @@ func (c *OSCollector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
// The corresponding metric values are sent separately.
|
// The corresponding metric values are sent separately.
|
||||||
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {
|
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
|
||||||
ch <- c.FreePhysicalMemory
|
ch <- c.FreePhysicalMemoryBytes
|
||||||
ch <- c.FreeSpaceInPagingFiles
|
ch <- c.FreeSpaceInPagingFilesBytes
|
||||||
ch <- c.FreeVirtualMemory
|
ch <- c.FreeVirtualMemoryBytes
|
||||||
ch <- c.MaxNumberOfProcesses
|
ch <- c.ProcessesMax
|
||||||
ch <- c.MaxProcessMemorySize
|
ch <- c.ProcessMemoryBytesBytes
|
||||||
ch <- c.NumberOfProcesses
|
ch <- c.Processes
|
||||||
ch <- c.NumberOfUsers
|
ch <- c.Users
|
||||||
ch <- c.SizeStoredInPagingFiles
|
ch <- c.SizeStoredInPagingFilesBytes
|
||||||
ch <- c.TotalVirtualMemorySize
|
ch <- c.VirtualMemoryBytesTotal
|
||||||
ch <- c.TotalVisibleMemorySize
|
ch <- c.VisibleMemoryBytesTotal
|
||||||
}
|
}
|
||||||
|
|
||||||
type Win32_OperatingSystem struct {
|
type Win32_OperatingSystem struct {
|
||||||
@@ -149,63 +149,63 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreePhysicalMemory,
|
c.FreePhysicalMemoryBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].FreePhysicalMemory),
|
float64(dst[0].FreePhysicalMemory*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeSpaceInPagingFiles,
|
c.FreeSpaceInPagingFilesBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].FreeSpaceInPagingFiles),
|
float64(dst[0].FreeSpaceInPagingFiles*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeVirtualMemory,
|
c.FreeVirtualMemoryBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].FreeVirtualMemory),
|
float64(dst[0].FreeVirtualMemory*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MaxNumberOfProcesses,
|
c.ProcessesMax,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].MaxNumberOfProcesses),
|
float64(dst[0].MaxNumberOfProcesses),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MaxProcessMemorySize,
|
c.ProcessMemoryBytesBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].MaxProcessMemorySize),
|
float64(dst[0].MaxProcessMemorySize*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberOfProcesses,
|
c.Processes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].NumberOfProcesses),
|
float64(dst[0].NumberOfProcesses),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberOfUsers,
|
c.Users,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].NumberOfUsers),
|
float64(dst[0].NumberOfUsers),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SizeStoredInPagingFiles,
|
c.SizeStoredInPagingFilesBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].SizeStoredInPagingFiles),
|
float64(dst[0].SizeStoredInPagingFiles*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalVirtualMemorySize,
|
c.VirtualMemoryBytesTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TotalVirtualMemorySize),
|
float64(dst[0].TotalVirtualMemorySize*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalVisibleMemorySize,
|
c.VisibleMemoryBytesTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TotalVisibleMemorySize),
|
float64(dst[0].TotalVisibleMemorySize*1024), // KiB -> bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user