Metrics Publisher

AWS Lambda is tightly integrated with other AWS services and provides excellent opportunities for improving your service’s observability posture. Sparta includes a CloudWatch Metrics publisher that periodically publishes metrics to CloudWatch.

This periodic task publishes environment-level metrics that have been detected by the gopsutil package. Metrics include:

  • CPU
    • Percent used
  • Disk
    • Percent used
  • Host
    • Uptime (milliseconds)
  • Load
    • Load1 (no units)
    • Load5 (no units)
    • Load15 (no units)
  • Network
    • NetBytesSent (bytes)
    • NetBytesRecv (bytes)
    • NetErrin (count)
    • NetErrout (count)

You can provide an optional map[string]string set of dimensions to which the metrics should be published. This enables targeted alert conditions that can be used to improve system resiliency.

To register the metric publisher, call the RegisterLambdaUtilizationMetricPublisher at some point in your main() call graph. For example:

import spartaCloudWatch "github.com/mweagle/Sparta/aws/cloudwatch"
func main() {
  ...
  spartaCloudWatch.RegisterLambdaUtilizationMetricPublisher(map[string]string{
    "BuildId":    sparta.StampedBuildID,
  })
  ...
}

The optional map[string]string parameter is the custom Name-Value pairs to use as a CloudWatch Dimension