0.38.6_agent_hotfix
This commit is contained in:
1 parent
1239ff524d
commit
d4a604970e
14 files changed
+478
-162
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type agentHealthMetrics struct {
|
||||
RSSBytes *uint64 `json:"rss_bytes,omitempty"`
|
||||
HeapAllocBytes uint64 `json:"go_heap_alloc_bytes"`
|
||||
Goroutines int `json:"goroutines"`
|
||||
OpenFDs *int `json:"open_fds,omitempty"`
|
||||
}
|
||||
|
||||
// agentDiagnostics is an authenticated, on-demand snapshot. No background
|
||||
// goroutine, accumulating history, or extra public health endpoint is needed.
|
||||
func agentDiagnostics() agentHealthMetrics {
|
||||
var memory runtime.MemStats
|
||||
runtime.ReadMemStats(&memory)
|
||||
result := agentHealthMetrics{HeapAllocBytes: memory.HeapAlloc, Goroutines: runtime.NumGoroutine()}
|
||||
// Linux agents expose RSS and descriptor counts in /proc. On unsupported
|
||||
// platforms omit these fields instead of incorrectly calling heap RSS.
|
||||
if fields := strings.Fields(readTrimmed("/proc/self/statm")); len(fields) >= 2 {
|
||||
if resident, err := strconv.ParseUint(fields[1], 10, 64); err == nil {
|
||||
rss := resident * uint64(os.Getpagesize())
|
||||
result.RSSBytes = &rss
|
||||
}
|
||||
}
|
||||
if entries, err := os.ReadDir("/proc/self/fd"); err == nil {
|
||||
count := len(entries)
|
||||
result.OpenFDs = &count
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in new issue
Block a user