mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
system: Metric windows_system_boot_time_timestamp returns a UNIX timestamp again. (#1967)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de> Signed-off-by: Jan-Otto Kröpke <github@jkroepke.de>
This commit is contained in:
@@ -16,7 +16,7 @@ None
|
|||||||
|
|
||||||
| Name | Description | Type | Labels |
|
| Name | Description | Type | Labels |
|
||||||
|----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
|
|----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
|
||||||
| `windows_system_boot_time_timestamp_seconds` | Unix timestamp of last system boot | gauge | None |
|
| `windows_system_boot_time_timestamp` | Unix timestamp of last system boot | gauge | None |
|
||||||
| `windows_system_context_switches_total` | Total number of [context switches](https://en.wikipedia.org/wiki/Context_switch) | counter | None |
|
| `windows_system_context_switches_total` | Total number of [context switches](https://en.wikipedia.org/wiki/Context_switch) | counter | None |
|
||||||
| `windows_system_exception_dispatches_total` | Total exceptions dispatched by the system | counter | None |
|
| `windows_system_exception_dispatches_total` | Total exceptions dispatched by the system | counter | None |
|
||||||
| `windows_system_processes` | Number of process contexts currently loaded or running on the operating system | gauge | None |
|
| `windows_system_processes` | Number of process contexts currently loaded or running on the operating system | gauge | None |
|
||||||
@@ -41,7 +41,7 @@ windows_system_processes{instance="localhost"}
|
|||||||
## Useful queries
|
## Useful queries
|
||||||
Find hosts that have rebooted in the last 24 hours
|
Find hosts that have rebooted in the last 24 hours
|
||||||
```
|
```
|
||||||
time() - windows_system_boot_time_timestamp_seconds < 86400
|
time() - windows_system_boot_time_timestamp < 86400
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alerting examples
|
## Alerting examples
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ package system
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
"github.com/prometheus-community/windows_exporter/internal/headers/kernel32"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/pdh"
|
"github.com/prometheus-community/windows_exporter/internal/pdh"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
@@ -39,6 +41,8 @@ var ConfigDefaults = Config{}
|
|||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
|
||||||
|
bootTimeTimestamp float64
|
||||||
|
|
||||||
perfDataCollector *pdh.Collector
|
perfDataCollector *pdh.Collector
|
||||||
perfDataObject []perfDataCounterValues
|
perfDataObject []perfDataCounterValues
|
||||||
|
|
||||||
@@ -48,8 +52,10 @@ type Collector struct {
|
|||||||
processes *prometheus.Desc
|
processes *prometheus.Desc
|
||||||
processesLimit *prometheus.Desc
|
processesLimit *prometheus.Desc
|
||||||
systemCallsTotal *prometheus.Desc
|
systemCallsTotal *prometheus.Desc
|
||||||
bootTime *prometheus.Desc
|
// Deprecated: Use windows_system_boot_time_timestamp instead
|
||||||
threads *prometheus.Desc
|
bootTimeSeconds *prometheus.Desc
|
||||||
|
bootTime *prometheus.Desc
|
||||||
|
threads *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *Config) *Collector {
|
func New(config *Config) *Collector {
|
||||||
@@ -80,11 +86,17 @@ func (c *Collector) Close() error {
|
|||||||
|
|
||||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||||
c.bootTime = prometheus.NewDesc(
|
c.bootTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "boot_time_timestamp_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "boot_time_timestamp"),
|
||||||
"Unix timestamp of system boot time",
|
"Unix timestamp of system boot time",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
c.bootTimeSeconds = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(types.Namespace, Name, "boot_time_timestamp_seconds"),
|
||||||
|
"Deprecated: Use windows_system_boot_time_timestamp instead",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
c.contextSwitchesTotal = prometheus.NewDesc(
|
c.contextSwitchesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
||||||
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
||||||
@@ -129,6 +141,8 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
|||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
c.bootTimeTimestamp = float64(time.Now().Unix() - int64(kernel32.GetTickCount64()/1000))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues](pdh.CounterTypeRaw, "System", nil)
|
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues](pdh.CounterTypeRaw, "System", nil)
|
||||||
@@ -172,17 +186,24 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
|||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
c.perfDataObject[0].SystemCallsPerSec,
|
c.perfDataObject[0].SystemCallsPerSec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.bootTime,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
c.perfDataObject[0].SystemUpTime,
|
|
||||||
)
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.threads,
|
c.threads,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
c.perfDataObject[0].Threads,
|
c.perfDataObject[0].Threads,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.bootTimeSeconds,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
c.bootTimeTimestamp,
|
||||||
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.bootTime,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
c.bootTimeTimestamp,
|
||||||
|
)
|
||||||
|
|
||||||
// Windows has no defined limit, and is based off available resources. This currently isn't calculated by WMI and is set to default value.
|
// Windows has no defined limit, and is based off available resources. This currently isn't calculated by WMI and is set to default value.
|
||||||
// https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-processes-and-threads/ba-p/723824
|
// https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-processes-and-threads/ba-p/723824
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem
|
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ type perfDataCounterValues struct {
|
|||||||
ExceptionDispatchesPerSec float64 `perfdata:"Exception Dispatches/sec"`
|
ExceptionDispatchesPerSec float64 `perfdata:"Exception Dispatches/sec"`
|
||||||
ProcessorQueueLength float64 `perfdata:"Processor Queue Length"`
|
ProcessorQueueLength float64 `perfdata:"Processor Queue Length"`
|
||||||
SystemCallsPerSec float64 `perfdata:"System Calls/sec"`
|
SystemCallsPerSec float64 `perfdata:"System Calls/sec"`
|
||||||
SystemUpTime float64 `perfdata:"System Up Time"`
|
|
||||||
Processes float64 `perfdata:"Processes"`
|
Processes float64 `perfdata:"Processes"`
|
||||||
Threads float64 `perfdata:"Threads"`
|
Threads float64 `perfdata:"Threads"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ import (
|
|||||||
|
|
||||||
//nolint:gochecknoglobals
|
//nolint:gochecknoglobals
|
||||||
var (
|
var (
|
||||||
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||||
|
|
||||||
procGetDynamicTimeZoneInformationSys = kernel32.NewProc("GetDynamicTimeZoneInformation")
|
procGetDynamicTimeZoneInformationSys = modkernel32.NewProc("GetDynamicTimeZoneInformation")
|
||||||
kernelLocalFileTimeToFileTime = kernel32.NewProc("LocalFileTimeToFileTime")
|
procKernelLocalFileTimeToFileTime = modkernel32.NewProc("LocalFileTimeToFileTime")
|
||||||
|
procGetTickCount = modkernel32.NewProc("GetTickCount64")
|
||||||
)
|
)
|
||||||
|
|
||||||
// SYSTEMTIME contains a date and time.
|
// SYSTEMTIME contains a date and time.
|
||||||
@@ -72,9 +73,15 @@ func GetDynamicTimeZoneInformation() (DynamicTimezoneInformation, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LocalFileTimeToFileTime(localFileTime, utcFileTime *windows.Filetime) uint32 {
|
func LocalFileTimeToFileTime(localFileTime, utcFileTime *windows.Filetime) uint32 {
|
||||||
ret, _, _ := kernelLocalFileTimeToFileTime.Call(
|
ret, _, _ := procKernelLocalFileTimeToFileTime.Call(
|
||||||
uintptr(unsafe.Pointer(localFileTime)),
|
uintptr(unsafe.Pointer(localFileTime)),
|
||||||
uintptr(unsafe.Pointer(utcFileTime)))
|
uintptr(unsafe.Pointer(utcFileTime)))
|
||||||
|
|
||||||
return uint32(ret)
|
return uint32(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTickCount64() uint64 {
|
||||||
|
ret, _, _ := procGetTickCount.Call()
|
||||||
|
|
||||||
|
return uint64(ret)
|
||||||
|
}
|
||||||
|
|||||||
@@ -393,7 +393,9 @@ windows_service_state{name="Themes",state="running"} 1
|
|||||||
windows_service_state{name="Themes",state="start pending"} 0
|
windows_service_state{name="Themes",state="start pending"} 0
|
||||||
windows_service_state{name="Themes",state="stop pending"} 0
|
windows_service_state{name="Themes",state="stop pending"} 0
|
||||||
windows_service_state{name="Themes",state="stopped"} 0
|
windows_service_state{name="Themes",state="stopped"} 0
|
||||||
# HELP windows_system_boot_time_timestamp_seconds Unix timestamp of system boot time
|
# HELP windows_system_boot_time_timestamp Unix timestamp of system boot time
|
||||||
|
# TYPE windows_system_boot_time_timestamp gauge
|
||||||
|
# HELP windows_system_boot_time_timestamp_seconds Deprecated: Use windows_system_boot_time_timestamp instead
|
||||||
# TYPE windows_system_boot_time_timestamp_seconds gauge
|
# TYPE windows_system_boot_time_timestamp_seconds gauge
|
||||||
# HELP windows_system_context_switches_total Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)
|
# HELP windows_system_context_switches_total Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)
|
||||||
# TYPE windows_system_context_switches_total counter
|
# TYPE windows_system_context_switches_total counter
|
||||||
|
|||||||
Reference in New Issue
Block a user