Skip to content

Commit 63dee21

Browse files
authored
add field bytes_added_packed in status file etc. (#519)
1 parent 25c2f06 commit 63dee21

File tree

8 files changed

+75
-57
lines changed

8 files changed

+75
-57
lines changed

monitor/prom/backup.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ const (
1313
)
1414

1515
type BackupMetrics struct {
16-
duration *prometheus.GaugeVec
17-
filesNew *prometheus.GaugeVec
18-
filesChanged *prometheus.GaugeVec
19-
filesUnmodified *prometheus.GaugeVec
20-
dirNew *prometheus.GaugeVec
21-
dirChanged *prometheus.GaugeVec
22-
dirUnmodified *prometheus.GaugeVec
23-
filesTotal *prometheus.GaugeVec
24-
bytesAdded *prometheus.GaugeVec
25-
bytesTotal *prometheus.GaugeVec
26-
status *prometheus.GaugeVec
27-
time *prometheus.GaugeVec
16+
duration *prometheus.GaugeVec
17+
filesNew *prometheus.GaugeVec
18+
filesChanged *prometheus.GaugeVec
19+
filesUnmodified *prometheus.GaugeVec
20+
dirNew *prometheus.GaugeVec
21+
dirChanged *prometheus.GaugeVec
22+
dirUnmodified *prometheus.GaugeVec
23+
filesTotal *prometheus.GaugeVec
24+
bytesAdded *prometheus.GaugeVec
25+
bytesAddedPacked *prometheus.GaugeVec
26+
bytesTotal *prometheus.GaugeVec
27+
status *prometheus.GaugeVec
28+
time *prometheus.GaugeVec
2829
}
2930

3031
func newBackupMetrics(labels []string) BackupMetrics {
@@ -83,6 +84,12 @@ func newBackupMetrics(labels []string) BackupMetrics {
8384
Name: "added_bytes",
8485
Help: "Total number of bytes added to the repository.",
8586
}, labels),
87+
bytesAddedPacked: prometheus.NewGaugeVec(prometheus.GaugeOpts{
88+
Namespace: namespace,
89+
Subsystem: backup,
90+
Name: "added_bytes_packed",
91+
Help: "Total number of bytes added to the repository after compression.",
92+
}, labels),
8693
bytesTotal: prometheus.NewGaugeVec(prometheus.GaugeOpts{
8794
Namespace: namespace,
8895
Subsystem: backup,

monitor/prom/metrics.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func NewMetrics(profile, group, version string, resticversion string, configLabe
5252
p.info.With(mergeLabels(cloneLabels(labels), map[string]string{goVersionLabel: runtime.Version(), versionLabel: version})).Set(1)
5353

5454
p.resticInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
55-
Name: "restic_build_info",
56-
Help: "restic build information.",
55+
Name: "restic_build_info",
56+
Help: "restic build information.",
5757
}, append(keys, versionLabel))
5858
// send the information about the build right away
5959
p.resticInfo.With(mergeLabels(cloneLabels(labels), map[string]string{versionLabel: resticversion})).Set(1)
@@ -72,6 +72,7 @@ func NewMetrics(profile, group, version string, resticversion string, configLabe
7272
p.backup.dirUnmodified,
7373
p.backup.filesTotal,
7474
p.backup.bytesAdded,
75+
p.backup.bytesAddedPacked,
7576
p.backup.bytesTotal,
7677
p.backup.status,
7778
p.backup.time,
@@ -92,6 +93,7 @@ func (p *Metrics) BackupResults(status Status, summary monitor.Summary) {
9293

9394
p.backup.filesTotal.With(p.labels).Set(float64(summary.FilesTotal))
9495
p.backup.bytesAdded.With(p.labels).Set(float64(summary.BytesAdded))
96+
p.backup.bytesAddedPacked.With(p.labels).Set(float64(summary.BytesAddedPacked))
9597
p.backup.bytesTotal.With(p.labels).Set(float64(summary.BytesTotal))
9698
p.backup.status.With(p.labels).Set(float64(status))
9799
p.backup.time.With(p.labels).Set(float64(time.Now().Unix()))

monitor/status/profile.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ type CommandStatus struct {
3030
// BackupStatus contains the last backup status
3131
type BackupStatus struct {
3232
CommandStatus
33-
FilesNew int `json:"files_new"`
34-
FilesChanged int `json:"files_changed"`
35-
FilesUnmodified int `json:"files_unmodified"`
36-
DirsNew int `json:"dirs_new"`
37-
DirsChanged int `json:"dirs_changed"`
38-
DirsUnmodified int `json:"dirs_unmodified"`
39-
FilesTotal int `json:"files_total"`
40-
BytesAdded uint64 `json:"bytes_added"`
41-
BytesTotal uint64 `json:"bytes_total"`
33+
FilesNew int `json:"files_new"`
34+
FilesChanged int `json:"files_changed"`
35+
FilesUnmodified int `json:"files_unmodified"`
36+
DirsNew int `json:"dirs_new"`
37+
DirsChanged int `json:"dirs_changed"`
38+
DirsUnmodified int `json:"dirs_unmodified"`
39+
FilesTotal int `json:"files_total"`
40+
BytesAdded uint64 `json:"bytes_added"`
41+
BytesAddedPacked uint64 `json:"bytes_added_packed"`
42+
BytesTotal uint64 `json:"bytes_total"`
4243
}
4344

4445
// BackupSuccess indicates the last backup was successful
@@ -50,15 +51,16 @@ func (p *Profile) BackupSuccess(summary monitor.Summary, stderr string) *Profile
5051
Duration: int64(math.Ceil(summary.Duration.Seconds())),
5152
Stderr: stderr,
5253
},
53-
FilesNew: summary.FilesNew,
54-
FilesChanged: summary.FilesChanged,
55-
FilesUnmodified: summary.FilesUnmodified,
56-
DirsNew: summary.DirsNew,
57-
DirsChanged: summary.DirsChanged,
58-
DirsUnmodified: summary.DirsUnmodified,
59-
FilesTotal: summary.FilesTotal,
60-
BytesAdded: summary.BytesAdded,
61-
BytesTotal: summary.BytesTotal,
54+
FilesNew: summary.FilesNew,
55+
FilesChanged: summary.FilesChanged,
56+
FilesUnmodified: summary.FilesUnmodified,
57+
DirsNew: summary.DirsNew,
58+
DirsChanged: summary.DirsChanged,
59+
DirsUnmodified: summary.DirsUnmodified,
60+
FilesTotal: summary.FilesTotal,
61+
BytesAdded: summary.BytesAdded,
62+
BytesAddedPacked: summary.BytesAddedPacked,
63+
BytesTotal: summary.BytesTotal,
6264
}
6365
return p
6466
}
@@ -73,15 +75,16 @@ func (p *Profile) BackupError(err error, summary monitor.Summary, stderr string)
7375
Duration: int64(math.Ceil(summary.Duration.Seconds())),
7476
Stderr: stderr,
7577
},
76-
FilesNew: 0,
77-
FilesChanged: 0,
78-
FilesUnmodified: 0,
79-
DirsNew: 0,
80-
DirsChanged: 0,
81-
DirsUnmodified: 0,
82-
FilesTotal: 0,
83-
BytesAdded: 0,
84-
BytesTotal: 0,
78+
FilesNew: 0,
79+
FilesChanged: 0,
80+
FilesUnmodified: 0,
81+
DirsNew: 0,
82+
DirsChanged: 0,
83+
DirsUnmodified: 0,
84+
FilesTotal: 0,
85+
BytesAdded: 0,
86+
BytesAddedPacked: 0,
87+
BytesTotal: 0,
8588
}
8689
return p
8790
}

