Add uptime in webgui (fixes #1501)

This commit is contained in:
ralder
2015-04-03 21:00:13 +03:00
committed by Sergey Mishin
parent a5edb6807e
commit b5d7ce8ebe
6 changed files with 54 additions and 7 deletions

View File

@@ -45,7 +45,7 @@ var (
configInSync = true configInSync = true
guiErrors = []guiError{} guiErrors = []guiError{}
guiErrorsMut sync.Mutex guiErrorsMut sync.Mutex
modt = time.Now().UTC().Format(http.TimeFormat) startTime = time.Now()
eventSub *events.BufferedSubscription eventSub *events.BufferedSubscription
) )
@@ -518,6 +518,7 @@ func restGetSystem(w http.ResponseWriter, r *http.Request) {
cpuUsageLock.RUnlock() cpuUsageLock.RUnlock()
res["cpuPercent"] = cpusum / float64(len(cpuUsagePercent)) / float64(runtime.NumCPU()) res["cpuPercent"] = cpusum / float64(len(cpuUsagePercent)) / float64(runtime.NumCPU())
res["pathSeparator"] = string(filepath.Separator) res["pathSeparator"] = string(filepath.Separator)
res["uptime"] = int(time.Since(startTime).Seconds())
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(res) json.NewEncoder(w).Encode(res)
@@ -833,7 +834,7 @@ func embeddedStatic(assetDir string) http.Handler {
w.Header().Set("Content-Type", mtype) w.Header().Set("Content-Type", mtype)
} }
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs))) w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs)))
w.Header().Set("Last-Modified", modt) w.Header().Set("Last-Modified", startTime.UTC().Format(http.TimeFormat))
w.Write(bs) w.Write(bs)
}) })

View File

@@ -158,6 +158,7 @@
"Upgrade To {%version%}": "Upgrade To {{version}}", "Upgrade To {%version%}": "Upgrade To {{version}}",
"Upgrading": "Upgrading", "Upgrading": "Upgrading",
"Upload Rate": "Upload Rate", "Upload Rate": "Upload Rate",
"Uptime": "Uptime",
"Use HTTPS for GUI": "Use HTTPS for GUI", "Use HTTPS for GUI": "Use HTTPS for GUI",
"Version": "Version", "Version": "Version",
"Versions Path": "Versions Path", "Versions Path": "Versions Path",

View File

@@ -320,6 +320,10 @@
</span> </span>
</td> </td>
</tr> </tr>
<tr>
<th><span class="glyphicon glyphicon-time"></span>&emsp;<span translate>Uptime</span></th>
<td class="text-right">{{system.uptime | duration:"m"}}</td>
</tr>
<tr> <tr>
<th><span class="glyphicon glyphicon-tag"></span>&emsp;<span translate>Version</span></th> <th><span class="glyphicon glyphicon-tag"></span>&emsp;<span translate>Version</span></th>
<td class="text-right">{{version}}</td> <td class="text-right">{{version}}</td>
@@ -1038,6 +1042,7 @@
<script src="scripts/syncthing/core/filters/alwaysNumberFilter.js"></script> <script src="scripts/syncthing/core/filters/alwaysNumberFilter.js"></script>
<script src="scripts/syncthing/core/filters/basenameFilter.js"></script> <script src="scripts/syncthing/core/filters/basenameFilter.js"></script>
<script src="scripts/syncthing/core/filters/binaryFilter.js"></script> <script src="scripts/syncthing/core/filters/binaryFilter.js"></script>
<script src="scripts/syncthing/core/filters/durationFilter.js"></script>
<script src="scripts/syncthing/core/filters/naturalFilter.js"></script> <script src="scripts/syncthing/core/filters/naturalFilter.js"></script>
<script src="scripts/syncthing/core/services/localeService.js"></script> <script src="scripts/syncthing/core/services/localeService.js"></script>

View File

@@ -1069,7 +1069,7 @@ angular.module('syncthing.core')
break; break;
} }
} }
}; }
folders.sort(); folders.sort();
return folders; return folders;

View File

@@ -0,0 +1,35 @@
/** convert amount of seconds to string format "d h m s" without zero values
* precision must be one of 'd', 'h', 'm', 's'(default)
* Example:
* {{121020003|duration}} --> 1400d 16h 40m 3s
* {{121020003|duration:"m"}} --> 1400d 16h 40m
* {{121020003|duration:"h"}} --> 1400d 16h
* {{1|duration:"h"}} --> <1h
**/
angular.module('syncthing.core')
.filter('duration', function () {
'use strict';
var SECONDS_IN = {"d": 86400, "h": 3600, "m": 60, "s": 1};
return function (input, precision) {
var result = "";
if (!precision) {
precision = "s";
}
input = parseInt(input, 10);
for (var k in SECONDS_IN) {
var t = (input/SECONDS_IN[k] | 0); // Math.floor
if (t > 0) {
result += " " + t + k;
}
if (precision == k) {
return result ? result : "<1" + k;
} else {
input %= SECONDS_IN[k];
}
}
return "[Error: incorrect usage, precision must be one of " + Object.keys(SECONDS_IN) + "]";
};
});

File diff suppressed because one or more lines are too long