Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

🖥️ Linux Monitor API

A FastAPI project to expose various Linux system statistics as RESTful APIs using common Linux commands.

⚠️Important: This project only works on Linux systems.
It uses native Linux shell commands (e.g. lshw, df, ps, etc.)
❌ It will not run correctly on Windows or macOS.


🚀 Features

  • ✅ System Information (kernel, hostname, uptime, user)
  • ✅ CPU & Memory Usage (top, free, lscpu)
  • ✅ Disk & Filesystem Info (df, du, mount)
  • ✅ Network Status (IP, routes, ping, traceroute)
  • ✅ Processes & Services (ps, systemctl)
  • ✅ Logs (syslog, dmesg, auth.log)
  • ✅ Hardware Details (lshw, lspci, sensors)

📁 Project Structure

linux_monitor_api/
├── app/
│ ├── main.py
│ ├── routes/
│ │ ├── system.py
│ │ ├── cpu_memory.py
│ │ ├── disk.py
│ │ ├── network.py
│ │ ├── processes.py
│ │ ├── logs.py
│ │ └── hardware.py
│ └── utils/
│ └── run_command.py
├── tests/
│ ├── test_system.py
│ ├── test_cpu_memory.py
│ ├── test_disk.py
│ ├── test_network.py
│ ├── test_processes.py
│ ├── test_logs.py
│ └── test_hardware.py
├── requirements.txt
└── README.md

▶️ Run the API

1. Install dependencies

pip install -r requirements.txt

2. Start the server

uvicorn app.main:app --reload

🧪 Run Tests

pytest tests/

🛡️ Notes

  • Some commands may require elevated privileges (e.g., dmidecode, lshw).
  • Make sure required tools like traceroute, dig, or lm-sensors are installed if needed.

📬 Example API Calls

EndpointDescription
/api/system/unameKernel info (uname -a)
/api/cpu/lscpuCPU info (lscpu)
/api/disk/dfDisk usage (df -h)
/api/network/ipIP addresses (ip a)
/api/processes/psRunning processes (ps aux)
/api/logs/syslogSyslog tail (tail /syslog)
/api/hardware/lshwHardware info (lshw)

📡 Command to API Endpoint Mapping

🔧 Command🛣️ API Endpoint📝 Description🗂️ Scope
uname -a/api/system/unameKernel name, version, architecture🔧 System Information
hostnamectl/api/system/hostnameShow hostname and system information🔧 System Information
lsb_release -a/api/system/releaseUbuntu release information🔧 System Information
uptime/api/system/uptimeSystem uptime and load average🔧 System Information
whoami/api/system/userCurrent logged-in user🔧 System Information
id/api/system/idUser ID and group info🔧 System Information
uname -m/api/system/architectureSystem architecture🔧 System Information
top/api/cpu/topReal-time CPU, memory, processes snapshot🧠 CPU & Memory Usage
vmstat 1/api/cpu/vmstatCPU/memory system performance🧠 CPU & Memory Usage
lscpu/api/cpu/lscpuDetailed CPU information🧠 CPU & Memory Usage
free -h/api/memory/freeMemory usage summary🧠 CPU & Memory Usage
cat /proc/meminfo/api/memory/meminfoLive memory usage details🧠 CPU & Memory Usage
df -h/api/disk/dfDisk space usage💾 Disk & Filesystem
du -sh */api/disk/duDisk usage per directory💾 Disk & Filesystem
lsblk/api/disk/lsblkBlock devices overview💾 Disk & Filesystem
mount/api/disk/mountMounted filesystems💾 Disk & Filesystem
fdisk -l/api/disk/fdiskPartition table info💾 Disk & Filesystem
findmnt/api/disk/findmntHierarchical view of mount points💾 Disk & Filesystem
ip a/api/network/ipShow IP addresses🌐 Network
ip route/api/network/routeRouting table🌐 Network
ss -tuln/api/network/ssListening ports (TCP/UDP)🌐 Network
ping 8.8.8.8/api/network/pingTest network connectivity🌐 Network
traceroute google.com/api/network/tracerouteTrace network route🌐 Network
dig example.com/api/network/digDNS lookup🌐 Network
nmcli dev show/api/network/nmcliNetwork manager details🌐 Network
ps aux/api/processes/psList running processes🔋 Processes & Services
systemctl status/api/processes/systemctl_statusService manager status🔋 Processes & Services
systemctl list-units/api/processes/systemctl_servicesList active services🔋 Processes & Services
journalctl -xe/api/processes/journalctlView systemd logs🔋 Processes & Services
tail -n 100 /var/log/syslog/api/logs/syslogFollow system logs🔍 Logs
less /var/log/auth.log/api/logs/authAuthentication logs🔍 Logs
dmesg/api/logs/dmesgKernel ring buffer🔍 Logs
lshw -short/api/hardware/lshwDetailed hardware info🧰 Hardware Info
lspci/api/hardware/lspciPCI bus devices🧰 Hardware Info
lsusb/api/hardware/lsusbUSB devices🧰 Hardware Info
dmidecode/api/hardware/dmidecodeBIOS, motherboard, RAM details🧰 Hardware Info
sensors/api/hardware/sensorsCPU temperature sensors🧰 Hardware Info

📌 License

This project is licensed under the MIT License.

About

FastAPI project to monitor Linux system info (CPU, memory, disk, network)

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages