Exemplo n.º 1
0
func (store *StatsStorage) fetchStats(zkServers map[string]string) {

	for {
		hosts := getZKHostsFromConfig()
		ipPorts := []string{}
		// keep order when splitting in hosts list and ip:port list
		for _, h := range hosts {
			ipPorts = append(ipPorts, zkServers[h])
		}
		servers, ok := zk.FLWSrvr(ipPorts, 3*time.Second)

		recorded := map[string]zk.ServerStats{}
		for idx, s := range servers {
			if s.Error != nil {
				log.Debug(s.Error)
			}
			recorded[hosts[idx]] = *s
		}
		store.lock.Lock()
		store.stats = recorded
		store.lock.Unlock()
		if !ok {
			log.Error("Failed to fetch stats on one or more servers")
		}

		time.Sleep(2 * time.Second)
	}

}
Exemplo n.º 2
0
func getServerStat(servers []string, timeout time.Duration) error {
	serverStats, ok := zk.FLWSrvr(servers, timeout)
	if !ok {
		err := serverStats[0].Error
		return err
	}
	return nil
}