diff --git a/conf.example.yml b/conf.example.yml index 5c4e37d..1466bd1 100644 --- a/conf.example.yml +++ b/conf.example.yml @@ -150,6 +150,10 @@ log: # optional maxage: 7 # keep logs for 7 days metrics: - prometheus: + prometheus: # optional endpoint: /metrics listen_addr: ":6178" # default listens on port 6178 on all IPs. + heartbeat: # optional - upon successful backup, makes a GET http request to one or more URLs. This is useful for use with monitoring services such as healthchecks.io or deadmanssnitch.com + urls: + - http(s)://url-to-make-request-to + - http(s)://another-url-to-make-request-to diff --git a/main.go b/main.go index ac1c6ba..59e8e0d 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "github.com/cooperspencer/gickup/gogs" "github.com/cooperspencer/gickup/local" "github.com/cooperspencer/gickup/logger" + "github.com/cooperspencer/gickup/metrics/heartbeat" "github.com/cooperspencer/gickup/metrics/prometheus" "github.com/cooperspencer/gickup/types" "github.com/robfig/cron/v3" @@ -183,6 +184,10 @@ func runBackup(conf *types.Conf) { prometheus.JobsComplete.Inc() prometheus.JobDuration.Observe(duration.Seconds()) + if len(conf.Metrics.Heartbeat.URLs) > 0 { + heartbeat.Send(conf.Metrics.Heartbeat) + } + log.Info(). Str("duration", duration.String()). Msg("Backup run complete") diff --git a/metrics/heartbeat/heartbeat.go b/metrics/heartbeat/heartbeat.go new file mode 100644 index 0000000..fbb83f8 --- /dev/null +++ b/metrics/heartbeat/heartbeat.go @@ -0,0 +1,18 @@ +package heartbeat + +import ( + "net/http" + + "github.com/cooperspencer/gickup/types" + "github.com/rs/zerolog/log" +) + +func Send(conf types.HeartbeatConfig) { + for _, u := range conf.URLs { + log.Info().Str("url", u).Msg("sending heartbeat") + _, err := http.Get(u) + if err != nil { + log.Error().Str("monitoring", "heartbeat").Msg(err.Error()) + } + } +} diff --git a/types/types.go b/types/types.go index 8402e96..5db30a0 100644 --- a/types/types.go +++ b/types/types.go @@ -58,9 +58,14 @@ type PrometheusConfig struct { Endpoint string `yaml:"endpoint"` } +type HeartbeatConfig struct { + URLs []string `yaml:"urls"` +} + // Metrics TODO. type Metrics struct { Prometheus PrometheusConfig `yaml:"prometheus"` + Heartbeat HeartbeatConfig `yaml:"heartbeat"` } // Logging TODO.