Beispiel #1
0
func Monitor() {
	tick := time.NewTicker(REFRESH_TIME * time.Second)
	for {
		<-tick.C
		for k, v := range cpuUsages {
			previousCpuUsages[k] = v
		}

		containers, err := docker.ListContainers()
		if err != nil {
			log.Println(err)
			continue
		}

		for _, container := range containers {
			n, err := cpuacctUsage(container)
			if err != nil {
				log.Println(err)
			}
			cpuUsages[container] = n
		}
	}
}
func main() {
	fmt.Println("Initializing monitoring agent...")
	flag.Parse()
	cpuThreshold := Threshold{*cpuWarning, *cpuCritical}
	memThreshold := Threshold{*memWarning, *memCritical}

	go cpu.Monitor()

	tick := time.NewTicker(1 * time.Second)

	for {
		<-tick.C
		containers, err := docker.ListContainers()
		if err != nil {
			log.Println(err)
			continue
		}

		for _, container := range containers {
			AlertCPU(container, &cpuThreshold)
			AlertMemory(container, &memThreshold)
		}
	}
}