Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88d0d8a724 | ||
|
|
5803dca3a5 | ||
|
|
f98c60467d | ||
|
|
c51f35bcea | ||
|
|
02098a9742 | ||
|
|
3e2b56ba89 | ||
|
|
15b8f8a293 | ||
|
|
58327394dd | ||
|
|
49f5940a43 | ||
|
|
1f177902e6 | ||
|
|
6888ced1a7 | ||
|
|
cc159fa8fb | ||
|
|
92cb9c86d1 | ||
|
|
1701ced07b | ||
|
|
fe82465c19 | ||
|
|
ab73c4666e | ||
|
|
16837562ea |
No files matched your search
@@ -0,0 +1,27 @@
|
|||||||
|
name: build
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '*.md'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '*.md'
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.14
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Build binary to make sure it works
|
||||||
|
run: go build -mod vendor
|
||||||
|
- name: Test
|
||||||
|
run: go test -mod vendor -cover ./...
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
name: Go
|
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
build-112:
|
|
||||||
name: Build with Go 1.12
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Go 1.12
|
|
||||||
uses: actions/setup-go@v1
|
|
||||||
with:
|
|
||||||
go-version: 1.12
|
|
||||||
id: go
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
- name: Test
|
|
||||||
run: go test -mod vendor ./...
|
|
||||||
- name: Build
|
|
||||||
run: go build -mod vendor
|
|
||||||
|
|
||||||
build-113:
|
|
||||||
name: Build with Go 1.13
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Go 1.13
|
|
||||||
uses: actions/setup-go@v1
|
|
||||||
with:
|
|
||||||
go-version: 1.13
|
|
||||||
id: go
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
- name: Test
|
|
||||||
run: go test -mod vendor ./...
|
|
||||||
- name: Build
|
|
||||||
run: go build -mod vendor
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
# gatus
|
# gatus
|
||||||
|
|
||||||
|

