Monitoring
Metrics, alarms, time series — drive with the real CloudWatch / Azure Monitor / Cloud Monitoring SDK
Monitoring
Emulates metric ingest + alarm evaluation: CloudWatch (AWS), Azure Monitor (Azure), Cloud Monitoring (GCP).
| Provider | Service | SDK-compat | Driver |
|---|---|---|---|
| AWS | CloudWatch (Smithy rpc-v2-cbor) | ✓ Live | aws.CloudWatch |
| Azure | Azure Monitor | ✓ Live | azure.Monitor |
| GCP | Cloud Monitoring | ✓ Live | gcp.CloudMonitoring |
Use the real SDK (recommended)
import (
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
awsserver "github.com/stackshy/cloudemu/server/aws"
)
cloud := cloudemu.NewAWS()
ts := httptest.NewServer(awsserver.New(awsserver.Drivers{CloudWatch: cloud.CloudWatch}))
client := cloudwatch.NewFromConfig(cfg, func(o *cloudwatch.Options) {
o.BaseEndpoint = aws.String(ts.URL)
})
client.PutMetricData(ctx, &cloudwatch.PutMetricDataInput{
Namespace: aws.String("App"),
MetricData: []types.MetricDatum{
{MetricName: aws.String("CPU"), Value: aws.Float64(45.2)},
},
})
client.PutMetricAlarm(ctx, &cloudwatch.PutMetricAlarmInput{
AlarmName: aws.String("HighCPU"),
MetricName: aws.String("CPU"),
Namespace: aws.String("App"),
Threshold: aws.Float64(80.0),
ComparisonOperator: types.ComparisonOperatorGreaterThanThreshold,
EvaluationPeriods: aws.Int32(1),
Period: aws.Int32(60),
Statistic: types.StatisticAverage,
})Operations supported via SDK-compat
CloudWatch: PutMetricData, GetMetricStatistics, ListMetrics, PutMetricAlarm, DescribeAlarms, DeleteAlarms.
Azure Monitor: microsoft.insights/metricAlerts CRUD, metric ingest/read.
Cloud Monitoring: Time-series ingest/read at /v3/projects/.../, alert policies.
Realistic behaviors
- Auto-metrics from compute:
RunInstancesautomatically pushes 5 metrics (CPU, NetworkIn, NetworkOut, DiskReadOps, DiskWriteOps) with 5 backfill datapoints at 1-minute intervals. - Alarm auto-evaluation:
PutMetricDatatriggersevaluateAlarms()for each affected namespace+metric. Alarms transition betweenOKandALARMbased on threshold comparison. - Alarm history:
GetAlarmHistory()returns transition events with timestamps.
Alternative: Portable Go API
import mondriver "github.com/stackshy/cloudemu/monitoring/driver"
aws.CloudWatch.PutMetricData(ctx, []mondriver.MetricDatum{
{Namespace: "App", MetricName: "CPU", Value: 45.2, Unit: "Percent"},
})