mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-26 22:56:36 +00:00
chore: Refactor Config Collector API (#1558)
This commit is contained in:
18
exporter.go
18
exporter.go
@@ -38,9 +38,6 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
|
||||
const PROCESS_ALL_ACCESS = windows.STANDARD_RIGHTS_REQUIRED | windows.SYNCHRONIZE | windows.SPECIFIC_RIGHTS_ALL
|
||||
|
||||
// Same struct prometheus uses for their /version endpoint.
|
||||
// Separate copy to avoid pulling all of prometheus as a dependency.
|
||||
type prometheusVersion struct {
|
||||
@@ -63,18 +60,23 @@ var priorityStringToInt = map[string]uint32{
|
||||
}
|
||||
|
||||
func setPriorityWindows(pid int, priority uint32) error {
|
||||
handle, err := windows.OpenProcess(PROCESS_ALL_ACCESS, false, uint32(pid))
|
||||
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
|
||||
handle, err := windows.OpenProcess(
|
||||
windows.STANDARD_RIGHTS_REQUIRED|windows.SYNCHRONIZE|windows.SPECIFIC_RIGHTS_ALL,
|
||||
false, uint32(pid),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//nolint:errcheck
|
||||
defer windows.CloseHandle(handle) // Technically this can fail, but we ignore it
|
||||
|
||||
err = windows.SetPriorityClass(handle, priority)
|
||||
if err != nil {
|
||||
if err = windows.SetPriorityClass(handle, priority); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = windows.CloseHandle(handle); err != nil {
|
||||
return fmt.Errorf("failed to close handle: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user