This is a reporter for the go-metrics that will posts metrics to CloudWatch.
import "github.com/weareyolo/cloudmetrics"
go cloudmetrics.Publish(metrics.DefaultRegistry,
"/sample/", // namespace
)
cloudmetrics
supports a number of configuration options:
package main
import (
"context"
"time"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/weareyolo/go-metrics"
"github.com/weareyolo/cloudmetrics"
)
func main() {
p := cloudmetrics.NewPublisher(
metrics.DefaultRegistry, // metrics registry
"/sample/", // namespace
cloudmetrics.WithDimensions(map[string]string{
"k1": "v1",
"k2": "v2",
}), // allows for custom dimensions
cloudmetrics.WithInterval(5*time.Minute), // custom interval
cloudmetrics.WithContext(context.Background()), // enables graceful shutdown via contexts
cloudmetrics.WithPercentiles([]float64{.5, .99}), // customize percentiles for histograms and timers
cloudmetrics.WithUnits(map[string]string{
"size": cloudwatch.StandardUnitGigabytes,
}), // customize units based on metric names
)
go p.Publish()
for {
time.Sleep(5 * time.Minute)
}
}