Skip to content

Commit

Permalink
Correct metrics while another backup in progress. (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
S3RK authored and paunin committed Nov 3, 2017
1 parent d18f09a commit 2b39702
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions barman/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func collectMetrics() map[string]int64 {

diagnose := barmanDiagnose()
backups := diagnose.Servers.Pg_cluster.Backups
backups = FilterBackups(backups, func(b BarmanBackup) bool {
return b.Status == "DONE"
})

metrics["barman_check_is_ok"] = int64(barmanCheck())
metrics["barman_backups_amount"] = int64(len(backups))
Expand Down Expand Up @@ -56,6 +59,16 @@ func collectMetrics() map[string]int64 {
return metrics
}

func FilterBackups(backups map[string]BarmanBackup, filter func(BarmanBackup) bool) map[string]BarmanBackup {
result := make(map[string]BarmanBackup, len(backups))
for key, backup := range backups {
if filter(backup) {
result[key] = backup
}
}
return result
}

var execCommand = exec.Command
func barmanCheck() int {
checkCmd := execCommand("barman", "check")
Expand Down Expand Up @@ -83,6 +96,7 @@ type BarmanBackup struct {
End_time CustomTime
Copy_stats map[string]float64
Size int64
Status string
}

func barmanDiagnose() BarmanDiagnose {
Expand Down
28 changes: 28 additions & 0 deletions barman/metrics/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@
"timeline": 1,
"version": 90508,
"xlog_segment_size": 16777216
},
"20171102T071700": {
"backup_id": "20171102T071700",
"backup_label": null,
"begin_offset": null,
"begin_time": "Thu Nov 2 07:17:00 2017",
"begin_wal": null,
"begin_xlog": "273/7A8C3080",
"config_file": "/var/lib/postgresql/data/postgresql.conf",
"copy_stats": null,
"deduplicated_size": null,
"end_offset": null,
"end_time": null,
"end_wal": null,
"end_xlog": null,
"error": null,
"hba_file": "/var/lib/postgresql/data/pg_hba.conf",
"ident_file": "/var/lib/postgresql/data/pg_ident.conf",
"included_files": null,
"mode": "postgres",
"pgdata": "/var/lib/postgresql/data",
"server_name": "pg_cluster",
"size": null,
"status": "STARTED",
"tablespaces": null,
"timeline": null,
"version": 90509,
"xlog_segment_size": 16777216
}
},
"config": {
Expand Down

0 comments on commit 2b39702

Please sign in to comment.