(container *runtimeapi.Container)
| 26 | ) |
| 27 | |
| 28 | func (ds *dockerService) getContainerStats(container *runtimeapi.Container) (*runtimeapi.ContainerStats, error) { |
| 29 | containerID := container.Id |
| 30 | statsJSON, err := ds.client.GetContainerStats(containerID) |
| 31 | if err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | |
| 35 | dockerStats := statsJSON.Stats |
| 36 | timestamp := time.Now().UnixNano() |
| 37 | containerStats := &runtimeapi.ContainerStats{ |
| 38 | Attributes: &runtimeapi.ContainerAttributes{ |
| 39 | Id: containerID, |
| 40 | Metadata: container.Metadata, |
| 41 | Labels: container.Labels, |
| 42 | Annotations: container.Annotations, |
| 43 | }, |
| 44 | Cpu: &runtimeapi.CpuUsage{ |
| 45 | Timestamp: timestamp, |
| 46 | UsageCoreNanoSeconds: &runtimeapi.UInt64Value{ |
| 47 | Value: dockerStats.CPUStats.CPUUsage.TotalUsage, |
| 48 | }, |
| 49 | }, |
| 50 | Memory: &runtimeapi.MemoryUsage{ |
| 51 | Timestamp: timestamp, |
| 52 | WorkingSetBytes: &runtimeapi.UInt64Value{ |
| 53 | Value: dockerStats.MemoryStats.Usage, |
| 54 | }, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | cstat := ds.containerStatsCache.getStats(containerID) |
| 59 | if cstat != nil && cstat.isInitialized() { |
| 60 | containerStats.WritableLayer = &runtimeapi.FilesystemUsage{ |
| 61 | Timestamp: timestamp, |
| 62 | FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: ds.dockerRootDir}, |
| 63 | UsedBytes: &runtimeapi.UInt64Value{Value: cstat.getContainerRWSize()}, |
| 64 | } |
| 65 | } |
| 66 | return containerStats, nil |
| 67 | } |
no test coverage detected