https://github.com/tomsh-hr/pingstat
A lightweight, user-level script for multi-server ping logging, storing stats per server in user-writable SQLite databases.
https://github.com/tomsh-hr/pingstat
bash linux ping server
Last synced: 2 months ago
JSON representation
A lightweight, user-level script for multi-server ping logging, storing stats per server in user-writable SQLite databases.
- Host: GitHub
- URL: https://github.com/tomsh-hr/pingstat
- Owner: tomsh-hr
- License: mit
- Created: 2025-03-12T10:27:28.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-12T10:46:10.000Z (3 months ago)
- Last Synced: 2025-03-12T11:33:57.098Z (3 months ago)
- Topics: bash, linux, ping, server
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pingstat
A lightweight, user-level script for multi-server ping logging, storing stats per server in user-writable SQLite databases.
---
## Example Output
```bash
pingstat -d
``````bash
day abs_min avg_min avg_avg avg_max abs_max avg_loss weekday num_pings
---------- ------- ------- ------- ------- ------- -------- --------- ---------
2025-03-09 0.056 0.083 0.133 0.183 1.171 0.0% Sunday 56
2025-03-08 0.052 0.084 0.132 0.182 0.323 0.0% Saturday 96
2025-03-07 0.055 0.096 0.146 0.188 0.265 8.3% Friday 96
2025-03-06 0.053 0.073 0.104 0.135 0.237 3.2% Thursday 94
2025-03-05 0.055 0.084 0.128 0.167 0.235 0.0% Wednesday 96
2025-03-04 0.056 0.090 0.138 0.191 1.111 1.0% Tuesday 96
2025-03-03 0.054 0.097 0.142 0.183 0.231 5.4% Monday 37
2025-03-02 0.058 0.079 0.124 0.179 0.316 12.5% Sunday 24
2025-03-01 0.059 0.087 0.132 0.174 0.223 4.2% Saturday 24
2025-02-28 0.060 0.085 0.136 0.184 0.229 0.0% Friday 28
2025-02-27 0.056 0.063 0.093 0.135 0.168 0.0% Thursday 4
-------------------------------------------------------------------------------------Note: Times are in milliseconds (ms), and packet loss in %.
```### **Stat Definitions**
- **abs_min** – absolute minimum (quickest response of the day/month).
- **avg_min** – average minimum ping over the day.
- **avg_avg** – average ping of all requests for that day.
- **avg_max** – average of the maximum ping values recorded.
- **abs_max** – absolute maximum (the slowest response recorded).
- **avg_loss** – average packet loss percentage for the day/month.
- **weekday** – day of the week (only for the -d flag).
- **num_pings** – number of pings for the day/month.---
## Features
✅ **Manage multiple servers** (`add`, `remove`, `list`) without manually editing config files.
✅ **Log ping statistics** (`min/avg/max/mdev/loss`) into a dedicated SQLite `.db` file per server.
✅ **View historical stats** with daily (`-d`) or monthly (`-m`) aggregation.
✅ **Minimal dependencies** – requires only `bash`, `ping`, `sqlite3`, and `aws`.
✅ **Automate pings** using `cron` for long-term monitoring.---
## Installation
### **System-wide Installation** (Requires `sudo`)
```bash
wget -qO- "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | sudo bash
```
or (if you prefer curl):```bash
curl -sL "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | sudo bash
```This installs `pingstat` in `/usr/bin/`, making it available to all users.
### **User-Level Installation** (No `sudo`)
```bash
wget -qO- "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | bash
```or:
```bash
curl -sL "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | bash
```
*(Ensure `~/bin` is in your `$PATH` to run `pingstat` easily.)*### **Install a Specific Version** (e.g., `1.0.0`)
```bash
wget -qO- "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | sudo bash -s -- 1.0.0
```or:
```bash
curl -sL "https://codeberg.org/tomsh/pingstat/raw/branch/main/install" | sudo bash -s -- 1.0.0
```---
## Basic Usage
```bash
pingstat [options]
```### **Server Management**
- `pingstat add ` → Add a server (e.g., `kernel.org`).
- `pingstat remove ` → Remove a server from the list.
- `pingstat list` → List all configured servers.### **Ping & Stats**
- `pingstat -p` → Ping all servers (or use `-s ` for one).
- `pingstat -d [N]` → Show daily stats for the last `N` days (default: 20).
- `pingstat -m [N]` → Show monthly stats for the last `N` months (default: 12).
- `pingstat -s ` → Apply `-p`, `-d`, or `-m` to a specific server.### **Examples**
```bash
pingstat add kernel.org
pingstat add gnu.org
pingstat list
``````bash
pingstat -p # Ping all servers
pingstat -p -s gnu.org # Ping only gnu.org
pingstat -d 5 # Show last 5 days' stats
pingstat -d 5 -s gnu.org # Last 5 days for gnu.org only
pingstat remove gnu.org # Remove gnu.org from the list
```---
## Automating with Cron
To ping **all** servers every **5 minutes**, edit your crontab (`crontab -e`) and add:
```cron
*/5 * * * * pingstat -p
```For a single server:
```cron
*/5 * * * * pingstat -p -s kernel.org
```---
## Updating
To update to the latest version:
```bash
pingstat --update
```Or manually by running install script as described above.
---
## Uninstalling
To remove `pingstat`, run:
```bash
pingstat --uninstall
```Or manually remove:
```bash
sudo rm /usr/bin/pingstat # System-wide install
rm -rf ~/.config/pingstat # User config
rm -rf ~/.local/share/pingstat # User data
```
*(Adjust paths if you installed locally.)*---
## License
Licensed under [MIT](LICENSE).