A small shell script to collect basic server performance metrics and optionally send them to stdout, a CSV file, or a remote collector.
- Capture CPU, memory, disk, and load metrics
- Timestamped, human- and machine-friendly output
- Optional CSV logging for historical analysis
- Simple CLI flags for flexible behavior
- Designed for cron or interactive use
- POSIX-compatible shell (bash/sh)
- coreutils: date, awk, grep
- vmstat, free, df, iostat (optional but recommended)
- Network tools for remote send (curl or netcat) if using remote export
- git clone https://github.com/NicksonJacksonWilfest/server-performance.git
- Place the script in a directory on the server, e.g. /usr/local/bin/server-performance
- Make it executable: chmod +x /usr/local/bin/server-performance
Basic run (print human-readable summary): ./server_stats
Write a CSV line to a file: ./server_stats --output /var/log/server-performance.csv
Send metrics to an HTTP collector: ./server_stats --send http://collector.example.org/ingest
Show help: ./server_stats --help
- --help, -h Print usage and options.
- --output Append a CSV-formatted line to the given file (creates file if missing).
- --send POST metrics to a remote HTTP endpoint as JSON.
- --interval When combined with --daemon, sample at this interval.
- --daemon Run continuously, emitting metrics at the configured interval.
- --fields Comma-separated subset of metrics to collect (cpu,mem,disk,load).
- Human mode: plain text summary with totals and percentages.
- CSV mode: one line per sample with ISO8601 timestamp and fields: timestamp,cpu_percent,load1,load5,load15,mem_total_kB,mem_used_kB,disk_root_percent
- JSON (for --send): { "timestamp": "...", "cpu": ..., "mem": {...}, "disk": {...}, "load": [...] }
Add a cron job for periodic sampling, for example every 5 minutes: */5 * * * * /usr/local/bin/server-performance --output /var/log/server-performance.csv
Rotate CSV logs using logrotate or include a log-rotation step in cron. Keep retention policies according to storage and compliance needs.
- Missing commands: ensure required utilities are installed and in PATH.
- Permissions: ensure the script can write to the output path and has execute permission.
- Remote send failures: verify network access and endpoint authentication/format.
Open a pull request with a focused change, include tests or usage notes where applicable.
None
Distrodev