func (im *InstanceMonitor) monitorInstanceStats() { rev := im.doozer.GetCurrentRevision() watchPath := path.Join("/statistics", "**") for { ev, err := im.doozer.Wait(watchPath, rev+1) rev = ev.Rev if err != nil { continue } // If it's being removed no need to send notification, it's sent my monitorInstances if ev.IsDel() { continue } else { var s skynet.ServiceInfo var stats skynet.ServiceStatistics var ok bool servicePath := strings.Replace(ev.Path, "/statistics", "/services", 1) // If InstanceMonitor doesn't know about it, it was probably deleted, safe not to send notification if s, ok = im.instances[servicePath]; !ok { continue } buf := bytes.NewBuffer(ev.Body) err = json.Unmarshal(buf.Bytes(), &stats) if err != nil { fmt.Println("error unmarshalling service") continue } s.Stats = &stats // Let's create an update notification to send, with our new statistics im.notificationChan <- InstanceMonitorNotification{ Path: ev.Path, Service: s, OldService: im.instances[servicePath], Type: InstanceStatsUpdateNotification, } } } }