Cloud costs can spiral without monitoring and governance. Tagging all resources, setting billing alarms, and regularly rightsizing instances are essential practices for production cloud environments.
| Term / Service | Description / Value | Notes |
|---|---|---|
| CloudWatch | AWS monitoring service for metrics, logs, alarms | Collect metrics, create dashboards, trigger alarms |
| CloudWatch metrics | CPU, NetworkIn, DiskReadOps, custom metrics | Pre-built metrics for all AWS services |
| CloudWatch alarm | Trigger action when metric threshold breached | Send SNS notification, trigger Auto Scaling |
| CloudWatch Logs | Centralized log aggregation service | Lambda logs, EC2 logs, VPC flow logs |
| CloudWatch Dashboard | Visual monitoring dashboard | Combine metrics, alarms, logs in one view |
| CloudTrail | Audit log of all API calls in your account | Who did what, when — compliance and security |
| Config | Track resource configuration changes over time | Compliance rules, configuration history |
| Cost Explorer | Analyze and visualize AWS spending | Break down by service, tag, region, time |
| Billing alarm | Alert when estimated charges exceed threshold | Set at $10, $50, $100 — catch runaway costs early |
| Budgets | Set spending budgets with alerts | Alert at 80% and 100% of monthly budget |
| Cost allocation tags | user:project, user:env, user:owner | Tag resources to track costs by team/project |
| Reserved Instance savings | Up to 75% vs On-Demand | 3-year all-upfront gives maximum savings |
| Savings Plans | Commit to $/hour in exchange for discount | More flexible than RIs — applies across instance types |
| Spot Instance savings | Up to 90% off On-Demand | For fault-tolerant batch jobs, CI/CD, dev workloads |
| Rightsizing | Match instance size to actual usage | Look at CPU/memory utilization — downsize idle instances |
| Auto Scaling | Match capacity to demand automatically | Scale out during traffic spikes, in during quiet periods |
| Trusted Advisor | AWS service for cost/security/performance recommendations | Free for basic checks, Business/Enterprise support for full |
| Health Dashboard | AWS Service Health Dashboard + Personal Health Dashboard | Monitor AWS service outages affecting your account |
| Azure Monitor | Azure monitoring equivalent to CloudWatch | Metrics, logs, alerts, dashboards |
| Azure Cost Management | Azure cost analysis and budgeting tool | Equivalent to AWS Cost Explorer + Budgets |
| GCP Cloud Monitoring | Stackdriver Monitoring — GCP equivalent | Metrics, alerting, dashboards, uptime checks |
# Cloud Monitoring & Cost Management
# ── CloudWatch Alarm (billing threshold) ─────────────────────
aws cloudwatch put-metric-alarm \
--alarm-name "BillingAlarm-50USD" \
--alarm-description "Alert when charges exceed $50" \
--metric-name EstimatedCharges \
--namespace AWS/Billing \
--statistic Maximum \
--period 86400 \
--threshold 50 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 1 \
--alarm-actions arn:aws:sns:us-east-1:123456789012:billing-alerts \
--dimensions Name=Currency,Value=USD \
--treat-missing-data notBreaching
# ── CloudWatch Metric Alarm (CPU) ────────────────────────────
aws cloudwatch put-metric-alarm \
--alarm-name "HighCPU-WebServer" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--dimensions Name=InstanceId,Value=i-1234567890abcdef0 \
--period 300 \
--statistic Average \
--threshold 80 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2 \
--alarm-actions arn:aws:sns:us-east-1:123456789012:ops-alerts \
--ok-actions arn:aws:sns:us-east-1:123456789012:ops-alerts
# ── CloudWatch Log Insights query ────────────────────────────
aws logs start-query \
--log-group-name /aws/lambda/MyWebUniversityAPI \
--start-time $(date -d '1 hour ago' +%s) \
--end-time $(date +%s) \
--query-string '
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20'
# ── Cost Explorer: last month by service ─────────────────────
aws ce get-cost-and-usage \
--time-period Start=2026-05-01,End=2026-06-01 \
--granularity MONTHLY \
--metrics BlendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--query 'ResultsByTime[0].Groups[*].[Keys[0],Metrics.BlendedCost.Amount]' \
--output table
# ── Tag resources for cost tracking ──────────────────────────
# Apply tags to ALL resources
aws ec2 create-tags \
--resources i-1234567890abcdef0 \
--tags Key=Project,Value=MyWebUniversity \
Key=Environment,Value=Production \
Key=Owner,Value=alice \
Key=CostCenter,Value=Engineering
# ── Python: CloudWatch custom metrics ────────────────────────
import boto3
from datetime import datetime
cloudwatch = boto3.client('cloudwatch', region_name='us-east-1')
# Publish custom metric
cloudwatch.put_metric_data(
Namespace='MyWebUniversity/App',
MetricData=[
{
'MetricName': 'ActiveUsers',
'Value': 142,
'Unit': 'Count',
'Timestamp': datetime.utcnow(),
'Dimensions': [
{'Name': 'Environment', 'Value': 'Production'},
{'Name': 'Region', 'Value': 'us-east-1'},
],
},
{
'MetricName': 'ResponseTime',
'Value': 0.245,
'Unit': 'Seconds',
'Timestamp': datetime.utcnow(),
},
]
)
print("Custom metrics published")
# Get metric statistics
response = cloudwatch.get_metric_statistics(
Namespace='AWS/EC2',
MetricName='CPUUtilization',
Dimensions=[{'Name': 'InstanceId', 'Value': 'i-1234567890abcdef0'}],
StartTime=datetime(2026, 6, 24),
EndTime=datetime(2026, 6, 25),
Period=3600,
Statistics=['Average', 'Maximum']
)
for dp in sorted(response['Datapoints'], key=lambda x: x['Timestamp']):
print(f" {dp['Timestamp'].strftime('%H:%M')} avg={dp['Average']:.1f}% max={dp['Maximum']:.1f}%")
# pip install boto3 && python3 monitoring.py