Below advice applies for:
- Deployment service: AWS Lightsail, AWS EC2
- Architecture: Intel/AMD (amd64), AWS Graviton2 (ARM64 / aarch64)
Recommended Preparations for Ubuntu System Configuration
Set hostname:
sudo hostnamectl set-hostname XXXX-sg01.soluvas.com
Enable byobu and make sure LC_ALL
is set by server even when connecting remotely:
# not just for multi-screens, but you'll get useful system load metrics
byobu-enable
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
Then re-login using ssh.
Update Ubuntu packages:
sudo apt update && sudo apt -y full-upgrade
To enable VSCode to watch files, please apply the following system tweak to the server.
Troubleshooting: UnhandledPromiseRejectionWarning: Error: ENOSPC: System limit for number of file watchers reached
Solution:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Using CloudWatch to track memory usage on Lightsail instances
Reference: Using CloudWatch to track memory usage on Lightsail instances
Important guide:
- All operations must be done as root, so
sudo su
before all steps. - CloudWatch agent IAM user is
cloudwatch_agent
. - Configuration file is /opt/aws/amazon-cloudwatch-agent/bin/config.json
Configuration file that works well and doesn’t use excessive custom metrics:
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/*error.log",
"log_group_name": "*error.log",
"log_stream_name": "{hostname}"
}
]
}
}
},
"metrics": {
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait"
],
"metrics_collection_interval": 60,
"totalcpu": true
},
"disk": {
"measurement": [
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"diskio": {
"measurement": [
"io_time",
"write_bytes",
"read_bytes",
"writes",
"reads"
],
"metrics_collection_interval": 60,
"resources": [
"xvda"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"net": {
"measurement": [
"net_bytes_sent",
"net_bytes_recv"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"swap": {
"measurement": [
],
"metrics_collection_interval": 60
}
}
}
}