Skip to content

Commit 7c078fa

Browse files
authored
Merge pull request #1 from exelban/dev
Release version
2 parents 7311aaf + 32c848e commit 7c078fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4233
-2805
lines changed

.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.idea
22
.git
3+
.DS_Store
34
config.yaml
45
mock_test.go
5-
admin/dist
6+
*.db
7+
.run
8+
example.yaml

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.DS_Store
33
config.yaml
44
mock_test.go
5-
todo.md
5+
*.db
6+
.run

.one

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: JAM
2+
context: services
3+
image: exelban/jam:latest
4+
build:
5+
push: true
6+
platforms: linux/amd64

Dockerfile

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
FROM exelban/baseimage:node-14 as build-web
2-
3-
WORKDIR /app/
4-
5-
COPY admin/package*.json ./
6-
COPY admin/yarn.lock ./
7-
RUN yarn --silent
8-
9-
COPY admin/ .
10-
RUN yarn build
11-
12-
FROM exelban/baseimage:golang-1.18 as build-app
1+
FROM exelban/baseimage:golang-latest as build-app
132

143
WORKDIR /app/
154
COPY go.mod .
165
COPY go.sum .
176
RUN go mod download
18-
19-
COPY --from=build-web /app/dist /app/admin/dist
207
COPY . .
218

229
RUN go build -o ./bin/main ./main.go
2310

2411
FROM exelban/baseimage:alpine-latest
25-
WORKDIR /srv
26-
COPY --from=build-app /app/bin/main /srv/main
12+
EXPOSE 8822
13+
WORKDIR /app
14+
COPY --from=build-app /app/bin/main /app/main
2715
ENTRYPOINT ./main

README.md

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
1-
# cheks
1+
# JAM
22

