Skip to content

Commit

Permalink
Show counters for total data transferred (fixes syncthing#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed May 24, 2014
1 parent 5454ca1 commit c2f75d3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions auto/gui.files.go

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions gui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
id;

prevDate = now;
$scope.inbps = 0;
$scope.outbps = 0;

for (id in data) {
if (!data.hasOwnProperty(id)) {
continue;
Expand All @@ -100,8 +97,6 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
data[id].inbps = 0;
data[id].outbps = 0;
}
$scope.inbps += data[id].inbps;
$scope.outbps += data[id].outbps;
}
$scope.connections = data;
});
Expand Down
8 changes: 4 additions & 4 deletions gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ <h3 class="panel-title">
</tr>
<tr>
<th><span class="glyphicon glyphicon-cloud-download"></span>&emsp;Download Rate</th>
<td class="text-right">{{inbps | metric}}bps</td>
<td class="text-right">{{connections['total'].inbps | metric}}bps ({{connections['total'].InBytesTotal | binary}}B)</td>
</tr>
<tr>
<th><span class="glyphicon glyphicon-cloud-upload"></span>&emsp;Upload Rate</th>
<td class="text-right">{{outbps | metric}}bps </td>
<td class="text-right">{{connections['total'].outbps | metric}}bps ({{connections['total'].OutBytesTotal | binary}}B)</td>
</tr>
<tr ng-if="system.extAnnounceOK != undefined">
<th><span class="glyphicon glyphicon-bullhorn"></span>&emsp;Announce Server</th>
Expand Down Expand Up @@ -262,11 +262,11 @@ <h3 class="panel-title">
</tr>
<tr>
<th><span class="glyphicon glyphicon-cloud-download"></span>&emsp;Download Rate</th>
<td class="text-right">{{connections[nodeCfg.NodeID].inbps | metric}}bps</td>
<td class="text-right">{{connections[nodeCfg.NodeID].inbps | metric}}bps ({{connections[nodeCfg.NodeID].InBytesTotal | binary}}B)</td>
</tr>
<tr>
<th><span class="glyphicon glyphicon-cloud-upload"></span>&emsp;Upload Rate</th>
<td class="text-right">{{connections[nodeCfg.NodeID].outbps | metric}}bps </td>
<td class="text-right">{{connections[nodeCfg.NodeID].outbps | metric}}bps ({{connections[nodeCfg.NodeID].OutBytesTotal | binary}}B)</td>
</tr>
<tr>
<th><span class="glyphicon glyphicon-tag"></span>&emsp;Version</th>
Expand Down
9 changes: 9 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
m.rmut.RUnlock()
m.pmut.RUnlock()

in, out := protocol.TotalInOut()
res["total"] = ConnectionInfo{
Statistics: protocol.Statistics{
At: time.Now(),
InBytesTotal: int(in),
OutBytesTotal: int(out),
},
}

return res
}

Expand Down
11 changes: 11 additions & 0 deletions protocol/counting.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ type countingReader struct {
tot uint64
}

var (
totalIncoming uint64
totalOutgoing uint64
)

func (c *countingReader) Read(bs []byte) (int, error) {
n, err := c.Reader.Read(bs)
atomic.AddUint64(&c.tot, uint64(n))
atomic.AddUint64(&totalIncoming, uint64(n))
return n, err
}

Expand All @@ -28,9 +34,14 @@ type countingWriter struct {
func (c *countingWriter) Write(bs []byte) (int, error) {
n, err := c.Writer.Write(bs)
atomic.AddUint64(&c.tot, uint64(n))
atomic.AddUint64(&totalOutgoing, uint64(n))
return n, err
}

func (c *countingWriter) Tot() uint64 {
return atomic.LoadUint64(&c.tot)
}

func TotalInOut() (uint64, uint64) {
return atomic.LoadUint64(&totalIncoming), atomic.LoadUint64(&totalOutgoing)
}

0 comments on commit c2f75d3

Please sign in to comment.