Пример #1
0
func main() {
	var opts struct {
		AWSAccess  string `long:"aws-access" env:"ACCESS_KEY" required:"true"`
		AWSSecret  string `long:"aws-secret" env:"SECRET_KEY" required:"true"`
		AWSRegion  string `long:"aws-region" env:"AWS_REGION" default:"us-east-1"`
		StatsDHost string `long:"statsd-host" env:"STATSD_HOST" default:"localhost:8125"`
		Verbose    bool   `long:"verbose" short:"v" env:"DEBUG" default:"false"`
	}

	godotenv.Load(".env")
	if _, err := flags.Parse(&opts); err != nil {
		log.Fatal("cannot parse command line arguments")
	}

	if opts.Verbose {
		log.SetLevel(log.DebugLevel)
	}

	statsdbuffer, err := getStatsdBuffer(opts.StatsDHost)
	if err != nil {
		log.Fatal("could not initialize statsd client")
	}
	statsdbuffer.Logger = log.StandardLogger()

	auth, err := aws.GetAuth(opts.AWSAccess, opts.AWSSecret, "", time.Now())
	if err != nil {
		log.WithField("error", err).Fatal("could not authenticate to aws")
	}

	region := aws.Regions[opts.AWSRegion]
	cw, err := cloudwatch.NewCloudWatch(auth, region.CloudWatchServicepoint)
	if err != nil {
		log.WithFields(log.Fields{
			"error":  err,
			"region": opts.AWSRegion,
		}).Fatal("could not open cloudwatch")
	}

	requests, err := getMetricRequests(cw)
	if err != nil {
		log.WithField("error", err).Fatal("could not build requests")
	}
	log.WithField("num_metrics", len(requests)).Info("built stats requests")

	ticker := time.NewTicker(time.Minute)
	for now := range ticker.C {
		goStats(cw, &requests, now, statsdbuffer)
	}
}
Пример #2
0
func (s *S) SetUpSuite(c *gocheck.C) {
	testServer.Start()
	auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
	s.cw, _ = cloudwatch.NewCloudWatch(auth, aws.ServiceInfo{testServer.URL, aws.V2Signature})
}
Пример #3
0
func (s *S) SetUpSuite(c *C) {
	testServer.Start()
	auth := aws.NewAuth("abc", "123", "", time.Time{})
	s.cw, _ = cloudwatch.NewCloudWatch(auth, aws.ServiceInfo{testServer.URL, aws.V2Signature})
}