groupcache_awsemf exports groupcache metrics to AWS CloudWatch Logs using Embedded Metric Format.
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/modernprogram/groupcache/v2"
"github.com/udhos/groupcache_awsemf/exporter"
"github.com/udhos/groupcache_exporter"
"github.com/udhos/groupcache_exporter/groupcache/modernprogram"
)
workspace := groupcache.NewWorkspace()
caches := startGroupcache(workspace)
//
// metrics exporter
//
var awsConfig *aws.Config
if cloudwatchSend {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatalf("aws sdk config error: %v", err)
}
awsConfig = &cfg
}
exporter, errExport := exporter.New(exporter.Options{
Application: "my-application-name",
AwsConfig: awsConfig, // if nil, metric is echoed to stdout
ListGroups: func() []groupcache_exporter.GroupStatistics {
return modernprogram.ListGroups(workspace)
},
ExportInterval: 20 * time.Second,
})
if errExport != nil {
log.Fatal(errExport)
}
defer exporter.Close()
- ./examples/groupcache-awsemf-google/main.go
- ./examples/groupcache-awsemf-mailgun/main.go
- ./examples/groupcache-awsemf-modernprogram/main.go
By default:
1 - EMF logs are issued to log group /groupache/{Application}
. See option LogGroup
to change the log group.
2 - EMF metrics are issued to namespace groupcache
. See option Namespace
to change the namespace.
3 - EMF metrics have dimension application={Application}
. See option Application
to set the application name.