Skip to content

Commit 206ee48

Browse files
committed
feat: initial commit
0 parents  commit 206ee48

File tree

9 files changed

+642
-0
lines changed

9 files changed

+642
-0
lines changed

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BETTER_STACK_URL=https://uptime.betterstack.com/api/v1/incoming-webhook/HYqP4eAdUr1q9WFQLdMvetUj
2+
CHECK_INTERVAL=10
3+
CPU_LIMIT=90
4+
MEMORY_LIMIT=90
5+
DISK_LIMIT=85

.github/workflows/docker-publish.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout the repo
12+
uses: actions/checkout@v4
13+
14+
- name: Login to DockerHub
15+
uses: docker/login-action@v1
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.actor }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Build and push
22+
uses: docker/build-push-action@v5
23+
with:
24+
context: .
25+
push: true
26+
tags: ghcr.io/appwrite/monitoring:${{ env.TAG }}

Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM golang:1.21-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache gcc musl-dev
7+
8+
# Copy go mod files
9+
COPY go.mod go.sum ./
10+
11+
# Download dependencies
12+
RUN go mod download
13+
14+
# Copy source code
15+
COPY . .
16+
17+
# Build the application
18+
RUN CGO_ENABLED=1 GOOS=linux go build -a -o monitoring .
19+
20+
# Copy the monitoring binary to /usr/local/bin to make it available in PATH
21+
COPY monitoring /usr/local/bin/monitoring
22+
RUN chmod +x /usr/local/bin/monitoring
23+
24+
# Final stage
25+
FROM alpine:3.19
26+
27+
WORKDIR /app
28+
29+
# Install runtime dependencies
30+
RUN apk add --no-cache ca-certificates
31+
32+
# Copy binary from builder
33+
COPY --from=builder /app/monitoring .

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Appwrite
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# System Monitoring
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 (formerly BetterUptime).
4+
5+
## Features
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
13+
14+
## Command Line Usage
15+
16+
The monitoring tool is configured through command-line flags:
17+
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+
```
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
77+
```
78+
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+
```
89+
90+
## Building from Source
91+
92+
1. Clone the repository:
93+
```bash
94+
git clone https://github.com/appwrite/monitoring.git
95+
cd monitoring
96+
```
97+
98+
2. Build the binary:
99+
```bash
100+
go build -o monitoring
101+
```
102+
103+
3. Run the monitoring tool:
104+
```bash
105+
monitoring --url=https://betterstack.com/webhook/xyz
106+
```
107+
108+
## Development
109+
110+
### Requirements
111+
- Go 1.21 or later
112+
- Docker and Docker Compose (for containerized deployment)
113+
114+
### Local Development
115+
1. Install dependencies:
116+
```bash
117+
go mod download
118+
```
119+
120+
2. Build and run:
121+
```bash
122+
go build -o monitoring
123+
monitoring --url=https://betterstack.com/webhook/xyz
124+
```
125+
126+
### Docker Development
127+
1. Build the image:
128+
```bash
129+
docker build -t monitoring .
130+
```
131+
132+
2. Run with Docker:
133+
```bash
134+
# Show help
135+
docker run --rm ghcr.io/appwrite/monitoring:latest monitoring --help
136+
137+
# Run monitoring with custom parameters
138+
docker run -d \
139+
--name monitoring \
140+
--privileged \
141+
--pid=host \
142+
-v /:/host:ro \
143+
ghcr.io/appwrite/monitoring:latest \
144+
monitoring \
145+
--url=https://betterstack.com/webhook/xyz \
146+
--interval=60
147+
```
148+
149+
## License
150+
151+
MIT License - see the [LICENSE](LICENSE) file for details

docker-compose.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3.8'
2+
3+
services:
4+
monitoring:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
command:
9+
- monitoring
10+
- "--url=${BETTER_STACK_URL}"
11+
- "--interval=10"
12+
- "--cpu-limit=90"
13+
- "--memory-limit=80"
14+
- "--disk-limit=85"
15+
volumes:
16+
- /:/host:ro
17+
pid: host
18+
privileged: true
19+
restart: unless-stopped

go.mod

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/appwrite/monitoring
2+
3+
go 1.19
4+
5+
require github.com/shirou/gopsutil/v3 v3.24.1
6+
7+
require (
8+
github.com/go-ole/go-ole v1.2.6 // indirect
9+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
10+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
11+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
12+
github.com/tklauser/go-sysconf v0.3.12 // indirect
13+
github.com/tklauser/numcpus v0.6.1 // indirect
14+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
15+
golang.org/x/sys v0.16.0 // indirect
16+
)

go.sum

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
5+
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
6+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
8+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
9+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
11+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
12+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
13+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
15+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
16+
github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI=
17+
github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU=
18+
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
19+
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
20+
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
21+
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
22+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
23+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
24+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
25+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
26+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
27+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
28+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
29+
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
30+
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
31+
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
32+
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
33+
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
34+
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
35+
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
36+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
37+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
39+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
40+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
41+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
42+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
43+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
44+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
45+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)