|
1 | | -# System Monitoring |
| 1 | +# Appwrite System Monitoring |
2 | 2 |
|
3 | | -A lightweight system monitoring tool that tracks CPU, memory, and disk usage across your infrastructure. When resource usage exceeds defined thresholds, it creates incidents in BetterStack. |
| 3 | +A system monitoring tool for Appwrite servers that tracks CPU, memory, and disk usage with alerting via BetterStack. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | | -- CPU usage monitoring |
8 | | -- Memory usage monitoring |
9 | | -- Disk usage monitoring (root and mounted volumes) |
10 | | -- Automatic incident creation and resolution |
11 | | -- Configurable thresholds via CLI |
12 | | -- Docker-based deployment |
| 7 | +- Monitors CPU usage with configurable thresholds |
| 8 | +- Monitors memory usage with configurable thresholds |
| 9 | +- Monitors disk usage (root and mounted volumes) with configurable thresholds |
| 10 | +- Uses Exponential Moving Average (EMA) to smooth out short-term spikes |
| 11 | +- Sends alerts to BetterStack when thresholds are exceeded |
13 | 12 |
|
14 | | -## Command Line Usage |
| 13 | +## Project Structure |
15 | 14 |
|
16 | | -The monitoring tool is configured through command-line flags: |
| 15 | +The project follows a simplified package structure: |
17 | 16 |
|
18 | | -```bash |
19 | | -monitoring [flags] |
20 | | - |
21 | | -Flags: |
22 | | - -url string |
23 | | - BetterStack webhook URL (required) |
24 | | - -interval int |
25 | | - Check interval in seconds (default: 300) |
26 | | - -cpu-limit float |
27 | | - CPU usage threshold percentage (default: 90) |
28 | | - -memory-limit float |
29 | | - Memory usage threshold percentage (default: 90) |
30 | | - -disk-limit float |
31 | | - Disk usage threshold percentage (default: 85) |
32 | | - -help |
33 | | - Display help information |
34 | | -``` |
35 | | - |
36 | | -### Examples |
37 | | - |
38 | | -```bash |
39 | | -# Basic usage with required URL |
40 | | -monitoring --url=https://betterstack.com/webhook/xyz |
41 | | - |
42 | | -# Custom thresholds |
43 | | -monitoring --url=https://betterstack.com/webhook/xyz \ |
44 | | - --cpu-limit=95 \ |
45 | | - --memory-limit=85 \ |
46 | | - --disk-limit=80 |
47 | | - |
48 | | -# More frequent checks (every minute) |
49 | | -monitoring --url=https://betterstack.com/webhook/xyz --interval=60 |
50 | 17 | ``` |
51 | | - |
52 | | -## Docker Deployment |
53 | | - |
54 | | -### Using Docker Run |
55 | | - |
56 | | -```bash |
57 | | -docker run -d \ |
58 | | - --name monitoring \ |
59 | | - --privileged \ |
60 | | - --pid=host \ |
61 | | - -v /:/host:ro \ |
62 | | - ghcr.io/appwrite/monitoring:latest \ |
63 | | - monitoring \ |
64 | | - --url=https://betterstack.com/webhook/xyz \ |
65 | | - --interval=300 \ |
66 | | - --cpu-limit=90 \ |
67 | | - --memory-limit=90 \ |
68 | | - --disk-limit=85 |
69 | | -``` |
70 | | - |
71 | | -### Using Docker Compose |
72 | | - |
73 | | -The docker-compose.yml file is configured with default parameters that you can modify as needed: |
74 | | - |
75 | | -```bash |
76 | | -docker-compose up -d |
| 18 | +monitoring/ |
| 19 | +├── main.go # Entry point with CLI argument parsing |
| 20 | +├── pkg/ |
| 21 | +│ ├── logger.go # Logging functionality at package level |
| 22 | +│ └── monitor/ # Core monitoring functionality |
| 23 | +│ ├── monitor.go # Main monitoring struct and Metric model |
| 24 | +│ ├── cpu.go # CPU-specific monitoring |
| 25 | +│ ├── memory.go # Memory-specific monitoring |
| 26 | +│ └── disk.go # Disk-specific monitoring |
| 27 | +├── go.mod # Go module definition |
| 28 | +└── README.md # Documentation |
77 | 29 | ``` |
78 | 30 |
|
79 | | -To modify the parameters, edit the command section in docker-compose.yml: |
80 | | -```yaml |
81 | | -command: |
82 | | - - monitoring |
83 | | - - "--url=https://betterstack.com/webhook/xyz" |
84 | | - - "--interval=10" |
85 | | - - "--cpu-limit=90" |
86 | | - - "--memory-limit=80" |
87 | | - - "--disk-limit=85" |
88 | | -``` |
| 31 | +## Usage |
89 | 32 |
|
90 | | -## Building from Source |
| 33 | +### Building |
91 | 34 |
|
92 | | -1. Clone the repository: |
93 | 35 | ```bash |
| 36 | +# Clone the repository |
94 | 37 | git clone https://github.com/appwrite/monitoring.git |
95 | 38 | cd monitoring |
96 | | -``` |
97 | | - |
98 | | -2. Build the binary: |
99 | | -```bash |
100 | | -go build -o monitoring |
101 | | -``` |
102 | 39 |
|
103 | | -3. Run the monitoring tool: |
104 | | -```bash |
105 | | -monitoring --url=https://betterstack.com/webhook/xyz |
| 40 | +# Build the binary |
| 41 | +go build -o appwrite-monitor main.go |
106 | 42 | ``` |
107 | 43 |
|
108 | | -## Development |
109 | | - |
110 | | -### Requirements |
111 | | -- Go 1.21 or later |
112 | | -- Docker and Docker Compose (for containerized deployment) |
| 44 | +### Running |
113 | 45 |
|
114 | | -### Local Development |
115 | | -1. Install dependencies: |
116 | 46 | ```bash |
117 | | -go mod download |
| 47 | +# Basic usage |
| 48 | +./appwrite-monitor --url="https://betterstack-webhook-url" |
| 49 | + |
| 50 | +# With custom thresholds |
| 51 | +./appwrite-monitor \ |
| 52 | + --url="https://betterstack-webhook-url" \ |
| 53 | + --interval=60 \ |
| 54 | + --cpu-limit=80 \ |
| 55 | + --memory-limit=85 \ |
| 56 | + --disk-limit=90 |
118 | 57 | ``` |
119 | 58 |
|
120 | | -2. Build and run: |
121 | | -```bash |
122 | | -go build -o monitoring |
123 | | -monitoring --url=https://betterstack.com/webhook/xyz |
124 | | -``` |
| 59 | +### Command Line Options |
125 | 60 |
|
126 | | -### Docker Development |
127 | | -``` |
128 | | -docker compose up -d |
129 | | -``` |
| 61 | +- `--url`: BetterStack webhook URL (required) |
| 62 | +- `--interval`: Check interval in seconds (default: 300) |
| 63 | +- `--cpu-limit`: CPU usage threshold percentage (default: 90) |
| 64 | +- `--memory-limit`: Memory usage threshold percentage (default: 90) |
| 65 | +- `--disk-limit`: Disk usage threshold percentage (default: 85) |
| 66 | + |
| 67 | +## How It Works |
130 | 68 |
|
131 | | -## License |
| 69 | +The monitoring tool uses Exponential Moving Average (EMA) to track resource usage over time, which helps prevent false alerts from momentary spikes. When the EMA of a resource exceeds the configured threshold, an alert is sent to BetterStack. |
132 | 70 |
|
133 | | -MIT License - see the [LICENSE](LICENSE) file for details |
| 71 | +The EMA smoothing factor is automatically calculated based on the check interval to provide roughly 5 minutes of smoothing. This means that sudden spikes will have less impact on the reported values, while sustained high usage will still trigger alerts. |
0 commit comments