示例#1
0
文件: utils.go 项目: freeformz/shh
// Small wrapper to handle errors on open
func FileLineChannel(fpath string) <-chan string {
	c, err := filechan.FileLineChannel(fpath)

	if err != nil {
		FatalError(slog.Context{"fn": "FileLineChannel", "fpath": fpath}, err, "creating FileLineChannel")
	}

	return c
}
示例#2
0
func (poller Cgroup) Poll(tick time.Time) {
	for _, cgroup := range poller.cgroups {
		// I can't use the FileLineChannel in utils.go here because I
		// don't want to raise a fatal error if the cgroup doesn't exist yet.

		cpuStat, err := filechan.FileLineChannel(CGROUPS_PATH + "/cpuacct/" + cgroup + "/cpuacct.stat")

		if err == nil {
			for line := range cpuStat {
				poller.handlePercentCpu(line, tick, cgroup)
			}
		}

		poller.handleMaxMemory("user", "memory.max_usage_in_bytes", tick, cgroup)
		poller.handleMaxMemory("kernel", "memory.kmem.max_usage_in_bytes", tick, cgroup)
		poller.handleMaxMemory("kernel.tcp", "memory.kmem.tcp.max_usage_in_bytes", tick, cgroup)
	}
}