func main() {
	glog.Info("Data Collector Initialization...")
	pcpport := 44323
	var contextStore = NewContext()
	var hosts = GetCadvisorHosts()
	var startTime = time.Now()
	clients := []ClientCache{}

	for len(hosts) < 1 {
		glog.Error("Could not talk to redis to obtain host, retrying in 5 seconds.")
		time.Sleep(time.Second * 5)
		hosts = GetCadvisorHosts()

		if time.Now().Sub(startTime) > 300*time.Second {
			glog.Fatal("Could not talk to redis to obtain host after 5 minutes, exiting.")
		}
	}

	for _, host := range hosts {
		endpoint := fmt.Sprintf("http://%s:%d", host, pcpport)
		context := pcp.NewContext("", "localhost")
		context.PollTimeout = 12
		client := pcp.NewClient(endpoint, context)
		client.RefreshContext()
		mquery := pcp.NewMetricQuery("")
		metrics, err := client.Metrics(mquery)
		if err != nil {
			glog.Errorf("Error fetching metrics for client: %s", err)
		}
		clients = append(clients, ClientCache{Client: client, Metrics: metrics})
	}

	for _, metricNames := range config.Influxdb.Schema {
		glog.Info("Iterating over schema")
		for _, cache := range clients {
			query := pcp.NewMetricValueQuery(metricNames, []string{})
			resp, err := cache.Client.MetricValues(query)
			if err != nil {
				glog.Errorf("Failed to retrieve metric values: %s\n", err)
			}

			for _, value := range resp.Values {
				metric := cache.Metrics.FindMetricByName(value.Name)
				indom, err := cache.Client.GetIndomForMetric(metric)
				if err != nil {
					glog.Errorf("Failed to get indom for metric: %s\n", err)
				}
				value.UpdateInstanceNames(indom)
			}
			glog.Info(resp.Values)
		}
	}
	os.Exit(0)
	contextStore.UpdateContext(hosts)

	GetInstanceMapping(contextStore)

	doWork(contextStore)
}
Exemple #2
0
func (pk *Peekachu) RefreshClients() {
	pk.Clients = []*Client{}
	nodes := pk.GetNodes()

	timer := pk.startTimeout()
	retries := 1

	for {
		if retries >= pk.config.Peekachu.MaxRetries {
			glog.Fatalf("Max Retries exceeded for Node query.")
		}

		if len(nodes) == 0 {
			glog.Info("Waiting for nodes to come online....")
			pk.retriesDelay()
			retries += 1
			nodes = pk.GetNodes()
		} else {
			glog.Infof("Found %d nodes: %v\n", len(nodes), nodes)
			timer.Stop()
			break
		}
	}

	for _, node := range nodes {
		context := pcp.NewContext("", pk.config.PCP.HostSpec)
		context.PollTimeout = pk.config.PCP.ContextPollTimeout
		pcpClient := pcp.NewClient(node, pk.config.PCP.Port, context)
		pcpClient.RefreshContext()
		mquery := pcp.NewMetricQuery("")
		metrics, err := pcpClient.Metrics(mquery)
		if err != nil {
			glog.Errorf("Error fetching metrics for client: %s", err)
		}
		client := NewClient(pcpClient)
		client.Metrics = metrics
		pk.Clients = append(pk.Clients, client)
	}
}