mirror: Add monitoring endpoint for mirroring operations (#3636)
* mirror: Add monitoring endpoint for mirroring operations The following are the added metrics: mc_mirror_failed_s3ops 3 mc_mirror_time_last_activity 9 mc_mirror_total_restarts 3 mc_mirror_total_s3ops 199920 Also, --watch automatically restarted if an error is detected Co-authored-by: Anis Elleuch <anis@min.io>
This commit is contained in:
co-authored by
Anis Elleuch
parent
1d9873c512
commit
28d8677578
+39
-1
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -35,6 +36,9 @@ import (
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
// mirror specific flags.
|
||||
@@ -111,6 +115,10 @@ var (
|
||||
Name: "attr",
|
||||
Usage: "add custom metadata for all objects",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "monitoring-port",
|
||||
Usage: "if specified, a new prometheus endpoint will be created to report mirroring activity",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -191,6 +199,21 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
var (
|
||||
s3mirrorTotalOps = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "mc_mirror_total_s3ops",
|
||||
Help: "The total number of failed mirror events",
|
||||
})
|
||||
s3mirrorFailedOps = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "mc_mirror_failed_s3ops",
|
||||
Help: "The total number of failed mirror events",
|
||||
})
|
||||
s3mirrorRestarts = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "mc_mirror_total_restarts",
|
||||
Help: "The number of mirroring restart",
|
||||
})
|
||||
)
|
||||
|
||||
const uaMirrorAppName = "mc-mirror"
|
||||
|
||||
type mirrorJob struct {
|
||||
@@ -417,7 +440,11 @@ func (mj *mirrorJob) monitorMirrorStatus() (errDuringMirror bool) {
|
||||
defer mj.status.Finish()
|
||||
|
||||
for sURLs := range mj.statusCh {
|
||||
// Update prometheus fields
|
||||
s3mirrorTotalOps.Inc()
|
||||
|
||||
if sURLs.Error != nil {
|
||||
s3mirrorFailedOps.Inc()
|
||||
switch {
|
||||
case sURLs.SourceContent != nil:
|
||||
if !isErrIgnored(sURLs.Error) {
|
||||
@@ -937,6 +964,16 @@ func mainMirror(cliCtx *cli.Context) error {
|
||||
// check 'mirror' cli arguments.
|
||||
srcURL, tgtURL := checkMirrorSyntax(ctx, cliCtx, encKeyDB)
|
||||
|
||||
if prometheusPort := cliCtx.String("monitoring-port"); prometheusPort != "" {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
go func() {
|
||||
if e := http.ListenAndServe(prometheusPort, nil); e != nil {
|
||||
fatalIf(probe.NewError(e), "Unable to setup monitoring endpoint.")
|
||||
}
|
||||
|
||||
}()
|
||||
}
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for {
|
||||
select {
|
||||
@@ -944,7 +981,8 @@ func mainMirror(cliCtx *cli.Context) error {
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
default:
|
||||
errorDetected := runMirror(ctx, cancelMirror, srcURL, tgtURL, cliCtx, encKeyDB)
|
||||
if cliCtx.Bool("multi-master") || cliCtx.Bool("active-active") {
|
||||
if cliCtx.Bool("watch") || cliCtx.Bool("multi-master") || cliCtx.Bool("active-active") {
|
||||
s3mirrorRestarts.Inc()
|
||||
time.Sleep(time.Duration(r.Float64() * float64(2*time.Second)))
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user