This repository contains a collection of useful CLI-based scripts for monitoring live metrics and data on a server. These scripts provide real-time information on disk usage, memory usage, active Node.js processes, and network traffic. Each script is designed to be run either once or in a live mode for continuous monitoring.
- Name: Christopher Hacia
- Website: https://chrishacia.com
This script fetches and displays disk usage statistics, showing details such as size, used space, and available space for mounted file systems. It supports a --live option for continuous monitoring.
child_process(Node.js built-in)cli-table(npm install cli-table)
- To run the script once:
node disk_usage.js
- To run the script in live mode:
node disk_usage.js --live
- None (Uses
dfcommand available by default)
This script displays the system's memory usage, including total memory, used memory, free memory, and more. The output is presented in a table format for better readability. Like disk_usage.js, it supports a --live option.
child_process(Node.js built-in)cli-table(npm install cli-table)
- To run the script once:
node memory_usage.js
- To run the script in live mode:
node memory_usage.js --live
- None (Uses
freecommand available by default)
This script checks for active Node.js processes and lists their PID, user, port, command, directory, and memory usage. It is useful for monitoring which Node.js applications are running and the resources they consume.
child_process(Node.js built-in)cli-table(npm install cli-table)clear(npm install clear)
- To run the script once:
node node_port_check.js
- To run the script in live mode:
node node_port_check.js --live
- Install
lsofandpwdxif not available:sudo apt install lsof procps
This script provides real-time monitoring of network traffic for various services (HTTP, HTTPS, MySQL, FTP) and displays a visual chart using the blessed and blessed-contrib libraries. It also tracks total active connections and presents the data in a terminal-based UI.
child_process(Node.js built-in)blessed(npm install blessed)blessed-contrib(npm install blessed-contrib)
- To run the script:
node traffic_monitor.js
- Install
ss(netstat replacement) andnloadfor bandwidth monitoring:sudo apt install iproute2 nload
This script recursively searches through directories starting at a given path, finds all node_modules folders, and deletes them. It also logs the deleted folders, calculates the total size of deleted node_modules, and skips symbolic links to avoid unnecessary processing.
fs(Node.js built-in)path(Node.js built-in)cli-progress(Progress bar for visual feedback. Install usingnpm install cli-progress)
-
To delete all
node_modulesfolders in a specific directory:./clean_node_modules.js /path/to/directory
-
To handle directories with symbolic links and log deleted folders: The script will automatically skip symbolic links and generate a log file named
clean_log-YYYY-MM-DD_HHMMSS.txtcontaining the paths of all deleted folders.
Before running the script in a bash terminal, ensure it has executable permissions:
chmod +x clean_node_modules.js- None (No additional system dependencies required)
MIT License