Skip to content

Add Windows metric for process handle counts #21379

Closed
@braydonk

Description

@braydonk

Component(s)

receiver/hostmetrics

Is your feature request related to a problem? Please describe.

I would like a metric for a process' Handle Count in Windows.

Describe the solution you'd like

I would like to add a gauge metric in hostmetrics called process.handles, which represents the process' handle count at time of collection.

Each scrape, the receiver would do a NtQuerySystemInformation syscall with the info class SystemProcessInformation, which responds with information for all processes including each process' handle count. For each pid, we would get the handle count from the syscall results and record the datapoint.

Describe alternatives you've considered

I have opened shirou/gopsutil#1455 with an accompanying example PR to implement this in gopsutil. This would bring this metric in-line with the implementation of all other process metrics, but this has 2 major issues:

  1. The gopsutil API is inflexible for a piece of process information that is exclusive to a single platform like this. NumFDs is not the same as a process' handle count in Windows.
  2. This is extremely inefficient. It requires doing a full syscall for all handles on the system for every single process we scrape metrics for.

Additional context

This StackExchange answer contains a good summary of what handles are in Windows: https://superuser.com/questions/1065826/handles-vs-threads-vs-processes

NtQuerySystemInformation syscall docs: https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntquerysysteminformation
Specifically this sections of the syscall docs is relevant: https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntquerysysteminformation#systemprocessinformation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions