Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add heartbeat metrics #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conf.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ metrics:
prometheus:
endpoint: /metrics
listen_addr: ":6178" # default listens on port 6178 on all IPs.
heartbeat:
url: http(s)://url-to-make-request-to
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
"gickup/gogs"
"gickup/local"
"gickup/logger"
prometheus "gickup/metrics/prometheus"
"gickup/metrics/heartbeat"
"gickup/metrics/prometheus"
"gickup/types"

"github.com/alecthomas/kong"
Expand Down Expand Up @@ -149,7 +150,7 @@ func RunBackup(conf *types.Conf) {
prometheus.CountReposDiscovered.WithLabelValues("gitlab").Set(float64(len(repos)))
Backup(repos, conf)

//Bitbucket
// Bitbucket
repos = bitbucket.Get(conf)
prometheus.CountReposDiscovered.WithLabelValues("bitbucket").Set(float64(len(repos)))
Backup(repos, conf)
Expand All @@ -160,6 +161,10 @@ func RunBackup(conf *types.Conf) {
prometheus.JobsComplete.Inc()
prometheus.JobDuration.Observe(duration.Seconds())

if conf.Metrics.Heartbeat.URL != "" {
heartbeat.Send(conf.Metrics.Heartbeat)
}

log.Info().
Str("duration", duration.String()).
Msg("Backup run complete")
Expand Down
16 changes: 16 additions & 0 deletions metrics/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package heartbeat

import (
"net/http"

"gickup/types"
"github.com/rs/zerolog/log"
)

func Send(conf types.HeartbeatConfig) {
log.Info().Str("url", conf.URL).Msg("sending heartbeat")
_, err := http.Get(conf.URL)
if err != nil {
log.Fatal().Str("monitoring", "heartbeat").Msg(err.Error())
}
}
5 changes: 5 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ type PrometheusConfig struct {
Endpoint string `yaml:"endpoint"`
}

type HeartbeatConfig struct {
URL string `yaml:"url"`
}

type Metrics struct {
Prometheus PrometheusConfig `yaml:"prometheus"`
Heartbeat HeartbeatConfig `yaml:"heartbeat"`
}

type Logging struct {
Expand Down