Skip to content

Instantly share code, notes, and snippets.

@jsturtevant
Created November 30, 2022 01:01
Show Gist options
  • Save jsturtevant/a7da98d6139b133eeb72576ef362fd95 to your computer and use it in GitHub Desktop.
Save jsturtevant/a7da98d6139b133eeb72576ef362fd95 to your computer and use it in GitHub Desktop.
func windowsCpuAndMemoryStats(stats *types.Metric) (*runtime.WindowsContainerStats, error) {
var cs runtime.WindowsContainerStats
if stats != nil {
s, err := typeurl.UnmarshalAny(stats.Data)
if err != nil {
return nil, fmt.Errorf("failed to extract container metrics: %w", err)
}
wstats := s.(*wstats.Statistics).GetWindows()
if wstats == nil {
return nil, fmt.Errorf("windows stats is empty")
}
if wstats.Processor != nil {
cs.Cpu = &runtime.WindowsCpuUsage{
Timestamp: wstats.Timestamp.UnixNano(),
UsageCoreNanoSeconds: &runtime.UInt64Value{Value: wstats.Processor.TotalRuntimeNS},
}
}
if wstats.Memory != nil {
cs.Memory = &runtime.WindowsMemoryUsage{
Timestamp: wstats.Timestamp.UnixNano(),
WorkingSetBytes: &runtime.UInt64Value{
Value: wstats.Memory.MemoryUsagePrivateWorkingSetBytes,
},
}
}
}
return &cs, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment