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) }
func (pk *Peekachu) refreshMetricValuesForClient( client *Client, table string, names []string, ) { glog.V(3).Infof("Fetching metric values for host %s...", client.PcpClient.Host) query := pcp.NewMetricValueQuery(names, []string{}) if resp, err := client.PcpClient.MetricValues(query); err != nil { msg := "Failed to retrieve metric values from host %s : %s\n" glog.Errorf(msg, client.PcpClient.Host, err) } else { for _, value := range resp.Values { metric := client.Metrics.FindMetricByName(value.MetricName) indom, err := client.PcpClient.GetIndomForMetric(metric) if err != nil { glog.Errorf( "Failed to get indom for metric '%s' with instance domain '%d': %s\n", metric.Name, metric.Indom, err, ) glog.Errorln("Refusing to update value due to prior errors.") } else { value.UpdateInstanceNames(indom) } } client.MetricValueResponses[table] = append( client.MetricValueResponses[table], resp, ) } }