Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
enginestatus use ajax to retrive
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Jan 5, 2020
1 parent 032b21a commit 07fd9de
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 400 deletions.
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ require (
github.com/NYTimes/gziphandler v1.1.1
github.com/anacrolix/log v0.5.0
github.com/anacrolix/torrent v1.11.0
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/boypt/scraper v1.0.2
github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/elithrar/simple-scrypt v1.3.0 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
github.com/jpillora/ansi v1.0.0 // indirect
github.com/jpillora/archive v0.0.0-20160301031048-e0b3681851f1
github.com/jpillora/cloud-torrent v0.0.0-00010101000000-000000000000
github.com/jpillora/cookieauth v0.0.0-20190219222732-2ae29b2a9c76
github.com/jpillora/eventsource v0.0.0-20170920003432-7ed8c999e167 // indirect
github.com/jpillora/opts v1.1.0
github.com/jpillora/requestlog v0.0.0-20181015073026-df8817be5f82
github.com/jpillora/sizestr v0.0.0-20160130011556-e2ea2fa42fb9 // indirect
github.com/jpillora/velox v0.0.0-20180825063758-42845d323220
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mmcdole/gofeed v1.0.0-beta2
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/pkg/errors v0.8.1
github.com/radovskyb/watcher v1.0.6
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
)

Expand Down
20 changes: 13 additions & 7 deletions scripts/make_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ OS=""
ARCH=""
EXESUFFIX=""
PKGCMD="gzip"
NOSTATIC=

for arg in "$@"; do
case $arg in
Expand All @@ -23,7 +24,10 @@ case $arg in
;;
xz)
PKGCMD=xz
;;
;;
nostat)
NOSTATIC=1
;;
nozip)
PKGCMD=
;;
Expand All @@ -39,13 +43,15 @@ if [[ -z $ARCH ]]; then
ARCH=$(go env GOARCH)
fi

pushd $__dir/../static
if ! git diff-index --quiet HEAD . ; then
echo "Warning: static change and not commited"
exit 1
if [[ -z $NOSTATIC ]]; then
pushd $__dir/../static
if ! git diff-index --quiet HEAD . ; then
echo "Warning: static change and not commited"
exit 1
fi
sh generate.sh
popd
fi
sh generate.sh
popd

pushd $__dir/..
BINFILE=${BIN}_${OS}_${ARCH}${SUFFIX}
Expand Down
1 change: 0 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type Server struct {
LatestRSSGuid string
Torrents map[string]*engine.Torrent
Users map[string]string
EngineStatus string
Stats struct {
Title string
Version string
Expand Down
3 changes: 3 additions & 0 deletions server/server_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (s *Server) apiGET(w http.ResponseWriter, r *http.Request) error {
s.state.Lock()
json.NewEncoder(w).Encode(s.state.Stats)
s.state.Unlock()
case "enginedebug":
w.Header().Set("Content-Type", "text/plain")
s.engine.WriteStauts(w)
default:
return errUnknowAct
}
Expand Down
7 changes: 0 additions & 7 deletions server/server_bg.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package server

import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -36,15 +34,10 @@ func (s *Server) backgroundRoutines() {

//start collecting stats
go func() {
var sBuf bytes.Buffer
sWriter := bufio.NewWriter(&sBuf)
for {
if s.state.NumConnections() > 0 {
c := s.engine.Config()
s.state.Stats.System.loadStats(c.DownloadDirectory)
sBuf.Reset()
s.engine.WriteStauts(sWriter)
s.state.EngineStatus = sBuf.String()
}
time.Sleep(5 * time.Second)
}
Expand Down
623 changes: 313 additions & 310 deletions static/files.go

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions static/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,20 @@ <h2>
</div>
<div>
<span ng-if="state.Stats.System.set">
<span ng-click="$root.showEnineStatus = !$root.showEnineStatus">ShowDebugInfo,</span>
<span>
cpu {{ state.Stats.System.cpu | round }}%,
</span>
<span>
mem {{ state.Stats.System.memUsedPercent | round }}%,
</span>
<span ng-click="toggleSections('enginedebug')">ShowDebugInfo,</span>
<span>
disk {{ state.Stats.System.diskUsedPercent | round }}%,
</span>
</span>
<span ng-if="state.Stats.Uptime">up {{ ago(state.Stats.Uptime) }}</span>
</div>
</footer>
<div ng-if="$root.showEnineStatus" class="ui mini message">
<div ng-if="$root.showEnineStatus" class="ui attached mini message">
<i ng-click="$root.showEnineStatus = false" class="close icon"></i>
<div class="header">
Torrent Engine Info
System Info
</div>
<span ng-if="state.Stats.System.set">
<p ng-if="state.Stats.System.set">
<span>
goroutines {{ state.Stats.System.goRoutines }},
</span>
Expand All @@ -116,10 +110,14 @@ <h2>
<span>
disk {{ state.Stats.System.diskUsedPercent | round }}%,
</span>
</span>
<span ng-if="state.Stats.Uptime">up {{ ago(state.Stats.Uptime) }}</span>
<pre>{{ $root.state.EngineStatus }}</pre>
<span ng-if="$root.state.EngineStatus.length === 0">Torrent Enging Bootstraping ...</span>
<span ng-if="state.Stats.Uptime">up {{ ago(state.Stats.Uptime) }}</span>
</p>
<div class="header">
Torrent Engine Status
</div>
<p>
<pre>{{ EngineStatus }}</pre>
</p>
</div>
</div>
<script src="js/vendor/query-string.js"></script>
Expand Down
11 changes: 10 additions & 1 deletion static/files/js/run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals app,window */

//RootController
app.run(function ($rootScope, search, api, storage) {
app.run(function ($rootScope, search, api, apiget, storage) {
var $scope = (window.scope = $rootScope);

var pn = window.location.pathname
Expand Down Expand Up @@ -124,6 +124,15 @@ app.run(function ($rootScope, search, api, storage) {
case "omni":
$rootScope.omni.edit = !$rootScope.omni.edit;
break
case "enginedebug":
$rootScope.showEnineStatus = !$rootScope.showEnineStatus;
if ($rootScope.showEnineStatus) {
$rootScope.EngineStatus = "loading...";
apiget.enginedebug().success(function (data) {
$rootScope.EngineStatus = data;
})
}
break
}
}

Expand Down
Loading

0 comments on commit 07fd9de

Please sign in to comment.