Beispiel #1
0
// circonusRegistry returns a provider that reports to Circonus.
func circonusRegistry(prefix string,
	circKey string,
	circApp string,
	circURL string,
	circBrokerID string,
	circCheckID string,
	interval time.Duration) (Registry, error) {

	var initError error

	once.Do(func() {
		if circKey == "" {
			initError = errors.New("metrics: Circonus API token key")
			return
		}

		if circApp == "" {
			circApp = serviceName
		}

		host, err := os.Hostname()
		if err != nil {
			initError = fmt.Errorf("metrics: unable to initialize Circonus %s", err)
			return
		}

		cfg := &cgm.Config{}

		cfg.CheckManager.API.TokenKey = circKey
		cfg.CheckManager.API.TokenApp = circApp
		cfg.CheckManager.API.URL = circURL
		cfg.CheckManager.Check.ID = circCheckID
		cfg.CheckManager.Broker.ID = circBrokerID
		cfg.Interval = fmt.Sprintf("%.0fs", interval.Seconds())
		cfg.CheckManager.Check.InstanceID = host
		cfg.CheckManager.Check.DisplayName = fmt.Sprintf("%s /%s", host, serviceName)
		cfg.CheckManager.Check.SearchTag = fmt.Sprintf("service:%s", serviceName)

		metrics, err := cgm.NewCirconusMetrics(cfg)
		if err != nil {
			initError = fmt.Errorf("metrics: unable to initialize Circonus %s", err)
			return
		}

		circonus = &cgmRegistry{metrics, prefix}

		metrics.Start()

		log.Print("[INFO] Sending metrics to Circonus")
	})

	return circonus, initError
}
Beispiel #2
0
// NewCirconusSink - create new metric sink for circonus
//
// one of the following must be supplied:
//    - API Token - search for an existing check or create a new check
//    - API Token + Check Id - the check identified by check id will be used
//    - API Token + Check Submission URL - the check identified by the submission url will be used
//    - Check Submission URL - the check identified by the submission url will be used
//      metric management will be *disabled*
//
// Note: If submission url is supplied w/o an api token, the public circonus ca cert will be used
// to verify the broker for metrics submission.
func NewCirconusSink(cc *Config) (*CirconusSink, error) {
	cfg := cgm.Config{}
	if cc != nil {
		cfg = cgm.Config(*cc)
	}

	metrics, err := cgm.NewCirconusMetrics(&cfg)
	if err != nil {
		return nil, err
	}

	return &CirconusSink{
		metrics: metrics,
	}, nil
}