Skip to content

metricbeat/module/windows/perfmon: report the instance count of a single instance - #54934

Open
srednoff888-art wants to merge 1 commit into
elastic:mainfrom
srednoff888-art:fix/perfmon-single-instance-count
Open

srednoff888-art wants to merge 1 commit into
elastic:mainfrom
srednoff888-art:fix/perfmon-single-instance-count

Conversation

@srednoff888-art

Copy link
Copy Markdown

Proposed commit message

With perfmon.group_all_counter, groupToSingleEvent left the instance count
out when it was 1, to keep it off the counters that have no instances to
count, such as _Total. So iis.webserver.process.worker_process_count was
missing on a server with one w3wp process.

Decide by the query instead: report the count for counters queried with a
wildcard instance, whatever it is. All counters of a namespace write the
same field in map order, and one of them can miss the value of an instance,
so report the highest count of the namespace.

Assisted-By: Claude Code

The iis.webserver queries show why the val == 1 check can't just be removed. Web Service(_Total), ASP.NET Applications(__Total__), ASP.NET and Web Service Cache all have exactly one value, and would each get a worker_process_count of 1. Only Process(w3wp*) has instances to count. isWildcard, which the reader already uses when it adds counters, tells them apart.

Counts above 1 are reported as before, also for queries without a wildcard.

The highest count matters once 1 is reported. With two worker processes, a rate counter such as % Processor Time can skip one of them (PDH_CALC_NEGATIVE_VALUE), and its count of 1 could then overwrite the 2 of the other process.* counters, depending on map order.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. worker_process_count is now also present when it is 1. iis.webserver is the only metricset in this repository that sets perfmon.group_all_counter.

How to test this PR locally

On Windows:

go test -v -run 'TestGroupToSingleEvent' ./metricbeat/module/windows/perfmon/

TestGroupToSingleEventInstanceCount/one_instance_of_a_wildcard fails without the change; the other cases keep the rest of the behavior in place. All the tests of the package pass on Windows 10 (amd64). I did not run them with the race detector.

I also ran the reader against real counters on that machine, with group_all_counter set and the instances explorer* (one process), svchost* (many), nosuchprocess* and _Total:

instance before after
explorer* no count 1
svchost* 79 78
nosuchprocess* no count no count
_Total no count no count

(The number of svchost processes changed between the two runs.) I don't have an IIS server to run the iis.webserver metricset itself.

Related issues

…gle instance

With perfmon.group_all_counter, groupToSingleEvent left the instance count
out when it was 1, to keep it off the counters that have no instances to
count, such as _Total. So iis.webserver.process.worker_process_count was
missing on a server with one w3wp process.

Decide by the query instead: report the count for counters queried with a
wildcard instance, whatever it is. All counters of a namespace write the
same field in map order, and one of them can miss the value of an instance,
so report the highest count of the namespace.

Assisted-By: Claude Code
@srednoff888-art
srednoff888-art requested a review from a team as a code owner November 25, 2026 22:07
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 25, 2026
@botelastic

botelastic Bot commented Nov 25, 2026

Copy link
Copy Markdown

This pull request doesn't have a Team:<team> label.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@mergify

mergify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @srednoff888-art? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@mergify

mergify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs_team Indicates that the issue/PR needs a Team:* label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metricbeat][IIS] webserver: worker_process_count not reported when exactly one w3wp process is running

1 participant