Exemplo n.º 1
0
func newMackerel(conffile string) *mkr.Client {
	apiKey := LoadApikeyFromEnvOrConfig(conffile)
	if apiKey == "" {
		logger.Log("error", `
    Not set MACKEREL_APIKEY environment variable. (Try "export MACKEREL_APIKEY='<Your apikey>'")
`)
		os.Exit(1)
	}

	if os.Getenv("DEBUG") != "" {
		mackerel, err := mkr.NewClientWithOptions(apiKey, "https://mackerel.io/api/v0", true)
		logger.DieIf(err)

		return mackerel
	}

	return mkr.NewClient(apiKey)
}
Exemplo n.º 2
0
func doAction(c *cli.Context) {
	awsKeyID := c.String("aws-key-id")
	awsSecKey := c.String("aws-secret-key")
	mackerelAPIKey := c.String("mackerel-api-key")

	client := mkr.NewClient(mackerelAPIKey)

	sess := session.New(&aws.Config{
		Credentials: credentials.NewStaticCredentials(awsKeyID, awsSecKey, ""),
		Region:      aws.String("ap-northeast-1"),
	})
	awsSession := NewAWSSession(sess)

	if c.Bool("debug") {
		sess.Config.LogLevel = aws.LogLevel(aws.LogDebug)
	}

	rdss := awsSession.fetchRDSList()
	awsSession.updateAWSElementList(rdss, client)

	elbs := awsSession.fetchLoadBalancerList()
	awsSession.updateAWSElementList(elbs, client)

	tickChan := time.NewTicker(60 * time.Second)
	quit := make(chan struct{})

	awsSession.crawlRDSMetrics(client, rdss)

	for {
		select {
		case <-tickChan.C:
			awsSession.crawlELBMetrics(client, elbs)
			awsSession.crawlRDSMetrics(client, rdss)
		case <-quit:
			tickChan.Stop()
			return
		}
	}

	//listMetric(sess)
}