1
1
mirror of https://github.com/cooperspencer/gickup synced 2024-09-16 21:31:40 +02:00

feat: Support multiple heartbeat URLs (#109)

* feat: add heartbeat metrics

* feat: Support multiple heartbeat URLs

#100 introduced heartbeat support but only supported one URL. This PR was closed, however I've re-introduced this feature and added support for multiple heartbeat URLs as discussed in the #100 discussion.

This also resolves #108 which is a feature request for the heartbeat feature.

* fix: When sending the heartbeat fails, log an error but don't crash the program

This prevents problems with external services from causing the program to quit.

Co-authored-by: Matthew Toohey <contact@mtoohey.com>
Co-authored-by: Jordan Crawford <>
This commit is contained in:
Jordan Crawford 2022-05-17 23:12:07 +12:00 committed by GitHub
parent 96419e641e
commit 510e234e52
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -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")

View File

@ -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())
}
}
}

View File

@ -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.