MCPcopy Create free account
hub / github.com/containerd/cgroups / Stat

Method Stat

cgroup1/cgroup.go:302–346  ·  view source on GitHub ↗

Stat returns the current metrics for the cgroup

(handlers ...ErrorHandler)

Source from the content-addressed store, hash-verified

300
301// Stat returns the current metrics for the cgroup
302func (c *cgroup) Stat(handlers ...ErrorHandler) (*v1.Metrics, error) {
303 c.mu.Lock()
304 defer c.mu.Unlock()
305 if c.err != nil {
306 return nil, c.err
307 }
308 if len(handlers) == 0 {
309 handlers = append(handlers, errPassthrough)
310 }
311 var (
312 stats = &v1.Metrics{
313 CPU: &v1.CPUStat{
314 Throttling: &v1.Throttle{},
315 Usage: &v1.CPUUsage{},
316 },
317 }
318 wg = &sync.WaitGroup{}
319 errs = make(chan error, len(c.subsystems))
320 )
321 for _, s := range c.subsystems {
322 if ss, ok := s.(stater); ok {
323 sp, err := c.path(s.Name())
324 if err != nil {
325 return nil, err
326 }
327 wg.Add(1)
328 go func() {
329 defer wg.Done()
330 if err := ss.Stat(sp, stats); err != nil {
331 for _, eh := range handlers {
332 if herr := eh(err); herr != nil {
333 errs <- herr
334 }
335 }
336 }
337 }()
338 }
339 }
340 wg.Wait()
341 close(errs)
342 for err := range errs {
343 return nil, err
344 }
345 return stats, nil
346}
347
348// Update updates the cgroup with the new resource values provided
349//

Callers

nothing calls this directly

Calls 3

NameMethod · 0.65
AddMethod · 0.65
StatMethod · 0.65

Tested by

no test coverage detected