github.com/georgethebeatle/containerd@v0.2.5/supervisor/stats.go (about)

     1  package supervisor
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/docker/containerd/runtime"
     7  )
     8  
     9  // StatsTask holds needed parameters to retrieve a container statistics
    10  type StatsTask struct {
    11  	baseTask
    12  	ID   string
    13  	Stat chan *runtime.Stat
    14  }
    15  
    16  func (s *Supervisor) stats(t *StatsTask) error {
    17  	start := time.Now()
    18  	i, ok := s.containers[t.ID]
    19  	if !ok {
    20  		return ErrContainerNotFound
    21  	}
    22  	// TODO: use workers for this
    23  	go func() {
    24  		s, err := i.container.Stats()
    25  		if err != nil {
    26  			t.ErrorCh() <- err
    27  			return
    28  		}
    29  		t.ErrorCh() <- nil
    30  		t.Stat <- s
    31  		ContainerStatsTimer.UpdateSince(start)
    32  	}()
    33  	return errDeferredResponse
    34  }