Improve documentation and panic on invalid service
This commit is contained in:
parent
fe3e60dbd4
commit
2878ad6a27
25
README.md
25
README.md
@ -15,6 +15,8 @@ By default, the configuration file is expected to be at `config/config.yaml`.
|
|||||||
|
|
||||||
You can specify a custom path by setting the `GATUS_CONFIG_FILE` environment variable.
|
You can specify a custom path by setting the `GATUS_CONFIG_FILE` environment variable.
|
||||||
|
|
||||||
|
Here's a simple example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
metrics: true # Whether to expose metrics at /metrics
|
metrics: true # Whether to expose metrics at /metrics
|
||||||
services:
|
services:
|
||||||
@ -23,13 +25,9 @@ services:
|
|||||||
interval: 15s # Duration to wait between every status check (default: 10s)
|
interval: 15s # Duration to wait between every status check (default: 10s)
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200" # Status must be 200
|
- "[STATUS] == 200" # Status must be 200
|
||||||
|
- "[BODY].status == UP" # The json path "$.status" must be equal to UP
|
||||||
- "[RESPONSE_TIME] < 300" # Response time must be under 300ms
|
- "[RESPONSE_TIME] < 300" # Response time must be under 300ms
|
||||||
- name: github
|
- name: example
|
||||||
url: https://api.github.com/healthz
|
|
||||||
interval: 2m
|
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- name: Example
|
|
||||||
url: https://example.org/
|
url: https://example.org/
|
||||||
interval: 30s
|
interval: 30s
|
||||||
conditions:
|
conditions:
|
||||||
@ -39,6 +37,20 @@ services:
|
|||||||
Note that you can also add environment variables in the your configuration file (i.e. `$DOMAIN`, `${DOMAIN}`)
|
Note that you can also add environment variables in the your configuration file (i.e. `$DOMAIN`, `${DOMAIN}`)
|
||||||
|
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
| Parameter | Description | Default |
|
||||||
|
| ----------------------- | ------------------------------------------------------ | -------------- |
|
||||||
|
| `metrics` | Whether to expose metrics at /metrics | `false`
|
||||||
|
| `services[].name` | Name of the service. Can be anything. | Required `""`
|
||||||
|
| `services[].url` | URL to send the request to | Required `""`
|
||||||
|
| `services[].conditions` | Conditions used to determine the health of the service | `[]`
|
||||||
|
| `services[].interval` | Duration to wait between every status check | `10s`
|
||||||
|
| `services[].method` | Request method | `GET`
|
||||||
|
| `services[].body` | Request body | `""`
|
||||||
|
| `services[].headers` | Request headers | `{}`
|
||||||
|
|
||||||
|
|
||||||
### Conditions
|
### Conditions
|
||||||
|
|
||||||
Here are some examples of conditions you can use:
|
Here are some examples of conditions you can use:
|
||||||
@ -52,6 +64,7 @@ Here are some examples of conditions you can use:
|
|||||||
| `[RESPONSE_TIME] < 500` | Response time must be below 500ms | 100ms, 200ms, 300ms | 500ms, 1500ms |
|
| `[RESPONSE_TIME] < 500` | Response time must be below 500ms | 100ms, 200ms, 300ms | 500ms, 1500ms |
|
||||||
| `[BODY] == 1` | The body must be equal to 1 | 1 | literally anything else |
|
| `[BODY] == 1` | The body must be equal to 1 | 1 | literally anything else |
|
||||||
| `[BODY].data.id == 1` | The jsonpath `$.data.id` is equal to 1 | `{"data":{"id":1}}` | literally anything else |
|
| `[BODY].data.id == 1` | The jsonpath `$.data.id` is equal to 1 | `{"data":{"id":1}}` | literally anything else |
|
||||||
|
| `[BODY].data[0].id == 1` | The jsonpath `$.data[0].id` is equal to 1 | `{"data":[{"id":1}]}` | literally anything else |
|
||||||
|
|
||||||
**NOTE**: `[BODY]` with JSON path (i.e. `[BODY].id == 1`) is currently in BETA. For the most part, the only thing that doesn't work is arrays.
|
**NOTE**: `[BODY]` with JSON path (i.e. `[BODY].id == 1`) is currently in BETA. For the most part, the only thing that doesn't work is arrays.
|
||||||
|
|
||||||
|
32
config.yaml
32
config.yaml
@ -1,21 +1,21 @@
|
|||||||
metrics: true
|
metrics: true
|
||||||
services:
|
services:
|
||||||
# - name: twinnation
|
- name: twinnation
|
||||||
# interval: 10s
|
|
||||||
# url: https://twinnation.org/health
|
|
||||||
# conditions:
|
|
||||||
# - "[STATUS] == 200"
|
|
||||||
# - "[RESPONSE_TIME] < 1000"
|
|
||||||
# - "[BODY].status == UP"
|
|
||||||
- name: twinnation-articles-api
|
|
||||||
interval: 10s
|
interval: 10s
|
||||||
url: https://twinnation.org/api/v1/articles
|
url: https://twinnation.org/health
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 1000"
|
||||||
|
- name: twinnation-articles-api
|
||||||
|
interval: 10s
|
||||||
|
url: https://twinnation.org/api/v1/articles/24
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].id == 24"
|
||||||
|
- "[BODY].tags[0] == spring"
|
||||||
|
- name: example
|
||||||
|
url: https://example.org/
|
||||||
|
interval: 30s
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].[0].id == 42"
|
|
||||||
|
|
||||||
# - name: example
|
|
||||||
# url: https://example.org/
|
|
||||||
# interval: 30s
|
|
||||||
# conditions:
|
|
||||||
# - "[STATUS] == 200"
|
|
||||||
|
@ -2,6 +2,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"github.com/TwinProduction/gatus/client"
|
"github.com/TwinProduction/gatus/client"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -10,13 +11,18 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNoCondition = errors.New("you must specify at least one condition per service")
|
||||||
|
ErrNoUrl = errors.New("you must specify an url for each service")
|
||||||
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Interval time.Duration `yaml:"interval,omitempty"`
|
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Method string `yaml:"method,omitempty"`
|
Method string `yaml:"method,omitempty"`
|
||||||
Body string `yaml:"body,omitempty"`
|
Body string `yaml:"body,omitempty"`
|
||||||
Headers map[string]string `yaml:"headers"`
|
Headers map[string]string `yaml:"headers,omitempty"`
|
||||||
|
Interval time.Duration `yaml:"interval,omitempty"`
|
||||||
Conditions []*Condition `yaml:"conditions"`
|
Conditions []*Condition `yaml:"conditions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +34,15 @@ func (service *Service) Validate() {
|
|||||||
if len(service.Method) == 0 {
|
if len(service.Method) == 0 {
|
||||||
service.Method = http.MethodGet
|
service.Method = http.MethodGet
|
||||||
}
|
}
|
||||||
|
if len(service.Headers) == 0 {
|
||||||
|
service.Headers = make(map[string]string)
|
||||||
|
}
|
||||||
|
if len(service.Url) == 0 {
|
||||||
|
panic(ErrNoUrl)
|
||||||
|
}
|
||||||
|
if len(service.Conditions) == 0 {
|
||||||
|
panic(ErrNoCondition)
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure that the request can be created
|
// Make sure that the request can be created
|
||||||
_, err := http.NewRequest(service.Method, service.Url, bytes.NewBuffer([]byte(service.Body)))
|
_, err := http.NewRequest(service.Method, service.Url, bytes.NewBuffer([]byte(service.Body)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user