Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60cfac948b | ||
|
|
958446050f | ||
|
|
88e94642d9 | ||
|
|
bc83a51907 | ||
|
|
08b8932331 | ||
|
|
9072d97bb8 | ||
|
|
cdd8a69669 | ||
|
|
3c14a02770 | ||
|
|
328ea83c25 | ||
|
|
ce986e8d1d | ||
|
|
31a4b484bf | ||
|
|
444d060736 |
+2
-2
@@ -4,7 +4,7 @@ name: test
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: test
|
- name: test
|
||||||
image: golang:1.15
|
image: golang:1.17
|
||||||
environment:
|
environment:
|
||||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||||
commands:
|
commands:
|
||||||
@@ -30,7 +30,7 @@ trigger:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build all binaries
|
- name: build all binaries
|
||||||
image: golang:1.15
|
image: golang:1.17
|
||||||
environment:
|
environment:
|
||||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||||
commands:
|
commands:
|
||||||
|
|||||||
+14
-25
@@ -1,32 +1,23 @@
|
|||||||
---
|
---
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- asciicheck
|
- errname
|
||||||
- bodyclose
|
- errorlint
|
||||||
- dogsled
|
|
||||||
- dupl
|
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- gochecknoinits
|
|
||||||
- gocognit
|
|
||||||
- gocritic
|
|
||||||
- gocyclo
|
|
||||||
- goerr113
|
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goimports
|
- goimports
|
||||||
- gomnd
|
- gomnd
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
# - gosec
|
|
||||||
# - ifshort
|
|
||||||
- interfacer
|
|
||||||
- maligned
|
|
||||||
- misspell
|
- misspell
|
||||||
- nakedret
|
- promlinter
|
||||||
- nestif
|
- tagliatelle
|
||||||
- nlreturn
|
- tenv
|
||||||
- noctx
|
- testpackage
|
||||||
- unparam
|
- thelper
|
||||||
|
- tparallel
|
||||||
|
- unconvert
|
||||||
|
- wrapcheck
|
||||||
- wsl
|
- wsl
|
||||||
# - errorlint
|
|
||||||
disable:
|
disable:
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
|
|
||||||
@@ -34,15 +25,13 @@ linters-settings:
|
|||||||
gosec:
|
gosec:
|
||||||
excludes:
|
excludes:
|
||||||
- G204
|
- G204
|
||||||
# gomnd:
|
tagliatelle:
|
||||||
# settings:
|
case:
|
||||||
# mnd:
|
rules:
|
||||||
# ignored-functions: math.*
|
yaml: snake
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- errcheck
|
|
||||||
- gosec
|
- gosec
|
||||||
- maligned
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v3.4.0
|
rev: v4.4.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-added-large-files
|
- id: check-added-large-files
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
@@ -10,13 +10,11 @@ repos:
|
|||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- repo: git://github.com/dnephin/pre-commit-golang
|
- repo: https://github.com/golangci/golangci-lint
|
||||||
rev: v0.4.0
|
rev: v1.50.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: go-fmt
|
|
||||||
- id: go-imports
|
|
||||||
- id: golangci-lint
|
- id: golangci-lint
|
||||||
- repo: https://github.com/hadolint/hadolint
|
- repo: https://github.com/hadolint/hadolint
|
||||||
rev: v2.4.0
|
rev: v2.12.1-beta
|
||||||
hooks:
|
hooks:
|
||||||
- id: hadolint
|
- id: hadolint
|
||||||
|
|||||||
+2
-6
@@ -1,15 +1,11 @@
|
|||||||
ARG REPO=library
|
ARG REPO=library
|
||||||
FROM multiarch/qemu-user-static:4.2.0-2 as qemu-user-static
|
FROM ${REPO}/alpine:3.12
|
||||||
FROM ${REPO}/alpine:3.10
|
|
||||||
|
|
||||||
# Copying all qemu files because amd64 doesn't exist and cannot condional copy
|
|
||||||
COPY --from=qemu-user-static /usr/bin/qemu-* /usr/bin/
|
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
|
|
||||||
# Add common checking tools
|
# Add common checking tools
|
||||||
RUN apk --no-cache add bash=~5.0 curl=~7.66 jq=~1.6
|
RUN apk --no-cache add bash=~5.0 curl=~7.79 jq=~1.6
|
||||||
|
|
||||||
# Add minitor user for running as non-root
|
# Add minitor user for running as non-root
|
||||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
ARG REPO=library
|
ARG REPO=library
|
||||||
FROM golang:1.12-alpine AS builder
|
FROM golang:1.17 AS builder
|
||||||
|
|
||||||
RUN apk add --no-cache git=~2
|
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -16,7 +14,7 @@ ARG VERSION=dev
|
|||||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
||||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
||||||
|
|
||||||
FROM ${REPO}/alpine:3.10
|
FROM ${REPO}/alpine:3.12
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
|
|
||||||
@@ -24,7 +22,7 @@ WORKDIR /app/
|
|||||||
COPY --from=builder /app/minitor .
|
COPY --from=builder /app/minitor .
|
||||||
|
|
||||||
# Add common checking tools
|
# Add common checking tools
|
||||||
RUN apk --no-cache add bash=~5.0 curl=~7.66 jq=~1.6
|
RUN apk --no-cache add bash=~5.0 curl=~7.79 jq=~1.6
|
||||||
|
|
||||||
# Add minitor user for running as non-root
|
# Add minitor user for running as non-root
|
||||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ func sendAlerts(config *Config, monitor *Monitor, alertNotice *AlertNotice) erro
|
|||||||
"Received alert, but no alert mechanisms exist. MonitorName=%s IsUp=%t",
|
"Received alert, but no alert mechanisms exist. MonitorName=%s IsUp=%t",
|
||||||
alertNotice.MonitorName, alertNotice.IsUp,
|
alertNotice.MonitorName, alertNotice.IsUp,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, alertName := range alertNames {
|
for _, alertName := range alertNames {
|
||||||
@@ -66,18 +68,22 @@ func sendAlerts(config *Config, monitor *Monitor, alertNotice *AlertNotice) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkMonitors(config *Config) error {
|
func checkMonitors(config *Config) error {
|
||||||
|
// TODO: Run this in goroutines and capture exceptions
|
||||||
for _, monitor := range config.Monitors {
|
for _, monitor := range config.Monitors {
|
||||||
if monitor.ShouldCheck() {
|
if monitor.ShouldCheck() {
|
||||||
success, alertNotice := monitor.Check()
|
success, alertNotice := monitor.Check()
|
||||||
|
|
||||||
hasAlert := alertNotice != nil
|
hasAlert := alertNotice != nil
|
||||||
|
|
||||||
// Track status metrics
|
// Track status metrics
|
||||||
Metrics.SetMonitorStatus(monitor.Name, monitor.IsUp())
|
Metrics.SetMonitorStatus(monitor.Name, monitor.IsUp())
|
||||||
Metrics.CountCheck(monitor.Name, success, monitor.LastCheckMilliseconds(), hasAlert)
|
Metrics.CountCheck(monitor.Name, success, monitor.LastCheckSeconds(), hasAlert)
|
||||||
|
|
||||||
if alertNotice != nil {
|
if alertNotice != nil {
|
||||||
return sendAlerts(config, monitor, alertNotice)
|
err := sendAlerts(config, monitor, alertNotice)
|
||||||
|
// If there was an error in sending an alert, exit early and bubble it up
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +98,7 @@ func main() {
|
|||||||
flag.BoolVar(&slog.DebugLevel, "debug", false, "Enables debug logs (default: false)")
|
flag.BoolVar(&slog.DebugLevel, "debug", false, "Enables debug logs (default: false)")
|
||||||
flag.BoolVar(&ExportMetrics, "metrics", false, "Enables prometheus metrics exporting (default: false)")
|
flag.BoolVar(&ExportMetrics, "metrics", false, "Enables prometheus metrics exporting (default: false)")
|
||||||
flag.BoolVar(&PyCompat, "py-compat", false, "Enables support for legacy Python Minitor config. Will eventually be removed. (default: false)")
|
flag.BoolVar(&PyCompat, "py-compat", false, "Enables support for legacy Python Minitor config. Will eventually be removed. (default: false)")
|
||||||
flag.IntVar(&MetricsPort, "metrics-port", 8080, "The port that Prometheus metrics should be exported on, if enabled. (default: 8080)")
|
flag.IntVar(&MetricsPort, "metrics-port", MetricsPort, "The port that Prometheus metrics should be exported on, if enabled. (default: 8080)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Print version if flag is provided
|
// Print version if flag is provided
|
||||||
@@ -116,9 +122,7 @@ func main() {
|
|||||||
// Start main loop
|
// Start main loop
|
||||||
for {
|
for {
|
||||||
err = checkMonitors(&config)
|
err = checkMonitors(&config)
|
||||||
if err != nil {
|
slog.OnErrPanicf(err, "Error checking monitors")
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(config.CheckInterval.Value())
|
time.Sleep(config.CheckInterval.Value())
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -16,7 +16,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Success",
|
Name: "Success",
|
||||||
Command: CommandOrShell{Command: []string{"true"}},
|
Command: CommandOrShell{Command: []string{"true"}},
|
||||||
},
|
},
|
||||||
@@ -28,7 +28,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Failure",
|
Name: "Failure",
|
||||||
Command: CommandOrShell{Command: []string{"false"}},
|
Command: CommandOrShell{Command: []string{"false"}},
|
||||||
AlertAfter: 1,
|
AlertAfter: 1,
|
||||||
@@ -41,7 +41,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Success",
|
Name: "Success",
|
||||||
Command: CommandOrShell{Command: []string{"ls"}},
|
Command: CommandOrShell{Command: []string{"ls"}},
|
||||||
alertCount: 1,
|
alertCount: 1,
|
||||||
@@ -54,7 +54,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Failure",
|
Name: "Failure",
|
||||||
Command: CommandOrShell{Command: []string{"false"}},
|
Command: CommandOrShell{Command: []string{"false"}},
|
||||||
AlertDown: []string{"unknown"},
|
AlertDown: []string{"unknown"},
|
||||||
@@ -68,7 +68,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Success",
|
Name: "Success",
|
||||||
Command: CommandOrShell{Command: []string{"true"}},
|
Command: CommandOrShell{Command: []string{"true"}},
|
||||||
AlertUp: []string{"unknown"},
|
AlertUp: []string{"unknown"},
|
||||||
@@ -82,7 +82,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Failure",
|
Name: "Failure",
|
||||||
Command: CommandOrShell{Command: []string{"false"}},
|
Command: CommandOrShell{Command: []string{"false"}},
|
||||||
AlertDown: []string{"good"},
|
AlertDown: []string{"good"},
|
||||||
@@ -90,7 +90,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Alerts: map[string]*Alert{
|
Alerts: map[string]*Alert{
|
||||||
"good": &Alert{
|
"good": {
|
||||||
Command: CommandOrShell{Command: []string{"true"}},
|
Command: CommandOrShell{Command: []string{"true"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -101,7 +101,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
config: Config{
|
config: Config{
|
||||||
Monitors: []*Monitor{
|
Monitors: []*Monitor{
|
||||||
&Monitor{
|
{
|
||||||
Name: "Failure",
|
Name: "Failure",
|
||||||
Command: CommandOrShell{Command: []string{"false"}},
|
Command: CommandOrShell{Command: []string{"false"}},
|
||||||
AlertDown: []string{"bad"},
|
AlertDown: []string{"bad"},
|
||||||
@@ -109,7 +109,7 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Alerts: map[string]*Alert{
|
Alerts: map[string]*Alert{
|
||||||
"bad": &Alert{
|
"bad": {
|
||||||
Name: "bad",
|
Name: "bad",
|
||||||
Command: CommandOrShell{Command: []string{"false"}},
|
Command: CommandOrShell{Command: []string{"false"}},
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-4
@@ -43,14 +43,14 @@ func NewMetrics() *MinitorMetrics {
|
|||||||
),
|
),
|
||||||
checkTime: prometheus.NewGaugeVec(
|
checkTime: prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "minitor_check_milliseconds",
|
Name: "minitor_check_seconds",
|
||||||
Help: "Time in miliseconds that a check ran for",
|
Help: "Time in miliseconds that a check ran for",
|
||||||
},
|
},
|
||||||
[]string{"monitor", "status"},
|
[]string{"monitor", "status"},
|
||||||
),
|
),
|
||||||
monitorStatus: prometheus.NewGaugeVec(
|
monitorStatus: prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "minitor_monitor_up_count",
|
Name: "minitor_monitor_up",
|
||||||
Help: "Status of currently responsive monitors",
|
Help: "Status of currently responsive monitors",
|
||||||
},
|
},
|
||||||
[]string{"monitor"},
|
[]string{"monitor"},
|
||||||
@@ -77,7 +77,7 @@ func (metrics *MinitorMetrics) SetMonitorStatus(monitor string, isUp bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountCheck counts the result of a particular Monitor check
|
// CountCheck counts the result of a particular Monitor check
|
||||||
func (metrics *MinitorMetrics) CountCheck(monitor string, isSuccess bool, ms int64, isAlert bool) {
|
func (metrics *MinitorMetrics) CountCheck(monitor string, isSuccess bool, secs float64, isAlert bool) {
|
||||||
status := "failure"
|
status := "failure"
|
||||||
if isSuccess {
|
if isSuccess {
|
||||||
status = "success"
|
status = "success"
|
||||||
@@ -94,7 +94,7 @@ func (metrics *MinitorMetrics) CountCheck(monitor string, isSuccess bool, ms int
|
|||||||
|
|
||||||
metrics.checkTime.With(
|
metrics.checkTime.With(
|
||||||
prometheus.Labels{"monitor": monitor, "status": status},
|
prometheus.Labels{"monitor": monitor, "status": status},
|
||||||
).Set(float64(ms))
|
).Set(secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountAlert counts an alert
|
// CountAlert counts an alert
|
||||||
|
|||||||
+3
-3
@@ -91,9 +91,9 @@ func (monitor Monitor) IsUp() bool {
|
|||||||
return monitor.alertCount == 0
|
return monitor.alertCount == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastCheckMilliseconds gives number of miliseconds the last check ran for
|
// LastCheckSeconds gives number of seconds the last check ran for
|
||||||
func (monitor Monitor) LastCheckMilliseconds() int64 {
|
func (monitor Monitor) LastCheckSeconds() float64 {
|
||||||
return monitor.lastCheckDuration.Milliseconds()
|
return monitor.lastCheckDuration.Seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (monitor *Monitor) success() (notice *AlertNotice) {
|
func (monitor *Monitor) success() (notice *AlertNotice) {
|
||||||
|
|||||||
Reference in New Issue
Block a user