> ## Documentation Index
> Fetch the complete documentation index at: https://docs.americ.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitoring

> Commands for monitoring system

#### Check if port is in use

> 🗎 **Refs**: [Check port in use on Linux](https://www.cyberciti.biz/faq/unix-linux-check-if-port-is-in-use-command/)

```shell theme={null}
# Ubuntu
sudo lsof -i -P -n | grep LISTEN
sudo lsof -i:$PORT
sudo ss -tulpn | grep LISTEN
sudo nmap -sTU -O $IP_ADDRESS

# AlmaLinux
sudo firewall-cmd --list-ports
```

#### Check local IP

```bash theme={null}
ip -4 addr show | grep inet
```

#### Check `systemctl` services

```bash theme={null}
# Specified service
sudo systemctl status $SERVICE_NAME
# All running services:
sudo systemctl --type=service
```

#### Check disk usage

```shell theme={null}
echo "Free disk space:" && \
df -h ~ | awk 'NR==2 {print $4 " available on " $6}' && \
echo -e "\nTop 5 largest directories in $HOME:" && \
du -h --max-depth=1 ~ | sort -hr | head -n 5
```
