mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2025-04-18 19:24:05 +03:00
fix: windows_cpu_processor_utility_total is always 0 (#1966)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
parent
ef46cd1dbe
commit
9db4318ea9
2
.github/workflows/pr-check.yaml
vendored
2
.github/workflows/pr-check.yaml
vendored
@ -37,7 +37,7 @@ jobs:
|
||||
- name: check
|
||||
run: |
|
||||
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" == "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" == "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
|
||||
fi
|
||||
|
||||
|
@ -122,6 +122,11 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
||||
continue
|
||||
}
|
||||
|
||||
secondValue := strings.HasSuffix(counterName, ",secondvalue")
|
||||
if secondValue {
|
||||
counterName = strings.TrimSuffix(counterName, ",secondvalue")
|
||||
}
|
||||
|
||||
var counter Counter
|
||||
if counter, ok = collector.counters[counterName]; !ok {
|
||||
counter = Counter{
|
||||
@ -132,9 +137,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasSuffix(counterName, ",secondvalue") {
|
||||
counterName = strings.TrimSuffix(counterName, ",secondvalue")
|
||||
|
||||
if secondValue {
|
||||
counter.FieldIndexSecondValue = f.Index[0]
|
||||
} else {
|
||||
counter.FieldIndexValue = f.Index[0]
|
||||
@ -206,9 +209,6 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
||||
}
|
||||
|
||||
counter.Type = counterInfo.DwType
|
||||
counter.Desc = windows.UTF16PtrToString(counterInfo.SzExplainText)
|
||||
counter.Desc = windows.UTF16PtrToString(counterInfo.SzExplainText)
|
||||
|
||||
if val, ok := SupportedCounterTypes[counter.Type]; ok {
|
||||
counter.MetricType = val
|
||||
} else {
|
||||
|
@ -31,6 +31,7 @@ func NewCounter(lastValue uint32) Counter {
|
||||
|
||||
func (c *Counter) AddValue(value uint32) {
|
||||
c.totalValue += float64(value - c.lastValue)
|
||||
c.lastValue = value
|
||||
}
|
||||
|
||||
func (c *Counter) Value() float64 {
|
||||
|
@ -20,20 +20,36 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCounter(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user