예제 #1
0
func DeleteMetric(client *http.Client, project, name string) error {
	service, err := cm.New(client)
	if err != nil {
		return err
	}
	_, err = service.MetricDescriptors.Delete(project, name).Do()

	return err
}
예제 #2
0
func ListMetrics(client *http.Client, project string) ([]*cm.MetricDescriptor, error) {
	service, err := cm.New(client)
	if err != nil {
		return nil, err
	}
	resp, err := service.MetricDescriptors.List(project, &cm.ListMetricDescriptorsRequest{}).Do()
	if err != nil {
		return nil, err
	}
	return resp.Metrics, nil
}
예제 #3
0
func CreateMetric(client *http.Client, project string, m *Metric) error {
	service, err := cm.New(client)
	if err != nil {
		return err
	}
	_, err = service.MetricDescriptors.Create(project, newMetricDescriptor(m)).Do()
	if err != nil {
		return err
	}

	return nil
}
예제 #4
0
func CreateGCMSink(uri *url.URL) (core.DataSink, error) {
	if len(uri.Scheme) > 0 {
		return nil, fmt.Errorf("scheme should not be set for GCM sink")
	}
	if len(uri.Host) > 0 {
		return nil, fmt.Errorf("host should not be set for GCM sink")
	}

	opts, err := url.ParseQuery(uri.RawQuery)

	metrics := "all"
	if len(opts["metrics"]) > 0 {
		metrics = opts["metrics"][0]
	}
	var metricFilter MetricFilter = metricsAll
	switch metrics {
	case "all":
		metricFilter = metricsAll
	case "autoscaling":
		metricFilter = metricsOnlyAutoscaling
	default:
		return nil, fmt.Errorf("invalid metrics parameter: %s", metrics)
	}

	if err := gce_util.EnsureOnGCE(); err != nil {
		return nil, err
	}

	// Detect project ID
	projectId, err := gce.ProjectID()
	if err != nil {
		return nil, err
	}

	// Create Google Cloud Monitoring service.
	client := oauth2.NewClient(oauth2.NoContext, google.ComputeTokenSource(""))
	gcmService, err := gcm.New(client)
	if err != nil {
		return nil, err
	}

	sink := &gcmSink{
		registered:   false,
		project:      projectId,
		gcmService:   gcmService,
		metricFilter: metricFilter,
	}
	glog.Infof("created GCM sink")
	if err := sink.registerAllMetrics(); err != nil {
		glog.Warningf("Error during metrics registration: %v", err)
	}
	return sink, nil
}
예제 #5
0
파일: gcm.go 프로젝트: CodeJuan/kubernetes
func newGcmSource() (dataSource, error) {
	// Detect project ID
	projectId, err := gce.ProjectID()
	if err != nil {
		return nil, err
	}

	// Create Google Cloud Monitoring service.
	client := oauth2.NewClient(oauth2.NoContext, google.ComputeTokenSource(""))
	s, err := gcm.New(client)
	if err != nil {
		return nil, err
	}

	return &gcmSource{
		project:    projectId,
		gcmService: s,
	}, nil
}
예제 #6
0
func WriteTimeseries(client *http.Client, project string, timeseries []*Timeseries) error {
	service, err := cm.New(client)
	if err != nil {
		return err
	}
	labels := make(map[string]string)
	timeseriesPoints := make([]*cm.TimeseriesPoint, len(timeseries))
	for ix, t := range timeseries {
		p := newTimeseriesPoint(t.MetricName, t.Int64Value, t.DoubleValue, t.Now, t.Labels)
		timeseriesPoints[ix] = p
	}

	request := &cm.WriteTimeseriesRequest{
		CommonLabels: labels,
		Timeseries:   timeseriesPoints,
	}
	_, err = service.Timeseries.Write(project, request).Do()
	return err
}