Skip to content

chrishacia/ServerScripts

Repository files navigation

Server Metrics CLI Tools

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.

Author

Table of Contents

  1. disk_usage.js
  2. memory_usage.js
  3. node_port_check.js
  4. traffic_monitor.js
  5. clean_node_modules.js

1. disk_usage.js

Description:

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.

Dependencies:

  • child_process (Node.js built-in)
  • cli-table (npm install cli-table)

Example usage:

  • To run the script once:
    node disk_usage.js
  • To run the script in live mode:
    node disk_usage.js --live

Ubuntu Dependencies:

  • None (Uses df command available by default)
_disk_usage

2. memory_usage.js

Description:

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.

Dependencies:

  • child_process (Node.js built-in)
  • cli-table (npm install cli-table)

Example usage:

  • To run the script once:
    node memory_usage.js
  • To run the script in live mode:
    node memory_usage.js --live

Ubuntu Dependencies:

  • None (Uses free command available by default)
_memory_usage

3. node_port_check.js

Description:

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.

Dependencies:

  • child_process (Node.js built-in)
  • cli-table (npm install cli-table)
  • clear (npm install clear)

Example usage:

  • To run the script once:
    node node_port_check.js
  • To run the script in live mode:
    node node_port_check.js --live

Ubuntu Dependencies:

  • Install lsof and pwdx if not available:
    sudo apt install lsof procps
_node_port_check

4. traffic_monitor.js

Description:

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.

Dependencies:

  • child_process (Node.js built-in)
  • blessed (npm install blessed)
  • blessed-contrib (npm install blessed-contrib)

Example usage:

  • To run the script:
    node traffic_monitor.js

Ubuntu Dependencies:

  • Install ss (netstat replacement) and nload for bandwidth monitoring:
    sudo apt install iproute2 nload
traffic_monitor

5. clean_node_modules.js

Description:

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.

Dependencies:

  • fs (Node.js built-in)
  • path (Node.js built-in)
  • cli-progress (Progress bar for visual feedback. Install using npm install cli-progress)

Example usage:

  • To delete all node_modules folders 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.txt containing the paths of all deleted folders.

Making the script executable:

Before running the script in a bash terminal, ensure it has executable permissions:

chmod +x clean_node_modules.js

Ubuntu Dependencies:

  • None (No additional system dependencies required)

License

MIT License

About

A small collection of scripts I use to check stats on my servers from the command line

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors