Created
February 15, 2019 15:07
-
-
Save fujiwara/1da580942599b1a2fdb93df2ffff94e3 to your computer and use it in GitHub Desktop.
Convert GetMetricData results to Mackerel metric format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"time" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/cloudwatch" | |
) | |
func main() { | |
var qs []*cloudwatch.MetricDataQuery | |
if err := json.NewDecoder(os.Stdin).Decode(&qs); err != nil { | |
panic(err) | |
} | |
svc := cloudwatch.New(session.Must(session.NewSession(&aws.Config{}))) | |
now := time.Now() | |
res, err := svc.GetMetricData(&cloudwatch.GetMetricDataInput{ | |
StartTime: aws.Time(now.Add(-4 * time.Minute)), | |
EndTime: aws.Time(now), | |
MetricDataQueries: qs, | |
}) | |
if err != nil { | |
panic(err) | |
} | |
for _, r := range res.MetricDataResults { | |
for i, ts := range r.Timestamps { | |
fmt.Printf("%s\t%d\t%f\n", *r.Label, (*ts).Unix(), *(r.Values[i])) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment