diff --git a/docs/collector.performancecounter.md b/docs/collector.performancecounter.md index 977fcb88..6ed78c3a 100644 --- a/docs/collector.performancecounter.md +++ b/docs/collector.performancecounter.md @@ -50,10 +50,14 @@ YAML: instances: ["*"] instance_label: "core" counters: - - name: "% Processor Time" + - name: "% User Time" metric: windows_performancecounter_processor_information_processor_time_total # optional labels: - state: active + state: user + - name: "% Privileged Time" + metric: windows_performancecounter_processor_information_processor_time_total # optional + labels: + state: privileged - name: "% Idle Time" metric: windows_performancecounter_processor_information_processor_time_total # optional labels: @@ -84,10 +88,17 @@ YAML: "instance_label": "core", "counters": [ { - "name": "% Processor Time", + "name": "% User Time", "metric": "windows_performancecounter_processor_information_processor_time_total", "labels": { - "state": "active" + "state": "user" + } + }, + { + "name": "% Privileged Time", + "metric": "windows_performancecounter_processor_information_processor_time_total", + "labels": { + "state": "privileged" } }, { @@ -207,8 +218,16 @@ keep counting up. If the multiplier is the reciprocal of an integer, like `0.001 the value is divided by that integer instead, which avoids rounding artifacts such as `0.009000000000000001`. If not specified, the value is exported as is. -With the `raw` type, `PERF_100NSEC_TIMER_INV` counters such as `% Processor Time` are not converted to seconds -and arrive in 100 ns ticks; a multiplier of `1e-7` converts them. +With the object `type` `raw`, the default, some counters are already converted +to seconds, so do not scale them again: `PERF_100NSEC_TIMER` and +`PERF_PRECISION_100NS_TIMER` counters such as `% Idle Time` are exported in +seconds, and `PERF_ELAPSED_TIME` counters such as `Process\Elapsed Time` as +seconds since the start. `PERF_100NSEC_TIMER_INV` counters such as +`% Processor Time` are not converted and arrive in 100 ns ticks of inactive time +(for `% Processor Time`, the idle time); a multiplier of `1e-7` converts them to +seconds. `PERF_AVERAGE_TIMER` counters such as `Avg. Disk sec/Read` count ticks +of the performance timer, whose frequency depends on the host, so a fixed +multiplier does not fit them; use the `formatted` type for them. This key is optional. @@ -222,60 +241,24 @@ Otherwise, they would produce identical series and the collector fails to start. ### Example ``` -# HELP windows_performancecounter_memory_cache_faults_total -# TYPE windows_performancecounter_memory_cache_faults_total counter -windows_performancecounter_memory_cache_faults_total 7.028097e+06 -# HELP windows_performancecounter_processor_information_processor_time_total +# HELP windows_performancecounter_memory_cache_faults_per_second windows_exporter: custom Performance Counter metric +# TYPE windows_performancecounter_memory_cache_faults_per_second gauge +windows_performancecounter_memory_cache_faults_per_second 0 +# HELP windows_performancecounter_processor_information_processor_time_total windows_exporter: custom Performance Counter metric # TYPE windows_performancecounter_processor_information_processor_time_total counter -windows_performancecounter_processor_information_processor_time_total{core="0,0",state="active"} 8.3809375e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,0",state="idle"} 8380.9375 -windows_performancecounter_processor_information_processor_time_total{core="0,1",state="active"} 8.2868125e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,1",state="idle"} 8286.8125 -windows_performancecounter_processor_information_processor_time_total{core="0,10",state="active"} 9.720046875e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,10",state="idle"} 9720.046875 -windows_performancecounter_processor_information_processor_time_total{core="0,11",state="active"} 9.994921875e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,11",state="idle"} 9994.921875 -windows_performancecounter_processor_information_processor_time_total{core="0,12",state="active"} 1.014403125e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,12",state="idle"} 10144.03125 -windows_performancecounter_processor_information_processor_time_total{core="0,13",state="active"} 1.0155453125e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,13",state="idle"} 10155.453125 -windows_performancecounter_processor_information_processor_time_total{core="0,14",state="active"} 1.01290625e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,14",state="idle"} 10129.0625 -windows_performancecounter_processor_information_processor_time_total{core="0,15",state="active"} 1.0134890625e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,15",state="idle"} 10134.890625 -windows_performancecounter_processor_information_processor_time_total{core="0,16",state="active"} 1.01405625e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,16",state="idle"} 10140.5625 -windows_performancecounter_processor_information_processor_time_total{core="0,17",state="active"} 1.0153421875e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,17",state="idle"} 10153.421875 -windows_performancecounter_processor_information_processor_time_total{core="0,18",state="active"} 1.0086390625e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,18",state="idle"} 10086.390625 -windows_performancecounter_processor_information_processor_time_total{core="0,19",state="active"} 1.0123453125e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,19",state="idle"} 10123.453125 -windows_performancecounter_processor_information_processor_time_total{core="0,2",state="active"} 8.3548125e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,2",state="idle"} 8354.8125 -windows_performancecounter_processor_information_processor_time_total{core="0,20",state="active"} 1.011703125e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,20",state="idle"} 10117.03125 -windows_performancecounter_processor_information_processor_time_total{core="0,21",state="active"} 1.0140984375e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,21",state="idle"} 10140.984375 -windows_performancecounter_processor_information_processor_time_total{core="0,22",state="active"} 1.014615625e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,22",state="idle"} 10146.15625 -windows_performancecounter_processor_information_processor_time_total{core="0,23",state="active"} 1.0145125e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,23",state="idle"} 10145.125 -windows_performancecounter_processor_information_processor_time_total{core="0,3",state="active"} 8.488953125e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,3",state="idle"} 8488.953125 -windows_performancecounter_processor_information_processor_time_total{core="0,4",state="active"} 9.338234375e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,4",state="idle"} 9338.234375 -windows_performancecounter_processor_information_processor_time_total{core="0,5",state="active"} 9.776453125e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,5",state="idle"} 9776.453125 -windows_performancecounter_processor_information_processor_time_total{core="0,6",state="active"} 9.736265625e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,6",state="idle"} 9736.265625 -windows_performancecounter_processor_information_processor_time_total{core="0,7",state="active"} 9.959375e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,7",state="idle"} 9959.375 -windows_performancecounter_processor_information_processor_time_total{core="0,8",state="active"} 9.939421875e+10 -windows_performancecounter_processor_information_processor_time_total{core="0,8",state="idle"} 9939.421875 -windows_performancecounter_processor_information_processor_time_total{core="0,9",state="active"} 1.0059484375e+11 -windows_performancecounter_processor_information_processor_time_total{core="0,9",state="idle"} 10059.484375 +windows_performancecounter_processor_information_processor_time_total{core="0,0",state="idle"} 92831.8125 +windows_performancecounter_processor_information_processor_time_total{core="0,0",state="privileged"} 28957.421875 +windows_performancecounter_processor_information_processor_time_total{core="0,0",state="user"} 12147.921875 +windows_performancecounter_processor_information_processor_time_total{core="0,1",state="idle"} 92790.4375 +windows_performancecounter_processor_information_processor_time_total{core="0,1",state="privileged"} 26724.78125 +windows_performancecounter_processor_information_processor_time_total{core="0,1",state="user"} 14421.8125 +windows_performancecounter_processor_information_processor_time_total{core="0,2",state="idle"} 91185.484375 +windows_performancecounter_processor_information_processor_time_total{core="0,2",state="privileged"} 27029.34375 +windows_performancecounter_processor_information_processor_time_total{core="0,2",state="user"} 15722.203125 ``` + +The memory gauge reads `0` here because the output comes from a single scrape: a formatted rate such as +`Cache Faults/sec` needs two samples, so it reports a value from the second scrape on. > [!NOTE] > If you are using a configuration file, the value must be keep as string. diff --git a/internal/collector/performancecounter/performancecounter_test_test.go b/internal/collector/performancecounter/performancecounter_test_test.go index 11f01034..2e8fc668 100644 --- a/internal/collector/performancecounter/performancecounter_test_test.go +++ b/internal/collector/performancecounter/performancecounter_test_test.go @@ -442,8 +442,8 @@ func TestCollectorMetricTypePerCounter(t *testing.T) { } // TestCollectorMultiplier checks that the multiplier scales the exported value. -// Commit Limit only changes when a page file is resized, so both objects read -// the same value. +// Commit Limit only changes when a page file grows or is resized, which is +// unlikely between the two reads, so both objects read the same value. func TestCollectorMultiplier(t *testing.T) { t.Parallel() diff --git a/internal/multiplier/multiplier.go b/internal/multiplier/multiplier.go index 038b829c..b2aa09f8 100644 --- a/internal/multiplier/multiplier.go +++ b/internal/multiplier/multiplier.go @@ -23,8 +23,8 @@ import ( "math" ) -// maxExactInteger is the largest integer up to which every integer has an -// exact float64 representation. +// maxExactInteger bounds the divisor. Beyond it, several integers round to the +// same reciprocal, so the rounded divisor may not be the one the user meant. const maxExactInteger = 1 << 53 // Multiplier scales values. The zero value leaves them unchanged. diff --git a/internal/multiplier/multiplier_test.go b/internal/multiplier/multiplier_test.go index fe44b897..d3e51e61 100644 --- a/internal/multiplier/multiplier_test.go +++ b/internal/multiplier/multiplier_test.go @@ -61,8 +61,8 @@ func TestNewInvalid(t *testing.T) { } // TestApplyDividesExactly checks that a multiplier that is the reciprocal of -// an integer gives the correctly rounded quotient, which a plain -// multiplication misses for about one in seven values. +// an integer gives the correctly rounded quotient. A plain multiplication +// misses it for some values, for example 9 * 0.001. func TestApplyDividesExactly(t *testing.T) { t.Parallel()