Skip to content

Commit

Permalink
Expose metrics by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gebn committed Apr 30, 2022
1 parent e6d5695 commit e101aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func app(ctx context.Context) error {
flgBackupDir := flag.String("dir", "/var/lib/unifi/backup/autobackup", "Path of the autobackup directory.")
flgBucket := flag.String("bucket", "", "Name of the S3 bucket to upload to.")
flgPrefix := flag.String("prefix", "unifi/", "Prepended to the backup file name to form the object key.")
flgMetrics := flag.String("metrics", "", "A listen spec on which to expose Prometheus metrics. If empty, no metrics are exposed.")
flgMetrics := flag.String("metrics", ":9184", "A listen spec on which to expose Prometheus metrics.")
flgTimeout := flag.Duration("timeout", 5*time.Minute, "The amount of time to allow for put and delete S3 requests.")
flgVersion := flag.Bool("version", false, "Print program version and exit.")
flag.Parse()
Expand All @@ -137,23 +137,21 @@ func app(ctx context.Context) error {
close(done)
}()

if *flgMetrics != "" {
srv := buildServer(*flgMetrics)
wg := sync.WaitGroup{}
defer wg.Wait()
wg.Add(1)
go func() {
defer wg.Done()
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Printf("server did not close cleanly: %v", err)
}
}()
defer func() {
if err := srv.Shutdown(context.Background()); err != nil {
log.Printf("failed to close listener: %v", err)
}
}()
}
srv := buildServer(*flgMetrics)
wg := sync.WaitGroup{}
defer wg.Wait()
wg.Add(1)
go func() {
defer wg.Done()
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Printf("server did not close cleanly: %v", err)
}
}()
defer func() {
if err := srv.Shutdown(ctx); err != nil {
log.Printf("failed to close listener: %v", err)
}
}()

monitor, err := monitor.New(*flgBackupDir)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion unifibackup.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ User=unifi
Restart=on-failure

# --prefix to override the bucket prefix from "unifi/"
# --metrics :<port> to expose metrics in Prometheus format
# --metrics :<port> to override Prometheus metrics port
# --timeout <duration, e.g. 10s> to set max duration per S3 operation
ExecStart=/opt/unifibackup/unifibackup --bucket <changeme>

Expand Down

0 comments on commit e101aa2

Please sign in to comment.