mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 04:06:36 +00:00
Converted PagingFreeBytes to use perflib
Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/headers/custom"
|
"github.com/prometheus-community/windows_exporter/headers/custom"
|
||||||
@@ -15,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("os", NewOSCollector)
|
registerCollector("os", NewOSCollector, "Paging File")
|
||||||
}
|
}
|
||||||
|
|
||||||
// A OSCollector is a Prometheus collector for WMI metrics
|
// A OSCollector is a Prometheus collector for WMI metrics
|
||||||
@@ -35,6 +36,12 @@ type OSCollector struct {
|
|||||||
Timezone *prometheus.Desc
|
Timezone *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pagingFileCounter struct {
|
||||||
|
Name string
|
||||||
|
Usage float64 `perflib:"% Usage"`
|
||||||
|
UsagePeak float64 `perflib:"% Usage Peak"`
|
||||||
|
}
|
||||||
|
|
||||||
// NewOSCollector ...
|
// NewOSCollector ...
|
||||||
func NewOSCollector() (Collector, error) {
|
func NewOSCollector() (Collector, error) {
|
||||||
const subsystem = "os"
|
const subsystem = "os"
|
||||||
@@ -124,7 +131,7 @@ func NewOSCollector() (Collector, error) {
|
|||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *OSCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *OSCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if desc, err := c.collect(ch); err != nil {
|
if desc, err := c.collect(ctx, ch); err != nil {
|
||||||
log.Error("failed collecting os metrics:", desc, err)
|
log.Error("failed collecting os metrics:", desc, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -149,7 +156,7 @@ type Win32_OperatingSystem struct {
|
|||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
/*var dst []Win32_OperatingSystem
|
/*var dst []Win32_OperatingSystem
|
||||||
q := queryAll(&dst)
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -203,13 +210,31 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
timezoneName,
|
timezoneName,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fsipf, err := custom.GetSizeStoredInPagingFiles()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pfc = make([]pagingFileCounter, 0)
|
||||||
|
if err := unmarshalObject(ctx.perfObjects["Paging File"], &pfc); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pfbPercent float64
|
||||||
|
for _, pageFile := range pfc {
|
||||||
|
if strings.Contains(strings.ToLower(pageFile.Name), "_total") {
|
||||||
|
pfbPercent = pageFile.Usage
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fpbNum := float64(fsipf) - (float64(fsipf) / float64(100) * pfbPercent)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingFreeBytes,
|
c.PagingFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(1234567),
|
float64(fpbNum),
|
||||||
// Cannot find a way to get this without WMI.
|
|
||||||
// Can get from CIM_OperatingSystem which is where WMI gets it from, but I can't figure out how to access this from cimwin32.dll
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-operatingsystem#properties
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
@@ -250,11 +275,6 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
float64(nwgi.Wki102_logged_on_users),
|
float64(nwgi.Wki102_logged_on_users),
|
||||||
)
|
)
|
||||||
|
|
||||||
fsipf, err := custom.GetSizeStoredInPagingFiles()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingLimitBytes,
|
c.PagingLimitBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user