os: export values in bytes, improve naming of labels

This commit is contained in:
Martin Lindhe 2016-08-26 11:35:31 +02:00
parent 79cc2d8fed
commit 6d299670f9
2 changed files with 70 additions and 64 deletions

View File

@ -16,6 +16,12 @@ os | Exposes Win32_OperatingSystem metrics (memory, processes, users)
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
Under [MIT](LICENSE)

View File

@ -13,88 +13,88 @@ import (
// A OSCollector is a Prometheus collector for WMI Win32_OperatingSystem metrics
type OSCollector struct {
FreePhysicalMemory *prometheus.Desc
FreeSpaceInPagingFiles *prometheus.Desc
FreeVirtualMemory *prometheus.Desc
MaxNumberOfProcesses *prometheus.Desc
MaxProcessMemorySize *prometheus.Desc
NumberOfProcesses *prometheus.Desc
NumberOfUsers *prometheus.Desc
SizeStoredInPagingFiles *prometheus.Desc
TotalVirtualMemorySize *prometheus.Desc
TotalVisibleMemorySize *prometheus.Desc
FreePhysicalMemoryBytes *prometheus.Desc
FreeSpaceInPagingFilesBytes *prometheus.Desc
FreeVirtualMemoryBytes *prometheus.Desc
ProcessesMax *prometheus.Desc
ProcessMemoryBytesBytes *prometheus.Desc
Processes *prometheus.Desc
Users *prometheus.Desc
SizeStoredInPagingFilesBytes *prometheus.Desc
VirtualMemoryBytesTotal *prometheus.Desc
VisibleMemoryBytesTotal *prometheus.Desc
}
// NewOSCollector ...
func NewOSCollector() *OSCollector {
return &OSCollector{
FreePhysicalMemory: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory"),
"Number, in kilobytes, of physical memory currently unused and available.",
FreePhysicalMemoryBytes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory_bytes"),
"Physical memory currently unused and available.",
nil,
nil,
),
FreeSpaceInPagingFiles: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files"),
"Number, in kilobytes, that can be mapped into the operating system paging files without causing any other pages to be swapped out.",
FreeSpaceInPagingFilesBytes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files_bytes"),
"Number of bytes that can be mapped into the operating system paging files without causing any other pages to be swapped out.",
nil,
nil,
),
FreeVirtualMemory: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory"),
"Number, in kilobytes, of virtual memory currently unused and available.",
FreeVirtualMemoryBytes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory_bytes"),
"Virtual memory currently unused and available.",
nil,
nil,
),
MaxNumberOfProcesses: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "max_number_of_processes"),
ProcessesMax: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "processes_max"),
"Maximum number of process contexts the operating system can support.",
nil,
nil,
),
MaxProcessMemorySize: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "max_process_memory_size"),
"Maximum number, in kilobytes, of memory that can be allocated to a process.",
ProcessMemoryBytesBytes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "process_memory_bytes_max"),
"Maximum bytes of memory that can be allocated to a process.",
nil,
nil,
),
NumberOfProcesses: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "number_of_processes"),
Processes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "processes"),
"Number of process contexts currently loaded or running on the operating system.",
nil,
nil,
),
NumberOfUsers: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "number_of_users"),
Users: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "users"),
"Number of user sessions for which the operating system is storing state information currently.",
nil,
nil,
),
SizeStoredInPagingFiles: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "size_stored_in_paging_files"),
"Total number of kilobytes that can be stored in the operating system paging files.",
SizeStoredInPagingFilesBytes: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "size_stored_in_paging_files_bytes"),
"Total number of bytes that can be stored in the operating system paging files.",
nil,
nil,
),
TotalVirtualMemorySize: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "total_virtual_memory_size"),
"Number, in kilobytes, of virtual memory.",
VirtualMemoryBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "virtual_memory_bytes_total"),
"Total amount of virtual memory.",
nil,
nil,
),
TotalVisibleMemorySize: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "total_visible_memory_size"),
"Total amount, in kilobytes, of physical memory available to the operating system.",
VisibleMemoryBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(wmiNamespace, "os", "visible_memory_bytes_total"),
"Total amount of physical memory available to the operating system.",
nil,
nil,
),
@ -114,16 +114,16 @@ func (c *OSCollector) Collect(ch chan<- prometheus.Metric) {
// The corresponding metric values are sent separately.
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.FreePhysicalMemory
ch <- c.FreeSpaceInPagingFiles
ch <- c.FreeVirtualMemory
ch <- c.MaxNumberOfProcesses
ch <- c.MaxProcessMemorySize
ch <- c.NumberOfProcesses
ch <- c.NumberOfUsers
ch <- c.SizeStoredInPagingFiles
ch <- c.TotalVirtualMemorySize
ch <- c.TotalVisibleMemorySize
ch <- c.FreePhysicalMemoryBytes
ch <- c.FreeSpaceInPagingFilesBytes
ch <- c.FreeVirtualMemoryBytes
ch <- c.ProcessesMax
ch <- c.ProcessMemoryBytesBytes
ch <- c.Processes
ch <- c.Users
ch <- c.SizeStoredInPagingFilesBytes
ch <- c.VirtualMemoryBytesTotal
ch <- c.VisibleMemoryBytesTotal
}
type Win32_OperatingSystem struct {
@ -149,63 +149,63 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
}
ch <- prometheus.MustNewConstMetric(
c.FreePhysicalMemory,
c.FreePhysicalMemoryBytes,
prometheus.GaugeValue,
float64(dst[0].FreePhysicalMemory),
float64(dst[0].FreePhysicalMemory*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.FreeSpaceInPagingFiles,
c.FreeSpaceInPagingFilesBytes,
prometheus.GaugeValue,
float64(dst[0].FreeSpaceInPagingFiles),
float64(dst[0].FreeSpaceInPagingFiles*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.FreeVirtualMemory,
c.FreeVirtualMemoryBytes,
prometheus.GaugeValue,
float64(dst[0].FreeVirtualMemory),
float64(dst[0].FreeVirtualMemory*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.MaxNumberOfProcesses,
c.ProcessesMax,
prometheus.GaugeValue,
float64(dst[0].MaxNumberOfProcesses),
)
ch <- prometheus.MustNewConstMetric(
c.MaxProcessMemorySize,
c.ProcessMemoryBytesBytes,
prometheus.GaugeValue,
float64(dst[0].MaxProcessMemorySize),
float64(dst[0].MaxProcessMemorySize*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.NumberOfProcesses,
c.Processes,
prometheus.GaugeValue,
float64(dst[0].NumberOfProcesses),
)
ch <- prometheus.MustNewConstMetric(
c.NumberOfUsers,
c.Users,
prometheus.GaugeValue,
float64(dst[0].NumberOfUsers),
)
ch <- prometheus.MustNewConstMetric(
c.SizeStoredInPagingFiles,
c.SizeStoredInPagingFilesBytes,
prometheus.GaugeValue,
float64(dst[0].SizeStoredInPagingFiles),
float64(dst[0].SizeStoredInPagingFiles*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.TotalVirtualMemorySize,
c.VirtualMemoryBytesTotal,
prometheus.GaugeValue,
float64(dst[0].TotalVirtualMemorySize),
float64(dst[0].TotalVirtualMemorySize*1024), // KiB -> bytes
)
ch <- prometheus.MustNewConstMetric(
c.TotalVisibleMemorySize,
c.VisibleMemoryBytesTotal,
prometheus.GaugeValue,
float64(dst[0].TotalVisibleMemorySize),
float64(dst[0].TotalVisibleMemorySize*1024), // KiB -> bytes
)
return nil, nil