monitor/summary.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import "time"
44

55
// Summary of the profile run
66
type Summary struct {
7-
Duration time.Duration
8-
FilesNew int
9-
FilesChanged int
10-
FilesUnmodified int
11-
DirsNew int
12-
DirsChanged int
13-
DirsUnmodified int
14-
FilesTotal int
15-
BytesAdded uint64
16-
BytesTotal uint64
17-
OutputAnalysis OutputAnalysis
7+
Duration time.Duration
8+
FilesNew int
9+
FilesChanged int
10+
FilesUnmodified int
11+
DirsNew int
12+
DirsChanged int
13+
DirsUnmodified int
14+
FilesTotal int
15+
BytesAdded uint64
16+
BytesAddedPacked uint64
17+
BytesTotal uint64
18+
OutputAnalysis OutputAnalysis
1819
}
1920

2021
// OutputAnalysis of the profile run

shell/json_summary.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ResticJsonSummary struct {
2121
DataBlobs int `json:"data_blobs"`
2222
TreeBlobs int `json:"tree_blobs"`
2323
DataAdded uint64 `json:"data_added"`
24+
DataAddedPacked uint64 `json:"data_added_packed"`
2425
TotalFilesProcessed int `json:"total_files_processed"`
2526
TotalBytesProcessed uint64 `json:"total_bytes_processed"`
2627
TotalDuration float64 `json:"total_duration"`
@@ -56,6 +57,7 @@ var ScanBackupJson ScanOutput = func(r io.Reader, summary *monitor.Summary, w io
5657
summary.DirsUnmodified = jsonSummary.DirsUnmodified
5758
summary.FilesTotal = jsonSummary.TotalFilesProcessed
5859
summary.BytesAdded = jsonSummary.DataAdded
60+
summary.BytesAddedPacked = jsonSummary.DataAddedPacked
5961
summary.BytesTotal = jsonSummary.TotalBytesProcessed
6062
}
6163
continue

shell/json_summary_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestScanJsonSummary(t *testing.T) {
1919
{"message_type":"status","percent_done":0.028711419769115988,"total_files":213,"files_done":13,"total_bytes":362948126,"bytes_done":10420756,"current_files":["/go/src/github.com/creativeprojects/resticprofile/build/restic","/go/src/github.com/creativeprojects/resticprofile/build/resticprofile"]}
2020
{"message_type":"status","percent_done":0.9763572825280271,"total_files":213,"files_done":163,"total_bytes":362948126,"bytes_done":354367046,"current_files":["/go/src/github.com/creativeprojects/resticprofile/resticprofile_darwin","/go/src/github.com/creativeprojects/resticprofile/resticprofile_linux"]}
2121
{"message_type":"status","seconds_elapsed":1,"percent_done":1,"total_files":213,"files_done":212,"total_bytes":362948126,"bytes_done":362948126,"current_files":["/go/src/github.com/creativeprojects/resticprofile/resticprofile_linux"]}
22-
{"message_type":"summary","files_new":213,"files_changed":11,"files_unmodified":12,"dirs_new":58,"dirs_changed":2,"dirs_unmodified":3,"data_blobs":402,"tree_blobs":59,"data_added":296530781,"total_files_processed":236,"total_bytes_processed":362948126,"total_duration":1.009156009,"snapshot_id":"6daa8ef6"}
22+
{"message_type":"summary","files_new":213,"files_changed":11,"files_unmodified":12,"dirs_new":58,"dirs_changed":2,"dirs_unmodified":3,"data_blobs":402,"tree_blobs":59,"data_added":296530781,"data_added_packed":74132695,"total_files_processed":236,"total_bytes_processed":362948126,"total_duration":1.009156009,"snapshot_id":"6daa8ef6"}
2323
`
2424

2525
if platform.IsWindows() {
@@ -64,6 +64,7 @@ func TestScanJsonSummary(t *testing.T) {
6464
assert.Equal(t, 2, summary.DirsChanged)
6565
assert.Equal(t, 3, summary.DirsUnmodified)
6666
assert.Equal(t, uint64(296530781), summary.BytesAdded)
67+
assert.Equal(t, uint64(74132695), summary.BytesAddedPacked)
6768
assert.Equal(t, uint64(362948126), summary.BytesTotal)
6869
assert.Equal(t, 236, summary.FilesTotal)
6970
}

shell/plain_summary.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var ScanBackupPlain ScanOutput = func(r io.Reader, summary *monitor.Summary, w i
1717
if runtime.GOOS == "windows" {
1818
eol = "\r\n"
1919
}
20-
rawBytes, unit, duration := 0.0, "", ""
20+
rawBytes, rawBytesStored, unit, unitStored, duration := 0.0, 0.0, "", "", ""
2121
scanner := bufio.NewScanner(r)
2222
for scanner.Scan() {
2323
_, err := w.Write([]byte(scanner.Text() + eol))
@@ -28,9 +28,10 @@ var ScanBackupPlain ScanOutput = func(r io.Reader, summary *monitor.Summary, w i
2828
_, _ = fmt.Sscanf(scanner.Text(), "Files: %d new, %d changed, %d unmodified", &summary.FilesNew, &summary.FilesChanged, &summary.FilesUnmodified)
2929
_, _ = fmt.Sscanf(scanner.Text(), "Dirs: %d new, %d changed, %d unmodified", &summary.DirsNew, &summary.DirsChanged, &summary.DirsUnmodified)
3030

31-
n, err := fmt.Sscanf(scanner.Text(), "Added to the repo: %f %3s", &rawBytes, &unit)
32-
if n == 2 && err == nil {
31+
n, err := fmt.Sscanf(scanner.Text(), "Added to the repository: %f %3s (%f %3s stored)", &rawBytes, &unit, &rawBytesStored, &unitStored)
32+
if n == 4 && err == nil {
3333
summary.BytesAdded = unformatBytes(rawBytes, unit)
34+
summary.BytesAddedPacked = unformatBytes(rawBytesStored, unitStored)
3435
}
3536

3637
n, err = fmt.Sscanf(scanner.Text(), "processed %d files, %f %3s in %s", &summary.FilesTotal, &rawBytes, &unit, &duration)

shell/plain_summary_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ created new cache in /Users/home/Library/Caches/restic
2020
2121
Files: 209 new, 2 changed, 12 unmodified
2222
Dirs: 58 new, 1 changed, 11 unmodified
23-
Added to the repo: 282.768 MiB
23+
Added to the repository: 282.768 MiB (70.691 MiB stored)
2424
2525
processed 223 files, 346.107 MiB in 0:00
2626
snapshot 07ab30a5 saved
@@ -61,6 +61,7 @@ snapshot 07ab30a5 saved
6161
assert.Equal(t, 1, summary.DirsChanged)
6262
assert.Equal(t, 11, summary.DirsUnmodified)
6363
assert.Equal(t, uint64(296503738), summary.BytesAdded)
64+
assert.Equal(t, uint64(74124886), summary.BytesAddedPacked)
6465
assert.Equal(t, uint64(362919494), summary.BytesTotal)
6566
assert.Equal(t, 223, summary.FilesTotal)
6667
}

0 commit comments

Comments
 (0)