3-
[![Cheks](https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/cheks/preview.png)](https://github.com/exelban/cheks/releases)
3+
[![JAM](https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/JAM/cover.png)](https://github.com/exelban/JAM)
44

5-
Simple monitoring for APIs and servers with dashboard and alerts.
5+
Just Another Monitoring
66

7-
## Install
8-
To run the Cheks you need to have a docker and configuration file.
7+
## Description
8+
JAM is a simple monitoring tool application.
9+
It allows you to monitor the status of your services and applications by sending HTTP requests to them and checking the response status code.
10+
The main idea is to have a simple and easy-to-use monitoring tool with minimalistic and nice design.
911

10-
Cheks provides small prebuild images for different architectures and operating systems.
11-
You could use an image from Docker Hub `exelban/cheks` or GitHub package registry `ghcr.io/exelban/cheks`.
12+
For now it is in the development stage and has a lot of features to be implemented. Such as proper alerts, more monitoring options, events history and more.
1213

13-
The easiest way to run Checks is to use docker-compose:
14+
## Features
15+
- 90 days history
16+
- groups of hosts
17+
- alerts (in progress)
18+
- events history (in progress)
19+
- multiple databases support (in progress, only bolt and in-memory for now)
1420

15-
```yaml
16-
version: "3"
21+
## Installation
1722

18-
services:
19-
cheks:
20-
image: exelban/cheks
21-
ports:
22-
- "8080:8080"
23-
volumes:
24-
- ${PWD}/config.yaml:/srv/config.yaml
25-
```
23+
Application is available as a Docker image. You can pull it from the Docker Hub or GitHub Registry:
24+
- [exelban/jam:latest](https://hub.docker.com/r/exelban/jam)
25+
- [ghcr.io/exelban/jam:latest](https://github.com/users/exelban/packages/container/package/jam)
2626

27-
or with docker:
27+
Also you can build it from the source code or use the precompiled binaries. But docker is the easiest way to run the application. And it is recommended to use it.
2828

29-
```shell
30-
docker run -p 8080:8080 -v $(pwd)/config.yaml:./srv/config.yaml exelban/cheks
29+
### Docker
30+
```bash
31+
docker run -d -v ./jam.yaml:/app/config.yaml exelban/jam:latest
3132
```
3233

33-
## Parameters
34-
35-
| Command line | Environment | Default | Description |
36-
| ------------ | ----------- | ------- | ----------- |
37-
| config | CONFIG | ./config.yaml | Path to the configuration file |
38-
| auth | AUTH | false | Secure dashboard with credentials |
39-
| username | USERNAME | | Username for the dashboard (only if auth is true). Required if AUTH=true |
40-
| password | PASSWORD | | Password for the dashboard. If empty, will be generated on the first run |
41-
42-
## Configuration file
43-
The simplest configuration file could only have a list of hosts:
44-
34+
### Docker Compose
4535
```yaml
46-
hosts:
47-
- url: https://github.com
48-
- url: https://google.com
49-
- url: https://facebook.com
36+
services:
37+
jam:
38+
image: exelban/jam:latest
39+
container_name: jam
40+
restart: unless-stopped
41+
volumes:
42+
- ./jam.yaml:/app/config.yaml
43+
logging:
44+
driver: "json-file"
45+
options:
46+
max-size: "10m"
47+
max-file: "3"
48+
healthcheck:
49+
test: "curl -f http://localhost:8822/healthz || exit 1"
50+
interval: 10s
51+
timeout: 10s
52+
retries: 3
53+
start_period: 3s
5054
```
5155
52-
Optional configuration for host:
53-
- `name: string` - name
54-
- `tags: [string]` - list of tags
56+
### Precompiled binaries
57+
You can download the precompiled binaries from the [releases](https://github.com/exelban/JAM/releases) page.
5558
56-
- `retry: string` - retry interval for request. Allowed golang style durations: 10s, 60s, 3m.
57-
- `timeout: string` - retry interval for request. Allowed golang style durations: 10s, 60s, 3m.
58-
- `initialDelay: string` - timeout before the request will be canceled. Allowed golang style durations: 10s, 60s, 3m.
59-
- `successThreshold: int` - number of success requests before host will be marked as live
60-
- `failureThreshold: int` - number of failed requests before host will be marked as dead
59+
### Build from source
60+
To build the application from the source code you need to have [Go](https://go.dev/doc/install) installed on your machine.
6161
62-
- `success` - allows to define success request parameters as response code and response body:
63-
64-
```yaml
65-
success:
66-
code: [200, 201, 202]
67-
body: {"ok": true}
62+
```bash
63+
git clone https://github.com/exelban/JAM.git
64+
cd JAM
65+
go build -o jam cmd/jam/main.go
66+
./jam
6867
```
6968

70-
- `headers: map[string]string` - you could specify the headers which will be sent with the request
69+
## Configuration
70+
The application is configured via JSON or YAML file. You can find the [example](https://github.com/exelban/JAM/blob/master/example.yaml) of the configuration file in the repository.
71+
You can set the path to the configuration file via the `--config-path` flag (`CONFIG_PATH` env) or by default it will look for the `config.yaml` file in the current directory.
7172

7273
## License
73-
[MIT License](https://github.com/exelban/cheks/blob/master/LICENSE)
74+
[MIT License](https://github.com/exelban/JAM/blob/master/LICENSE)

api/middleware.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package api
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"os"
7+
"runtime/debug"
8+
)
9+
10+
func Recoverer(next http.Handler) http.Handler {
11+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12+
defer func() {
13+
if rvr := recover(); rvr != nil && rvr != http.ErrAbortHandler {
14+
_, _ = fmt.Fprintf(os.Stderr, "Panic: %+v\n", rvr)
15+
debug.PrintStack()
16+
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
17+
}
18+
}()
19+
next.ServeHTTP(w, r)
20+
})
21+
}
22+
23+
func CORS(next http.Handler) http.Handler {
24+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
25+
w.Header().Set("Access-Control-Allow-Origin", "*")
26+
w.Header().Set("Access-Control-Allow-Methods", "GET")
27+
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
28+
if r.Method == http.MethodOptions {
29+
w.WriteHeader(http.StatusOK)
30+
return
31+
}
32+
next.ServeHTTP(w, r)
33+
})
34+
}
35+
36+
func Healthz(next http.Handler) http.Handler {
37+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
38+
if r.URL.Path == "/healthz" {
39+
w.WriteHeader(http.StatusOK)
40+
_, _ = w.Write([]byte("ok"))
41+
return
42+
}
43+
next.ServeHTTP(w, r)
44+
})
45+
}
46+
47+
func Info(app, version string) func(http.Handler) http.Handler {
48+
f := func(h http.Handler) http.Handler {
49+
fn := func(w http.ResponseWriter, r *http.Request) {
50+
w.Header().Set("App-Name", app)
51+
w.Header().Set("App-Version", version)
52+
h.ServeHTTP(w, r)
53+
}
54+
return http.HandlerFunc(fn)
55+
}
56+
return f
57+
}

0 commit comments

Comments
 (0)