CLOUD & DEVOPS
AWS Lambda MicroVM의 CPU 및 메모리 메트릭 수집

Most production services in AWS use at least two key metrics for service health – CPU and memory utilization. The amount of CPU and memory used by the host (in this case, a MicroVM) can indicate scaling signals or inefficiencies in your application. If you’re running a production workload on AWS Lambda MicroVMs , it’s recommended to have observability in these dimensions. And the easiest way to collect these metrics is through the Amazon CloudWatch Agent . This blog shows you how to collect CPU and memory metrics from within the MicroVM using the CloudWatch Agent.
To observe how a workload uses CPU and memory over time, run the CloudWatch Agent inside the MicroVM. Since a MicroVM image is a full OS snapshot, you can start the agent during image creation, meaning it will already be running the moment a MicroVM launches from that image. This means zero startup latency and one-time configuration: set up the CloudWatch Agent once in the image, and every MicroVM that launches from it already has a running monitoring stack. To setup CloudWatch Agent, you will modify the ZIP containing your application and Dockerfile , and build a MicroVM image.
Once you run a MicroVM from the image, three metrics will be emitted ( cpu_usage_active , cpu_usage_idle , mem_used_percent ) under an ImageName dimension populated from a Lambda-injected environment variable. The Lambda MicroVMs runtime automatically exposes these environment variables to your application: The example below uses AWS_LAMBDA_MICROVM_IMAGE_NAME as a metric dimension so you can monitor metrics per MicroVM image. Amazon CloudWatch Agent uses telegraf to process metrics and opentelemetry-collector (OTel) to export them. Normally, you configure the agent through a cwagent.
json file, which the agent’s config-translator converts into a telegraf TOML file and an OTel YAML file for the process to use at startup. In this post, we skip the JSON configuration and create the telegraf and OTel files directly. This lets us dynamically set a custom metric dimension from an environment variable using OTel’s ${env:VAR} syntax. The telegraf config defines which metrics to collect, while the OTel config resolves the environment variable at process start and appends it as a dimension.