|
||||||
[](https://cloud.docker.com/repository/docker/twinproduction/gatus)
|
[](https://cloud.docker.com/repository/docker/twinproduction/gatus)
|
||||||
|
|
||||||
A service health dashboard in Go that is meant to be used as a docker
|
A service health dashboard in Go that is meant to be used as a docker
|
||||||
@@ -10,16 +11,27 @@ Live example: https://status.twinnation.org/
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
metrics: true # Whether to expose metrics at /metrics
|
metrics: true # Whether to expose metrics at /metrics
|
||||||
services:
|
services:
|
||||||
- name: twinnation # Name of your service, can be anything
|
- name: twinnation # Name of your service, can be anything
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/health
|
||||||
interval: 15s # Duration to wait between every status check (opt. default: 10s)
|
interval: 15s # Duration to wait between every status check (default: 10s)
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200" # Status must be 200
|
||||||
|
- "[RESPONSE_TIME] < 300" # Response time must be under 300ms
|
||||||
- name: github
|
- name: github
|
||||||
url: https://api.github.com/healthz
|
url: https://api.github.com/healthz
|
||||||
|
interval: 2m
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- name: Example
|
||||||
|
url: https://example.org/
|
||||||
|
interval: 30s
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
```
|
```
|
||||||
@@ -27,6 +39,23 @@ 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}`)
|
||||||
|
|
||||||
|
|
||||||
|
### Conditions
|
||||||
|
|
||||||
|
Here are some examples of conditions you can use:
|
||||||
|
|
||||||
|
| Condition | Description | Passing values | Failing values |
|
||||||
|
| ------------------------------------- | ----------------------------------------- | ------------------------ | ----------------------- |
|
||||||
|
| `[STATUS] == 200` | Status must be equal to 200 | 200 | 201, 404, 500 |
|
||||||
|
| `[STATUS] < 300` | Status must lower than 300 | 200, 201, 299 | 301, 302, 400, 500 |
|
||||||
|
| `[STATUS] <= 299` | Status must be less than or equal to 299 | 200, 201, 299 | 301, 302, 400, 500 |
|
||||||
|
| `[STATUS] > 400` | Status must be greater than 400 | 401, 402, 403, 404 | 200, 201, 300, 400 |
|
||||||
|
| `[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].data.id == 1` | The jsonpath `$.data.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.
|
||||||
|
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
Building the Docker image is done as following:
|
Building the Docker image is done as following:
|
||||||
|
|||||||
+8
-5
@@ -1,11 +1,14 @@
|
|||||||
metrics: true
|
metrics: true
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: Twinnation
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/health
|
||||||
interval: 15s
|
interval: 10s
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- name: github
|
- "[RESPONSE_TIME] < 500"
|
||||||
url: https://api.github.com/healthz
|
- "[BODY].status == UP"
|
||||||
|
- name: Example
|
||||||
|
url: https://example.org/
|
||||||
|
interval: 30s
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
+63
-45
@@ -2,6 +2,8 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/TwinProduction/gatus/jsonpath"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -10,20 +12,23 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusPlaceholder = "[STATUS]"
|
||||||
|
IPPlaceHolder = "[IP]"
|
||||||
|
ResponseTimePlaceHolder = "[RESPONSE_TIME]"
|
||||||
|
BodyPlaceHolder = "[BODY]"
|
||||||
|
)
|
||||||
|
|
||||||
type HealthStatus struct {
|
type HealthStatus struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerMessage struct {
|
|
||||||
Error bool `json:"error"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
HttpStatus int `json:"status"`
|
HttpStatus int `json:"status"`
|
||||||
|
Body []byte `json:"-"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Ip string `json:"ip"`
|
Ip string `json:"-"`
|
||||||
Duration time.Duration `json:"duration"`
|
Duration time.Duration `json:"duration"`
|
||||||
Errors []string `json:"errors"`
|
Errors []string `json:"errors"`
|
||||||
ConditionResults []*ConditionResult `json:"condition-results"`
|
ConditionResults []*ConditionResult `json:"condition-results"`
|
||||||
@@ -53,7 +58,8 @@ func (service *Service) getIp(result *Result) {
|
|||||||
result.Ip = ips[0].String()
|
result.Ip = ips[0].String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *Service) getStatus(result *Result) {
|
func (service *Service) call(result *Result) {
|
||||||
|
// TODO: re-use the same client instead of creating multiple clients
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: time.Second * 10,
|
Timeout: time.Second * 10,
|
||||||
}
|
}
|
||||||
@@ -65,18 +71,22 @@ func (service *Service) getStatus(result *Result) {
|
|||||||
}
|
}
|
||||||
result.Duration = time.Now().Sub(startTime)
|
result.Duration = time.Now().Sub(startTime)
|
||||||
result.HttpStatus = response.StatusCode
|
result.HttpStatus = response.StatusCode
|
||||||
|
result.Body, err = ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
result.Errors = append(result.Errors, err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *Service) EvaluateConditions() *Result {
|
func (service *Service) EvaluateConditions() *Result {
|
||||||
result := &Result{Success: true, Errors: []string{}}
|
result := &Result{Success: true, Errors: []string{}}
|
||||||
service.getIp(result)
|
service.getIp(result)
|
||||||
if len(result.Errors) == 0 {
|
if len(result.Errors) == 0 {
|
||||||
service.getStatus(result)
|
service.call(result)
|
||||||
} else {
|
} else {
|
||||||
result.Success = false
|
result.Success = false
|
||||||
}
|
}
|
||||||
for _, condition := range service.Conditions {
|
for _, condition := range service.Conditions {
|
||||||
success := condition.Evaluate(result)
|
success := condition.evaluate(result)
|
||||||
if !success {
|
if !success {
|
||||||
result.Success = false
|
result.Success = false
|
||||||
}
|
}
|
||||||
@@ -86,53 +96,39 @@ func (service *Service) EvaluateConditions() *Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConditionResult struct {
|
type ConditionResult struct {
|
||||||
Condition *Condition `json:"condition"`
|
Condition *Condition `json:"condition"`
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Explanation string `json:"explanation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Condition string
|
type Condition string
|
||||||
|
|
||||||
func (c *Condition) Evaluate(result *Result) bool {
|
func (c *Condition) evaluate(result *Result) bool {
|
||||||
condition := string(*c)
|
condition := string(*c)
|
||||||
|
success := false
|
||||||
if strings.Contains(condition, "==") {
|
if strings.Contains(condition, "==") {
|
||||||
parts := sanitizeAndResolve(strings.Split(condition, "=="), result)
|
parts := sanitizeAndResolve(strings.Split(condition, "=="), result)
|
||||||
if parts[0] == parts[1] {
|
success = parts[0] == parts[1]
|
||||||
result.ConditionResults = append(result.ConditionResults, &ConditionResult{
|
|
||||||
Condition: c,
|
|
||||||
Success: true,
|
|
||||||
Explanation: fmt.Sprintf("%s is equal to %s", parts[0], parts[1]),
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
result.ConditionResults = append(result.ConditionResults, &ConditionResult{
|
|
||||||
Condition: c,
|
|
||||||
Success: false,
|
|
||||||
Explanation: fmt.Sprintf("%s is not equal to %s", parts[0], parts[1]),
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else if strings.Contains(condition, "!=") {
|
} else if strings.Contains(condition, "!=") {
|
||||||
parts := sanitizeAndResolve(strings.Split(condition, "!="), result)
|
parts := sanitizeAndResolve(strings.Split(condition, "!="), result)
|
||||||
if parts[0] != parts[1] {
|
success = parts[0] != parts[1]
|
||||||
result.ConditionResults = append(result.ConditionResults, &ConditionResult{
|
} else if strings.Contains(condition, "<=") {
|
||||||
Condition: c,
|
parts := sanitizeAndResolveNumerical(strings.Split(condition, "<="), result)
|
||||||
Success: true,
|
success = parts[0] <= parts[1]
|
||||||
Explanation: fmt.Sprintf("%s is not equal to %s", parts[0], parts[1]),
|
} else if strings.Contains(condition, ">=") {
|
||||||
})
|
parts := sanitizeAndResolveNumerical(strings.Split(condition, ">="), result)
|
||||||
return true
|
success = parts[0] >= parts[1]
|
||||||
} else {
|
} else if strings.Contains(condition, ">") {
|
||||||
result.ConditionResults = append(result.ConditionResults, &ConditionResult{
|
parts := sanitizeAndResolveNumerical(strings.Split(condition, ">"), result)
|
||||||
Condition: c,
|
success = parts[0] > parts[1]
|
||||||
Success: false,
|
} else if strings.Contains(condition, "<") {
|
||||||
Explanation: fmt.Sprintf("%s is equal to %s", parts[0], parts[1]),
|
parts := sanitizeAndResolveNumerical(strings.Split(condition, "<"), result)
|
||||||
})
|
success = parts[0] < parts[1]
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
result.Errors = append(result.Errors, fmt.Sprintf("invalid condition '%s' has been provided", condition))
|
result.Errors = append(result.Errors, fmt.Sprintf("invalid condition '%s' has been provided", condition))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
result.ConditionResults = append(result.ConditionResults, &ConditionResult{Condition: c, Success: success})
|
||||||
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanitizeAndResolve(list []string, result *Result) []string {
|
func sanitizeAndResolve(list []string, result *Result) []string {
|
||||||
@@ -140,13 +136,35 @@ func sanitizeAndResolve(list []string, result *Result) []string {
|
|||||||
for _, element := range list {
|
for _, element := range list {
|
||||||
element = strings.TrimSpace(element)
|
element = strings.TrimSpace(element)
|
||||||
switch strings.ToUpper(element) {
|
switch strings.ToUpper(element) {
|
||||||
case "[STATUS]":
|
case StatusPlaceholder:
|
||||||
element = strconv.Itoa(result.HttpStatus)
|
element = strconv.Itoa(result.HttpStatus)
|
||||||
case "[IP]":
|
case IPPlaceHolder:
|
||||||
element = result.Ip
|
element = result.Ip
|
||||||
|
case ResponseTimePlaceHolder:
|
||||||
|
element = strconv.Itoa(int(result.Duration.Milliseconds()))
|
||||||
|
case BodyPlaceHolder:
|
||||||
|
element = string(result.Body)
|
||||||
default:
|
default:
|
||||||
|
// if starts with BodyPlaceHolder, then do the jsonpath thingy
|
||||||
|
if strings.HasPrefix(element, BodyPlaceHolder) {
|
||||||
|
element = jsonpath.Eval(strings.Replace(element, fmt.Sprintf("%s.", BodyPlaceHolder), "", 1), result.Body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sanitizedList = append(sanitizedList, element)
|
sanitizedList = append(sanitizedList, element)
|
||||||
}
|
}
|
||||||
return sanitizedList
|
return sanitizedList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeAndResolveNumerical(list []string, result *Result) []int {
|
||||||
|
var sanitizedNumbers []int
|
||||||
|
sanitizedList := sanitizeAndResolve(list, result)
|
||||||
|
for _, element := range sanitizedList {
|
||||||
|
if number, err := strconv.Atoi(element); err != nil {
|
||||||
|
// Default to 0 if the string couldn't be converted to an integer
|
||||||
|
sanitizedNumbers = append(sanitizedNumbers, 0)
|
||||||
|
} else {
|
||||||
|
sanitizedNumbers = append(sanitizedNumbers, number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sanitizedNumbers
|
||||||
|
}
|
||||||
+135
-8
@@ -2,12 +2,13 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEvaluateWithIp(t *testing.T) {
|
func TestEvaluateWithIp(t *testing.T) {
|
||||||
condition := Condition("[IP] == 127.0.0.1")
|
condition := Condition("[IP] == 127.0.0.1")
|
||||||
result := &Result{Ip: "127.0.0.1"}
|
result := &Result{Ip: "127.0.0.1"}
|
||||||
condition.Evaluate(result)
|
condition.evaluate(result)
|
||||||
if !result.ConditionResults[0].Success {
|
if !result.ConditionResults[0].Success {
|
||||||
t.Errorf("Condition '%s' should have been a success", condition)
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
}
|
}
|
||||||
@@ -16,16 +17,142 @@ func TestEvaluateWithIp(t *testing.T) {
|
|||||||
func TestEvaluateWithStatus(t *testing.T) {
|
func TestEvaluateWithStatus(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 201")
|
condition := Condition("[STATUS] == 201")
|
||||||
result := &Result{HttpStatus: 201}
|
result := &Result{HttpStatus: 201}
|
||||||
condition.Evaluate(result)
|
condition.evaluate(result)
|
||||||
if !result.ConditionResults[0].Success {
|
if !result.ConditionResults[0].Success {
|
||||||
t.Errorf("Condition '%s' should have been a success", condition)
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvaluateWithFailure(t *testing.T) {
|
func TestEvaluateWithStatusFailure(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
result := &Result{HttpStatus: 500}
|
result := &Result{HttpStatus: 500}
|
||||||
condition.Evaluate(result)
|
condition.evaluate(result)
|
||||||
|
if result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithStatusUsingLessThan(t *testing.T) {
|
||||||
|
condition := Condition("[STATUS] < 300")
|
||||||
|
result := &Result{HttpStatus: 201}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithStatusFailureUsingLessThan(t *testing.T) {
|
||||||
|
condition := Condition("[STATUS] < 300")
|
||||||
|
result := &Result{HttpStatus: 404}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithResponseTimeUsingLessThan(t *testing.T) {
|
||||||
|
condition := Condition("[RESPONSE_TIME] < 500")
|
||||||
|
result := &Result{Duration: time.Millisecond * 50}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithResponseTimeUsingGreaterThan(t *testing.T) {
|
||||||
|
condition := Condition("[RESPONSE_TIME] > 500")
|
||||||
|
result := &Result{Duration: time.Millisecond * 750}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithResponseTimeUsingGreaterThanOrEqualTo(t *testing.T) {
|
||||||
|
condition := Condition("[RESPONSE_TIME] >= 500")
|
||||||
|
result := &Result{Duration: time.Millisecond * 500}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithResponseTimeUsingLessThanOrEqualTo(t *testing.T) {
|
||||||
|
condition := Condition("[RESPONSE_TIME] <= 500")
|
||||||
|
result := &Result{Duration: time.Millisecond * 500}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBody(t *testing.T) {
|
||||||
|
condition := Condition("[BODY] == test")
|
||||||
|
result := &Result{Body: []byte("test")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPath(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].status == UP")
|
||||||
|
result := &Result{Body: []byte("{\"status\":\"UP\"}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplex(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.name == john")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 1, \"name\": \"john\"}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplexInt(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.id == 1")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplexIntUsingGreaterThan(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.id > 0")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplexIntFailureUsingGreaterThan(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.id > 5")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplexIntUsingLessThan(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.id < 5")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 2}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
|
if !result.ConditionResults[0].Success {
|
||||||
|
t.Errorf("Condition '%s' should have been a success", condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvaluateWithBodyJsonPathComplexIntFailureUsingLessThan(t *testing.T) {
|
||||||
|
condition := Condition("[BODY].data.id < 5")
|
||||||
|
result := &Result{Body: []byte("{\"data\": {\"id\": 10}}")}
|
||||||
|
condition.evaluate(result)
|
||||||
if result.ConditionResults[0].Success {
|
if result.ConditionResults[0].Success {
|
||||||
t.Errorf("Condition '%s' should have been a failure", condition)
|
t.Errorf("Condition '%s' should have been a failure", condition)
|
||||||
}
|
}
|
||||||
@@ -34,8 +161,8 @@ func TestEvaluateWithFailure(t *testing.T) {
|
|||||||
func TestIntegrationEvaluateConditions(t *testing.T) {
|
func TestIntegrationEvaluateConditions(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "GitHub",
|
Name: "TwiNNatioN",
|
||||||
Url: "https://api.github.com/healthz",
|
Url: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
result := service.EvaluateConditions()
|
result := service.EvaluateConditions()
|
||||||
@@ -50,8 +177,8 @@ func TestIntegrationEvaluateConditions(t *testing.T) {
|
|||||||
func TestIntegrationEvaluateConditionsWithFailure(t *testing.T) {
|
func TestIntegrationEvaluateConditionsWithFailure(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 500")
|
condition := Condition("[STATUS] == 500")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "GitHub",
|
Name: "TwiNNatioN",
|
||||||
Url: "https://api.github.com/healthz",
|
Url: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
result := service.EvaluateConditions()
|
result := service.EvaluateConditions()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
metrics: true
|
metrics: true
|
||||||
services:
|
services:
|
||||||
- name: TwiNNatioN
|
- name: TwiNNatioN
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/health
|
||||||
interval: 10s
|
interval: 10s
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ data:
|
|||||||
metrics: true
|
metrics: true
|
||||||
services:
|
services:
|
||||||
- name: TwiNNatioN
|
- name: TwiNNatioN
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/health
|
||||||
interval: 1m
|
interval: 1m
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module github.com/TwinProduction/gatus
|
module github.com/TwinProduction/gatus
|
||||||
|
|
||||||
go 1.13
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/prometheus/client_golang v1.2.1
|
github.com/prometheus/client_golang v1.2.1
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package jsonpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Eval(path string, b []byte) string {
|
||||||
|
var object map[string]interface{}
|
||||||
|
err := json.Unmarshal(b, &object)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return walk(path, object)
|
||||||
|
}
|
||||||
|
|
||||||
|
func walk(path string, object map[string]interface{}) string {
|
||||||
|
keys := strings.Split(path, ".")
|
||||||
|
targetKey := keys[0]
|
||||||
|
// if there's only one key and the target key is that key, then return its value
|
||||||
|
if len(keys) == 1 {
|
||||||
|
return fmt.Sprintf("%v", object[targetKey])
|
||||||
|
}
|
||||||
|
// if there's more than one key, then walk deeper
|
||||||
|
if len(keys) > 0 {
|
||||||
|
return walk(strings.Replace(path, fmt.Sprintf("%s.", targetKey), "", 1), object[targetKey].(map[string]interface{}))
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
@@ -25,10 +25,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadConfiguration() *config.Config {
|
func loadConfiguration() *config.Config {
|
||||||
args := os.Args
|
|
||||||
var err error
|
var err error
|
||||||
if len(args) == 2 {
|
customConfigFile := os.Getenv("GATUS_CONFIG_FILE")
|
||||||
err = config.Load(args[1])
|
if len(customConfigFile) > 0 {
|
||||||
|
err = config.Load(customConfigFile)
|
||||||
} else {
|
} else {
|
||||||
err = config.LoadDefaultConfiguration()
|
err = config.LoadDefaultConfiguration()
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-32
@@ -4,11 +4,23 @@
|
|||||||
<title>Status</title>
|
<title>Status</title>
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||||
<style>
|
<style>
|
||||||
td > span.badge {
|
#results div.container:first-child {
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-top-right-radius: 3px;
|
||||||
|
}
|
||||||
|
#results div.container:last-child {
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
border-bottom-right-radius: 3px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-color: #dee2e6;
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
|
.status-ok {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 20px;
|
width: 1%;
|
||||||
cursor: default;
|
height: 20px;
|
||||||
margin-right: 2px;
|
margin-right: 4px;
|
||||||
|
background-color: #28a745;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -17,19 +29,7 @@
|
|||||||
<div class="text-center mb-3">
|
<div class="text-center mb-3">
|
||||||
<div class="display-4">Status</div>
|
<div class="display-4">Status</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-responsive">
|
<div id="results">
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Name</th>
|
|
||||||
<th scope="col">Status</th>
|
|
||||||
<th scope="col">Hostname</th>
|
|
||||||
<th scope="col">Response time</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="results">
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -38,12 +38,14 @@
|
|||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const OK = "<span class='badge badge-success' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>✓</span>";
|
//const OK = "<div class='status-ok' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'></div>"
|
||||||
const NOK = "<span class='badge badge-danger' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>X</span>";
|
const OK = "<span class='badge badge-success ml-1' style='width: 5%' title='__TIMESTAMP____RESPONSE_TIME____CONDITIONS____ERRORS__'>✓</span>";
|
||||||
|
const NOK = "<span class='badge badge-danger ml-1' style='width: 5%' title='__TIMESTAMP____RESPONSE_TIME____CONDITIONS____ERRORS__'>X</span>";
|
||||||
|
|
||||||
function generateServiceResultBox(serviceResult) {
|
function generateServiceResultBox(serviceResult) {
|
||||||
let output = (serviceResult.success ? OK : NOK);
|
let output = (serviceResult.success ? OK : NOK);
|
||||||
output = output.replace("__RESPONSE_TIME__", "Response time:\n" + parseInt(serviceResult.duration/1000000) + "ms");
|
output = output.replace("__TIMESTAMP__", "Timestamp:\n" + prettifyTimestamp(serviceResult.timestamp));
|
||||||
|
output = output.replace("__RESPONSE_TIME__", "\n\nResponse time:\n" + parseInt(serviceResult.duration/1000000) + "ms");
|
||||||
let conditions = "";
|
let conditions = "";
|
||||||
for (let conditionResultIndex in serviceResult['condition-results']) {
|
for (let conditionResultIndex in serviceResult['condition-results']) {
|
||||||
let conditionResult = serviceResult['condition-results'][conditionResultIndex];
|
let conditionResult = serviceResult['condition-results'][conditionResultIndex];
|
||||||
@@ -62,9 +64,9 @@
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshTable() {
|
function refreshResults() {
|
||||||
$.getJSON("/api/v1/results", function (data) {
|
$.getJSON("/api/v1/results", function (data) {
|
||||||
let tableBody = "";
|
let output = "";
|
||||||
for (let serviceName in data) {
|
for (let serviceName in data) {
|
||||||
let serviceStatusOverTime = "";
|
let serviceStatusOverTime = "";
|
||||||
let hostname = data[serviceName][data[serviceName].length-1].hostname
|
let hostname = data[serviceName][data[serviceName].length-1].hostname
|
||||||
@@ -82,21 +84,41 @@
|
|||||||
maxResponseTime = responseTime;
|
maxResponseTime = responseTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tableBody += ""
|
output += ""
|
||||||
+ "<tr>"
|
+ "<div class='container p-2 border-left border-right border-top border-black'>"
|
||||||
+ " <td>" + serviceName + "</td>"
|
+ " <div class='row mb-2'>"
|
||||||
+ " <td>" + serviceStatusOverTime + "</td>"
|
+ " <div class='col-8'>"
|
||||||
+ " <td><a href=\"//" + hostname + "\">" + hostname + "</a></td>"
|
+ " <span class='font-weight-bold'>" + serviceName + "</span> <span class='text-secondary font-weight-lighter'>- " + hostname + "</span>"
|
||||||
+ " <td>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</td>"
|
+ " </div>"
|
||||||
+ "</tr>";
|
+ " <div class='col-4 text-right'>"
|
||||||
|
+ " <span class='font-weight-lighter'>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</span>"
|
||||||
|
+ " </div>"
|
||||||
|
+ " </div>"
|
||||||
|
+ " <div class='row'>"
|
||||||
|
+ " <div class='col-12 d-flex flex-row-reverse'>"
|
||||||
|
+ " " + serviceStatusOverTime
|
||||||
|
+ " </div>"
|
||||||
|
+ " </div>"
|
||||||
|
+ "</div>";
|
||||||
}
|
}
|
||||||
$("#results").html(tableBody);
|
$("#results").html(output);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshTable();
|
function prettifyTimestamp(timestamp) {
|
||||||
|
let date = new Date(timestamp);
|
||||||
|
let YYYY = date.getFullYear();
|
||||||
|
let MM = ((date.getMonth()+1)<10?"0":"")+""+(date.getMonth()+1);
|
||||||
|
let DD = ((date.getDate())<10?"0":"")+""+(date.getDate());
|
||||||
|
let hh = ((date.getHours())<10?"0":"")+""+(date.getHours());
|
||||||
|
let mm = ((date.getMinutes())<10?"0":"")+""+(date.getMinutes());
|
||||||
|
let ss = ((date.getSeconds())<10?"0":"")+""+(date.getSeconds());
|
||||||
|
return YYYY+"-"+MM+"-"+DD+" "+hh+":"+mm+":"+ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshResults();
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
refreshTable();
|
refreshResults();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Vendored
+2
@@ -7,6 +7,7 @@ github.com/golang/protobuf/proto
|
|||||||
# github.com/matttproud/golang_protobuf_extensions v1.0.1
|
# github.com/matttproud/golang_protobuf_extensions v1.0.1
|
||||||
github.com/matttproud/golang_protobuf_extensions/pbutil
|
github.com/matttproud/golang_protobuf_extensions/pbutil
|
||||||
# github.com/prometheus/client_golang v1.2.1
|
# github.com/prometheus/client_golang v1.2.1
|
||||||
|
## explicit
|
||||||
github.com/prometheus/client_golang/prometheus
|
github.com/prometheus/client_golang/prometheus
|
||||||
github.com/prometheus/client_golang/prometheus/internal
|
github.com/prometheus/client_golang/prometheus/internal
|
||||||
github.com/prometheus/client_golang/prometheus/promauto
|
github.com/prometheus/client_golang/prometheus/promauto
|
||||||
@@ -24,4 +25,5 @@ github.com/prometheus/procfs/internal/util
|
|||||||
# golang.org/x/sys v0.0.0-20191010194322-b09406accb47
|
# golang.org/x/sys v0.0.0-20191010194322-b09406accb47
|
||||||
golang.org/x/sys/windows
|
golang.org/x/sys/windows
|
||||||
# gopkg.in/yaml.v2 v2.2.2
|
# gopkg.in/yaml.v2 v2.2.2
|
||||||
|
## explicit
|
||||||
gopkg.in/yaml.v2
|
gopkg.in/yaml.v2
|
||||||
+27
-23
@@ -20,28 +20,32 @@ func GetServiceResults() *map[string][]*core.Result {
|
|||||||
|
|
||||||
func Monitor(cfg *config.Config) {
|
func Monitor(cfg *config.Config) {
|
||||||
for _, service := range cfg.Services {
|
for _, service := range cfg.Services {
|
||||||
go func(service *core.Service) {
|
go monitor(service)
|
||||||
for {
|
// To prevent multiple requests from running at the same time
|
||||||
log.Printf("[watchdog][Monitor] Monitoring serviceName=%s", service.Name)
|
time.Sleep(500 * time.Millisecond)
|
||||||
result := service.EvaluateConditions()
|
}
|
||||||
metric.PublishMetricsForService(service, result)
|
}
|
||||||
rwLock.Lock()
|
|
||||||
serviceResults[service.Name] = append(serviceResults[service.Name], result)
|
func monitor(service *core.Service) {
|
||||||
if len(serviceResults[service.Name]) > 10 {
|
for {
|
||||||
serviceResults[service.Name] = serviceResults[service.Name][1:]
|
// By placing the lock here, we prevent multiple services from being monitored at the exact same time, which
|
||||||
}
|
// could cause performance issues and return inaccurate results
|
||||||
rwLock.Unlock()
|
rwLock.Lock()
|
||||||
log.Printf(
|
log.Printf("[watchdog][Monitor] Monitoring serviceName=%s", service.Name)
|
||||||
"[watchdog][Monitor] Finished monitoring serviceName=%s; errors=%d; requestDuration=%s",
|
result := service.EvaluateConditions()
|
||||||
service.Name,
|
metric.PublishMetricsForService(service, result)
|
||||||
len(result.Errors),
|
serviceResults[service.Name] = append(serviceResults[service.Name], result)
|
||||||
result.Duration.Round(time.Millisecond),
|
if len(serviceResults[service.Name]) > 20 {
|
||||||
)
|
serviceResults[service.Name] = serviceResults[service.Name][1:]
|
||||||
log.Printf("[watchdog][Monitor] Waiting interval=%s before monitoring serviceName=%s", service.Interval, service.Name)
|
}
|
||||||
time.Sleep(service.Interval)
|
rwLock.Unlock()
|
||||||
}
|
log.Printf(
|
||||||
}(service)
|
"[watchdog][Monitor] Finished monitoring serviceName=%s; errors=%d; requestDuration=%s",
|
||||||
// To prevent multiple requests from running exactly at the same time
|
service.Name,
|
||||||
time.Sleep(100 * time.Millisecond)
|
len(result.Errors),
|
||||||
|
result.Duration.Round(time.Millisecond),
|
||||||
|
)
|
||||||
|
log.Printf("[watchdog][Monitor] Waiting interval=%s before monitoring serviceName=%s", service.Interval, service.Name)
|
||||||
|
time.Sleep(service.Interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user