mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-26 14:46:35 +00:00
fix: windows_cpu_processor_utility_total is always 0 (#1966)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
(cherry picked from commit 9db4318ea9)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
2
.github/workflows/pr-check.yaml
vendored
2
.github/workflows/pr-check.yaml
vendored
@@ -37,7 +37,7 @@ jobs:
|
|||||||
- name: check
|
- name: check
|
||||||
run: |
|
run: |
|
||||||
PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
|
PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
|
||||||
if [[ -d "internal/collector/$PR_TITLE_PREFIX" ]] || [[ -d "internal/$PR_TITLE_PREFIX" ]] || [[ -d "pkg/$PR_TITLE_PREFIX" ]] || [[ -d "$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "docs" ]] || [[ "$PR_TITLE_PREFIX" == "ci" ]] || [[ "$PR_TITLE_PREFIX" == "revert" ]] || [[ "$PR_TITLE_PREFIX" == "fix" ]] || [[ "$PR_TITLE_PREFIX" == "feat" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "chore(docs)" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]] || [[ "$PR_TITLE_PREFIX" == "Synchronize common files from prometheus/prometheus" ]]; then
|
if [[ -d "internal/collector/$PR_TITLE_PREFIX" ]] || [[ -d "internal/$PR_TITLE_PREFIX" ]] || [[ -d "pkg/$PR_TITLE_PREFIX" ]] || [[ -d "$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "docs" ]] || [[ "$PR_TITLE_PREFIX" == "ci" ]] || [[ "$PR_TITLE_PREFIX" == "revert" ]] || [[ "$PR_TITLE_PREFIX" == "fix" ]] || [[ "$PR_TITLE_PREFIX" == "fix(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "feat" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "chore(docs)" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]] || [[ "$PR_TITLE_PREFIX" == "Release"* ]] || [[ "$PR_TITLE_PREFIX" == "Synchronize common files from prometheus/prometheus" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,11 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secondValue := strings.HasSuffix(counterName, ",secondvalue")
|
||||||
|
if secondValue {
|
||||||
|
counterName = strings.TrimSuffix(counterName, ",secondvalue")
|
||||||
|
}
|
||||||
|
|
||||||
var counter Counter
|
var counter Counter
|
||||||
if counter, ok = collector.counters[counterName]; !ok {
|
if counter, ok = collector.counters[counterName]; !ok {
|
||||||
counter = Counter{
|
counter = Counter{
|
||||||
@@ -132,9 +137,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(counterName, ",secondvalue") {
|
if secondValue {
|
||||||
counterName = strings.TrimSuffix(counterName, ",secondvalue")
|
|
||||||
|
|
||||||
counter.FieldIndexSecondValue = f.Index[0]
|
counter.FieldIndexSecondValue = f.Index[0]
|
||||||
} else {
|
} else {
|
||||||
counter.FieldIndexValue = f.Index[0]
|
counter.FieldIndexValue = f.Index[0]
|
||||||
@@ -198,11 +201,14 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ci := (*CounterInfo)(unsafe.Pointer(&buf[0]))
|
counterInfo := (*CounterInfo)(unsafe.Pointer(&buf[0]))
|
||||||
counter.Type = ci.DwType
|
if counterInfo == nil {
|
||||||
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
|
errs = append(errs, errors.New("GetCounterInfo: counter info is nil"))
|
||||||
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
|
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
counter.Type = counterInfo.DwType
|
||||||
if val, ok := SupportedCounterTypes[counter.Type]; ok {
|
if val, ok := SupportedCounterTypes[counter.Type]; ok {
|
||||||
counter.MetricType = val
|
counter.MetricType = val
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func NewCounter(lastValue uint32) Counter {
|
|||||||
|
|
||||||
func (c *Counter) AddValue(value uint32) {
|
func (c *Counter) AddValue(value uint32) {
|
||||||
c.totalValue += float64(value - c.lastValue)
|
c.totalValue += float64(value - c.lastValue)
|
||||||
|
c.lastValue = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Counter) Value() float64 {
|
func (c *Counter) Value() float64 {
|
||||||
|
|||||||
@@ -20,20 +20,36 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCounter(t *testing.T) {
|
func TestCounter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
c := utils.NewCounter(0)
|
c := utils.NewCounter(0)
|
||||||
assert.Equal(t, 0.0, c.Value()) //nolint:testifylint
|
require.Equal(t, 0.0, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
c.AddValue(1)
|
c.AddValue(10)
|
||||||
|
|
||||||
assert.Equal(t, 1.0, c.Value()) //nolint:testifylint
|
require.Equal(t, 10.0, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
c.AddValue(math.MaxUint32)
|
c.AddValue(50)
|
||||||
|
|
||||||
assert.Equal(t, float64(math.MaxUint32)+1.0, c.Value()) //nolint:testifylint
|
require.Equal(t, 50.0, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
|
c.AddValue(math.MaxUint32 - 10)
|
||||||
|
|
||||||
|
require.Equal(t, float64(math.MaxUint32)-10, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
|
c.AddValue(20)
|
||||||
|
|
||||||
|
require.Equal(t, float64(math.MaxUint32)+21, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
|
c.AddValue(40)
|
||||||
|
|
||||||
|
require.Equal(t, float64(math.MaxUint32)+41, c.Value()) //nolint:testifylint
|
||||||
|
|
||||||
|
c.AddValue(math.MaxUint32 - 10)
|
||||||
|
|
||||||
|
require.Equal(t, float64(math.MaxUint32)*2-9, c.Value()) //nolint:testifylint
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user