Merge pull request #514 from jamez70/developer_mode_add_loghandling

Added logfile truncation and download buttons to developer mdoe screen
pull/437/merge
cyoung 2017-02-02 22:28:23 -05:00 zatwierdzone przez GitHub
commit 1ae6b5cb1f
6 zmienionych plików z 225 dodań i 23 usunięć

Wyświetl plik

@ -97,6 +97,7 @@ const (
)
var logFileHandle *os.File
var usage *du.DiskUsage
var maxSignalStrength int
@ -790,6 +791,10 @@ func updateStatus() {
usage = du.NewDiskUsage("/")
globalStatus.DiskBytesFree = usage.Free()
fileInfo, err := logFileHandle.Stat()
if err == nil {
globalStatus.Logfile_Size = fileInfo.Size()
}
}
type WeatherMessage struct {
@ -1086,8 +1091,8 @@ type status struct {
UAT_PIREP_total uint32
UAT_NOTAM_total uint32
UAT_OTHER_total uint32
Errors []string
Errors []string
Logfile_Size int64
}
var globalSettings settings
@ -1310,6 +1315,23 @@ func signalWatcher() {
gracefulShutdown()
}
func clearDebugLogFile() {
if logFileHandle != nil {
_, err := logFileHandle.Seek(0,0)
if err != nil {
log.Printf("Could not seek to the beginning of the logfile\n")
return
} else {
err2 := logFileHandle.Truncate(0)
if err2 != nil {
log.Printf("Could not truncate the logfile\n")
return
}
log.Printf("Logfile truncated\n")
}
}
}
func main() {
// Catch signals for graceful shutdown.
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
@ -1374,6 +1396,8 @@ func main() {
log.Printf("%s\n", err_log.Error())
} else {
defer fp.Close()
// Keep the logfile handle for later use
logFileHandle = fp
mfp := io.MultiWriter(fp, os.Stdout)
log.SetOutput(mfp)
}

Wyświetl plik

@ -364,6 +364,11 @@ func doReboot() {
syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
func handleDeleteLogFile(w http.ResponseWriter, r *http.Request) {
log.Printf("handleDeleteLogFile called!!!\n")
clearDebugLogFile()
}
func handleDevelModeToggle(w http.ResponseWriter, r *http.Request) {
log.Printf("handleDevelModeToggle called!!!\n")
globalSettings.DeveloperMode = true
@ -407,6 +412,18 @@ func delayReboot() {
doReboot()
}
func handleDownloadLogRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "applicaiton/zip")
w.Header().Set("Content-Disposition", "attachment; filename='stratux.log'")
http.ServeFile(w, r, "/var/log/stratux.log")
}
func handleDownloadDBRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "applicaiton/zip")
w.Header().Set("Content-Disposition", "attachment; filename='stratux.sqlite'")
http.ServeFile(w, r, "/var/log/stratux.sqlite")
}
// Upload an update file.
func handleUpdatePostRequest(w http.ResponseWriter, r *http.Request) {
setNoCache(w)
@ -615,7 +632,9 @@ func managementInterface() {
http.HandleFunc("/updateUpload", handleUpdatePostRequest)
http.HandleFunc("/roPartitionRebuild", handleroPartitionRebuild)
http.HandleFunc("/develmodetoggle", handleDevelModeToggle)
http.HandleFunc("/deletelogfile", handleDeleteLogFile)
http.HandleFunc("/downloadlog", handleDownloadLogRequest)
http.HandleFunc("/downloaddb", handleDownloadDBRequest)
err := http.ListenAndServe(managementAddr, nil)
if err != nil {

3
web/js/main.js 100644 → 100755
Wyświetl plik

@ -15,6 +15,9 @@ var URL_REBOOT = "http://" + URL_HOST_BASE + "/reboot";
var URL_SHUTDOWN = "http://" + URL_HOST_BASE + "/shutdown";
var URL_RESTARTAPP = "http://" + URL_HOST_BASE + "/restart";
var URL_DEV_TOGGLE_GET = "http://" + URL_HOST_BASE + "/develmodetoggle";
var URL_DELETELOGFILE = "http://" + URL_HOST_BASE + "/deletelogfile";
var URL_DOWNLOADLOGFILE = "http://" + URL_HOST_BASE + "/downloadlog";
var URL_DOWNLOADDB = "http://" + URL_HOST_BASE + "/downloaddb";
// define the module with dependency on mobile-angular-ui
//var app = angular.module('stratux', ['ngRoute', 'mobile-angular-ui', 'mobile-angular-ui.gestures', 'appControllers']);

Wyświetl plik

@ -1,21 +1,59 @@
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<span class="panel_label">Developer Mode Items</span>
</div>
<div class="panel-body">
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Restart Stratux application</div>
<div class="panel-body">
<div class="form-group reset-flow">
<div class="col-xs-12">
<a ng-click="postRestart()" ui-turn-off="modalRestartApp" class="btn btn-primary">Restart Application</a>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
Restart Stratux application
</div>
<div class="panel-body">
<div class="form-group reset-flow" align="center">
<div class="col-xs-12">
<a ng-click="postRestart()" class=
"btn btn-primary btn-block" style=
"margin-bottom:1em;">Restart Application</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
Logfile (Size: {{Logfile_Size}} bytes)
</div>
<div class="panel-body">
<div class="col-xs-12">
<a href="./downloadlog" ng-click="postDownloadLog()"
class="btn btn-primary btn-block" style=
"margin-bottom:0.5em;">Download Logfile</a>
</div>
<div class="col-xs-12">
<a ng-click="postDeleteLog()" class=
"btn btn-primary btn-block" style=
"margin-bottom:0.5em;">Delete Logfile</a>
</div>
</div>
</div>
</div>
<div class="panel-group col-sm-6" style="float:right;">
<div class="panel panel-default">
<div class="panel-heading">
Database
</div>
<div class="panel-body">
<div class="col-xs-12">
<a href="./downloaddb" ng-click="postDownloadDB()"
class="btn btn-primary btn-block" style=
"margin-bottom:0.5em;">Download Database</a>
</div>
</div>
</div>
</div>
</div>

118
web/plates/js/developer.js 100644 → 100755
Wyświetl plik

@ -4,6 +4,92 @@ DeveloperCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']
// create our controller function with all necessary logic
function DeveloperCtrl($rootScope, $scope, $state, $http, $interval) {
$scope.$parent.helppage = 'plates/developer-help.html';
function connect($scope) {
if (($scope === undefined) || ($scope === null))
return; // we are getting called once after clicking away from the status page
if (($scope.socket === undefined) || ($scope.socket === null)) {
socket = new WebSocket(URL_STATUS_WS);
$scope.socket = socket; // store socket in scope for enter/exit usage
}
$scope.ConnectState = "Disconnected";
socket.onopen = function (msg) {
// $scope.ConnectStyle = "label-success";
$scope.ConnectState = "Connected";
};
socket.onclose = function (msg) {
// $scope.ConnectStyle = "label-danger";
$scope.ConnectState = "Disconnected";
$scope.$apply();
delete $scope.socket;
setTimeout(function() {connect($scope);}, 1000);
};
socket.onerror = function (msg) {
// $scope.ConnectStyle = "label-danger";
$scope.ConnectState = "Error";
$scope.$apply();
};
socket.onmessage = function (msg) {
console.log('Received status update.')
var status = JSON.parse(msg.data)
// Update Status
$scope.Version = status.Version;
$scope.Build = status.Build.substr(0, 10);
$scope.Devices = status.Devices;
$scope.Ping_connected = status.Ping_connected;
$scope.Connected_Users = status.Connected_Users;
$scope.UAT_messages_last_minute = status.UAT_messages_last_minute;
$scope.UAT_messages_max = status.UAT_messages_max;
$scope.ES_messages_last_minute = status.ES_messages_last_minute;
$scope.ES_messages_max = status.ES_messages_max;
$scope.GPS_satellites_locked = status.GPS_satellites_locked;
$scope.GPS_satellites_tracked = status.GPS_satellites_tracked;
$scope.GPS_satellites_seen = status.GPS_satellites_seen;
$scope.GPS_solution = status.GPS_solution;
$scope.GPS_position_accuracy = String(status.GPS_solution ? ", " + status.GPS_position_accuracy.toFixed(1) : "");
$scope.RY835AI_connected = status.RY835AI_connected;
$scope.UAT_METAR_total = status.UAT_METAR_total;
$scope.UAT_TAF_total = status.UAT_TAF_total;
$scope.UAT_NEXRAD_total = status.UAT_NEXRAD_total;
$scope.UAT_SIGMET_total = status.UAT_SIGMET_total;
$scope.UAT_PIREP_total = status.UAT_PIREP_total;
$scope.UAT_NOTAM_total = status.UAT_NOTAM_total;
$scope.UAT_OTHER_total = status.UAT_OTHER_total;
$scope.Logfile_Size = status.Logfile_Size;
// Errors array.
if (status.Errors.length > 0) {
$scope.visible_errors = true;
$scope.Errors = status.Errors;
}
var uptime = status.Uptime;
if (uptime != undefined) {
var up_d = parseInt((uptime/1000) / 86400),
up_h = parseInt((uptime/1000 - 86400*up_d) / 3600),
up_m = parseInt((uptime/1000 - 86400*up_d - 3600*up_h) / 60),
up_s = parseInt((uptime/1000 - 86400*up_d - 3600*up_h - 60*up_m));
$scope.Uptime = String(up_d + "/" + ((up_h < 10) ? "0" + up_h : up_h) + ":" + ((up_m < 10) ? "0" + up_m : up_m) + ":" + ((up_s < 10) ? "0" + up_s : up_s));
} else {
// $('#Uptime').text('unavailable');
}
var boardtemp = status.CPUTemp;
if (boardtemp != undefined) {
/* boardtemp is celcius to tenths */
$scope.CPUTemp = String(boardtemp.toFixed(1) + 'C / ' + ((boardtemp * 9 / 5) + 32.0).toFixed(1) + 'F');
} else {
// $('#CPUTemp').text('unavailable');
}
$scope.$apply(); // trigger any needed refreshing of data
};
}
$scope.postRestart = function () {
$http.post(URL_RESTARTAPP).
@ -14,5 +100,37 @@ function DeveloperCtrl($rootScope, $scope, $state, $http, $interval) {
// do nothing
});
};
$scope.postDeleteLog = function () {
$http.post(URL_DELETELOGFILE).
then(function (response) {
// do nothing
// $scope.$apply();
}, function (response) {
// do nothing
});
};
$scope.postDownloadLog = function () {
$http.post(URL_DOWNLOADLOGFILE).
then(function (response) {
// do nothing
// $scope.$apply();
}, function (response) {
// do nothing
});
};
$scope.postDownloadDB = function () {
$http.post(URL_DOWNLOADDB).
then(function (response) {
// do nothing
// $scope.$apply();
}, function (response) {
// do nothing
});
};
connect($scope); // connect - opens a socket and listens for messages
};

Wyświetl plik

@ -126,8 +126,8 @@
</div>
</div>
</div>
</div>
<!-- Developer mode area -->
<div class="col-sm-12">
<div ng-show="DeveloperMode" class="panel-group col-sm-6">