Exemplo n.º 1
0
func (self *hyperContainerHandler) GetStats() (*info.ContainerStats, error) {
	stats := info.ContainerStats{
		Timestamp: time.Now(),
		DiskIo: info.DiskIoStats{
			IoServiceBytes: make([]info.PerDiskStats, 0, 1),
			IoServiced:     make([]info.PerDiskStats, 0, 1),
		},
		Network: info.NetworkStats{
			Interfaces: make([]info.InterfaceStats, 0, 1),
		},
	}

	// TODO: container stats is not supported now
	if !self.isPod {
		return self.fakeStats()
	}

	podStats, err := self.client.GetPodStats(self.podID)
	if err != nil {
		return nil, fmt.Errorf("Failed to get hyper pod stats: %v", err)

	}

	stats.Cpu = info.CpuStats{
		Usage: info.CpuUsage{
			Total:  podStats.Cpu.Usage.Total,
			PerCpu: podStats.Cpu.Usage.PerCpu,
			User:   podStats.Cpu.Usage.User,
			System: podStats.Cpu.Usage.System,
		},
	}

	for _, stat := range podStats.Block.IoServiceBytesRecursive {
		stats.DiskIo.IoServiceBytes = append(stats.DiskIo.IoServiceBytes,
			info.PerDiskStats{
				Major: stat.Major,
				Minor: stat.Minor,
				Stats: stat.Stat,
			})
	}

	for _, stat := range podStats.Block.IoServicedRecursive {
		stats.DiskIo.IoServiced = append(stats.DiskIo.IoServiced,
			info.PerDiskStats{
				Major: stat.Major,
				Minor: stat.Minor,
				Stats: stat.Stat,
			})
	}

	stats.Memory = info.MemoryStats{
		Usage: podStats.Memory.Usage,
	}

	for _, stat := range podStats.Network.Interfaces {
		stats.Network.Interfaces = append(stats.Network.Interfaces,
			info.InterfaceStats{
				Name:      stat.Name,
				RxBytes:   stat.RxBytes,
				RxDropped: stat.RxDropped,
				RxErrors:  stat.RxErrors,
				RxPackets: stat.RxPackets,
				TxBytes:   stat.TxBytes,
				TxPackets: stat.TxPackets,
				TxErrors:  stat.TxErrors,
				TxDropped: stat.TxDropped,
			})

		stats.Network.RxBytes += stat.RxBytes
		stats.Network.RxPackets += stat.RxPackets
		stats.Network.RxErrors += stat.RxErrors
		stats.Network.RxDropped += stat.RxDropped
		stats.Network.TxBytes += stat.TxBytes
		stats.Network.TxPackets += stat.TxPackets
		stats.Network.TxErrors += stat.TxErrors
		stats.Network.TxDropped += stat.TxDropped
	}

	// TODO: fsstats and taskstats is not supported now
	stats.Filesystem = []info.FsStats{}
	stats.TaskStats = info.LoadStats{}

	return &stats, nil
}
Exemplo n.º 2
0
func (self *hyperContainerHandler) fakeStats() (*info.ContainerStats, error) {
	stats := info.ContainerStats{Timestamp: time.Now()}

	stats.Cpu = info.CpuStats{
		Usage: info.CpuUsage{
			Total:  24750780,
			PerCpu: []uint64{18354559, 6396221},
			User:   0,
			System: 10000000,
		},
		LoadAverage: 0,
	}

	stats.DiskIo = info.DiskIoStats{
		IoServiceBytes: []info.PerDiskStats{
			{
				Major: 253,
				Minor: 8,
				Stats: map[string]uint64{"Async": 5353472, "Read": 5353472, "Sync": 0, "Total": 5353472, "Write": 0},
			},
		},
	}

	stats.Memory = info.MemoryStats{
		Usage:      5763072,
		WorkingSet: 1871872,
		ContainerData: info.MemoryStatsMemoryData{
			Pgfault:    3174,
			Pgmajfault: 12,
		},
		HierarchicalData: info.MemoryStatsMemoryData{
			Pgfault:    3174,
			Pgmajfault: 12,
		},
	}

	stats.Network = info.NetworkStats{
		InterfaceStats: info.InterfaceStats{
			Name:      "eth0",
			RxBytes:   123223,
			RxPackets: 128,
			TxBytes:   10240,
			TxPackets: 10,
		},
		Interfaces: []info.InterfaceStats{
			{
				Name:      "eth0",
				RxBytes:   123223,
				RxPackets: 128,

				TxBytes:   10240,
				TxPackets: 10,
			},
		},
	}

	stats.Filesystem = []info.FsStats{}

	stats.TaskStats = info.LoadStats{}

	return &stats, nil
}