コード例 #1
0
// fillBuiltinMetrics adds internal metrics to the monitoring profile
func fillBuiltinMetrics(svc *service.Service) {
	if strings.HasPrefix(svc.ID, "isvc-") {
		return
	}

	if svc.MonitoringProfile.MetricConfigs == nil {
		builder, err := domain.NewMetricConfigBuilder("/metrics/api/performance/query", "POST")
		if err != nil {
			glog.Errorf("Could not create builder to add internal metrics: %s", err)
			return
		}
		config, err := builder.Config("metrics", "metrics", "metrics", "-1h")
		if err != nil {
			glog.Errorf("could not create metric config for internal metrics: %s", err)
		}
		svc.MonitoringProfile.MetricConfigs = []domain.MetricConfig{*config}
	}
	index, found := findInternalMetricConfig(svc)
	if !found {
		glog.Errorf("should have been able to find internal metrics config")
		return
	}
	config := &svc.MonitoringProfile.MetricConfigs[index]
	removeInternalMetrics(config)
	removeInternalGraphConfigs(svc)

	if len(svc.Startup) > 2 {
		addInternalMetrics(config)
		addInternalGraphConfigs(svc)
	}
}
コード例 #2
0
func findInternalMetricConfig(svc *service.Service) (index int, found bool) {
	// find the metric config
	for i := range svc.MonitoringProfile.MetricConfigs {
		if svc.MonitoringProfile.MetricConfigs[i].ID == "metrics" {
			return i, true
		}
	}
	builder, err := domain.NewMetricConfigBuilder("/metrics/api/performance/query", "POST")
	if err != nil {
		glog.Errorf("Could not create builder to add internal metrics: %s", err)
		return
	}
	config, err := builder.Config("metrics", "metrics", "metrics", "-1h")
	if err != nil {
		glog.Errorf("could not create metric config for internal metrics: %s", err)
	}
	svc.MonitoringProfile.MetricConfigs = append(
		svc.MonitoringProfile.MetricConfigs,
		*config)

	return len(svc.MonitoringProfile.MetricConfigs) - 1, true
}