Skip to content

Commit

Permalink
add backup stats
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinated92 committed Jun 5, 2024
1 parent c20a52b commit 709b964
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 23 deletions.
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type Cluster struct {
tunnel *ssh.Client `json:"-"`
QueryRules map[uint32]config.QueryRule `json:"-"`
Backups []v3.Backup `json:"-"`
BackupStat v3.BackupStat `json:"backupStat"`
SLAHistory []state.Sla `json:"slaHistory"`
APIUsers map[string]APIUser `json:"apiUsers"`
Schedule map[string]cron.Entry `json:"-"`
Expand Down
53 changes: 53 additions & 0 deletions cluster/cluster_bck.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,60 @@ func (cluster *Cluster) ResticFetchRepo() error {
}
}
cluster.Backups = filterRepo

cluster.ResticFetchRepoStat()
}

return nil
}

func (cluster *Cluster) ResticFetchRepoStat() error {

// defer func() { cluster.canResticFetchRepo = true }()
// if cluster.Conf.BackupRestic && cluster.canResticFetchRepo {
cluster.canResticFetchRepo = false
// var stdout, stderr []byte
var stdoutBuf, stderrBuf bytes.Buffer
var errStdout, errStderr error
resticcmd := exec.Command(cluster.Conf.BackupResticBinaryPath, "stats", "--mode", "raw-data", "--json")
stdoutIn, _ := resticcmd.StdoutPipe()
stderrIn, _ := resticcmd.StderrPipe()
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
stderr := io.MultiWriter(os.Stderr, &stderrBuf)

resticcmd.Env = cluster.ResticGetEnv()
if err := resticcmd.Start(); err != nil {
cluster.SetState("WARN0094", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["WARN0094"], resticcmd.Path, err, ""), ErrFrom: "BACKUP"})
return err
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
_, errStdout = io.Copy(stdout, stdoutIn)
wg.Done()
}()

_, errStderr = io.Copy(stderr, stderrIn)
wg.Wait()

err := resticcmd.Wait()
if err != nil {
cluster.StateMachine.AddState("WARN0093", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["WARN0093"], err, string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())), ErrFrom: "CHECK"})
cluster.ResticInitRepo()
return err
}
if errStdout != nil || errStderr != nil {
return errors.New("failed to capture stdout or stderr\n")
}

var repostat v3.BackupStat
err = json.Unmarshal(stdoutBuf.Bytes(), &repostat)
if err != nil {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlInfo, "Error unmarshal backups %s", err)
return err
}
cluster.BackupStat = repostat
// }

return nil
}
6 changes: 6 additions & 0 deletions repmanv3/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions share/dashboard/app/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ app.controller('DashboardController', function (
{ id: '6', name: 'SAT' },
];

$scope.humanFileSize = function(size) {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return +((size / Math.pow(1024, i)).toFixed(2)) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}

var getClusterUrl = function () {
return AppService.getClusterUrl($scope.selectedClusterName);
};
Expand Down
71 changes: 48 additions & 23 deletions share/dashboard/static/tab-cluster-backups.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@

<md-content class="md-padding">
<md-card>
<md-card-content>
<p class="sectionheader">Backups</p>
</md-card-content>
<table ng-if="backups" class="table">
<tr>
<th width="8%">Id</th>
<th width="20%">Time</th>
<th>Path</th>
<th width="20%">Hostname</th>
<th width="20%">Tags</th>
</tr>
<tr ng-repeat="bck in backups" ng-class="">
<td>{{bck.short_id}}</td>
<td>{{bck.time}}</td>
<td>{{bck.paths[0]}}</td>
<td>{{bck.hostname}}</td>
<td>{{bck.tags.join(', ')}}</td>
</tr>
</table>
</md-card>
</md-content>
<md-card>
<md-card-content>
<p class="sectionheader">Backups</p>
</md-card-content>

<md-card>
<table ng-if="backups" class="table">
<thead>
<tr>
<th>Total Size</th>
<th width="30%">Total File Count</th>
<th width="30%">Total Blob Count</th>
</tr>
</thead>
<tbody>
<tr ng-class="">
<td>{{humanFileSize(selectedCluster.backupStat.total_size)}}</td>
<td>{{selectedCluster.backupStat.total_file_count}}</td>
<td>{{selectedCluster.backupStat.total_blob_count}}</td>
</tr>
</tbody>
</table>
</md-card>

<md-card>
<table ng-if="backups" class="table">
<thead>
<tr>
<th width="8%">Id</th>
<th width="20%">Time</th>
<th>Path</th>
<th width="20%">Hostname</th>
<th width="20%">Tags</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="bck in backups" ng-class="">
<td>{{bck.short_id}}</td>
<td>{{bck.time}}</td>
<td>{{bck.paths[0]}}</td>
<td>{{bck.hostname}}</td>
<td>{{bck.tags.join(', ')}}</td>
</tr>
</tbody>
</table>
</md-card>
</md-card>
</md-content>

0 comments on commit 709b964

Please sign in to comment.