@@ -16,11 +16,53 @@ import (
16
16
17
17
"github.com/go-sql-driver/mysql"
18
18
"github.com/pkg/errors"
19
+ "github.com/prometheus/client_golang/prometheus"
19
20
20
21
"github.com/percona/percona-xtradb-cluster-operator/cmd/pitr/pxc"
21
22
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/backup/storage"
22
23
)
23
24
25
+ var (
26
+ pxcBinlogCollectorBackupSuccess = prometheus .NewCounter (
27
+ prometheus.CounterOpts {
28
+ Name : "pxc_binlog_collector_success_total" ,
29
+ Help : "Total number of successful binlog backups" ,
30
+ },
31
+ )
32
+ pxcBinlogCollectorBackupFailure = prometheus .NewCounter (
33
+ prometheus.CounterOpts {
34
+ Name : "pxc_binlog_collector_failure_total" ,
35
+ Help : "Total number of failed binlog backups" ,
36
+ },
37
+ )
38
+ pxcBinlogCollectorLastProcessingTime = prometheus .NewGauge (
39
+ prometheus.GaugeOpts {
40
+ Name : "pxc_binlog_collector_last_processing_timestamp" ,
41
+ Help : "Timestamp of the last successful binlog processing" ,
42
+ },
43
+ )
44
+ pxcBinlogCollectorLastUploadTime = prometheus .NewGauge (
45
+ prometheus.GaugeOpts {
46
+ Name : "pxc_binlog_collector_last_upload_timestamp" ,
47
+ Help : "Timestamp of the last successful binlog upload" ,
48
+ },
49
+ )
50
+ pxcBinlogCollectorGapDetected = prometheus .NewCounter (
51
+ prometheus.CounterOpts {
52
+ Name : "pxc_binlog_collector_gap_detected_total" ,
53
+ Help : "Total number of times the gap was detected in binlog" ,
54
+ },
55
+ )
56
+ )
57
+
58
+ func init () {
59
+ prometheus .MustRegister (pxcBinlogCollectorBackupSuccess )
60
+ prometheus .MustRegister (pxcBinlogCollectorBackupFailure )
61
+ prometheus .MustRegister (pxcBinlogCollectorLastProcessingTime )
62
+ prometheus .MustRegister (pxcBinlogCollectorLastUploadTime )
63
+ prometheus .MustRegister (pxcBinlogCollectorGapDetected )
64
+ }
65
+
24
66
type Collector struct {
25
67
db * pxc.PXC
26
68
storage storage.Storage
@@ -103,6 +145,7 @@ func New(ctx context.Context, c Config) (*Collector, error) {
103
145
func (c * Collector ) Run (ctx context.Context ) error {
104
146
err := c .newDB (ctx )
105
147
if err != nil {
148
+ pxcBinlogCollectorBackupFailure .Inc ()
106
149
return errors .Wrap (err , "new db connection" )
107
150
}
108
151
defer c .close ()
@@ -113,9 +156,11 @@ func (c *Collector) Run(ctx context.Context) error {
113
156
114
157
err = c .CollectBinLogs (ctx )
115
158
if err != nil {
159
+ pxcBinlogCollectorBackupFailure .Inc ()
116
160
return errors .Wrap (err , "collect binlog files" )
117
161
}
118
162
163
+ pxcBinlogCollectorBackupSuccess .Inc ()
119
164
return nil
120
165
}
121
166
@@ -369,6 +414,7 @@ func (c *Collector) CollectBinLogs(ctx context.Context) error {
369
414
if lastUploadedBinlogName == "" {
370
415
log .Println ("ERROR: Couldn't find the binlog that contains GTID set:" , c .lastUploadedSet .Raw ())
371
416
log .Println ("ERROR: Gap detected in the binary logs. Binary logs will be uploaded anyway, but full backup needed for consistent recovery." )
417
+ pxcBinlogCollectorGapDetected .Inc ()
372
418
if err := createGapFile (c .lastUploadedSet ); err != nil {
373
419
return errors .Wrap (err , "create gap file" )
374
420
}
@@ -382,6 +428,7 @@ func (c *Collector) CollectBinLogs(ctx context.Context) error {
382
428
383
429
if len (list ) == 0 {
384
430
log .Println ("No binlogs to upload" )
431
+ pxcBinlogCollectorLastProcessingTime .SetToCurrentTime ()
385
432
return nil
386
433
}
387
434
@@ -402,6 +449,8 @@ func (c *Collector) CollectBinLogs(ctx context.Context) error {
402
449
return errors .Wrap (err , "manage binlog" )
403
450
}
404
451
452
+ pxcBinlogCollectorLastUploadTime .SetToCurrentTime ()
453
+
405
454
lastTs , err := c .db .GetBinLogLastTimestamp (ctx , binlog .Name )
406
455
if err != nil {
407
456
return errors .Wrap (err , "get last timestamp" )
@@ -411,6 +460,8 @@ func (c *Collector) CollectBinLogs(ctx context.Context) error {
411
460
return errors .Wrap (err , "update timeline file" )
412
461
}
413
462
}
463
+
464
+ pxcBinlogCollectorLastProcessingTime .SetToCurrentTime ()
414
465
return nil
415
466
}
416
467
0 commit comments