Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Added MultiMinion and cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter af Geijerstam committed Feb 13, 2015
1 parent dd991c2 commit cfdf87b
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 14 deletions.
11 changes: 11 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
History
=======

0.4
Added MultiMinion - Possibility to monitor several titan-machines in one view
Added shortcut to return to the legacy-interface
Changed format for uptime-duration to make it more readable
Favicon added. (Created by "Bleh Blob" - Creative Commons License)

0.3
First public release
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"d3": "~3.3.13",
"bootstrap": "~3.3.1",
"angular-route": "~1.3.4"
"angular-route": "~1.3.4",
"angular-cookies": "~1.3.4"
}
}
9 changes: 7 additions & 2 deletions coffee/app.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
angular.module('KncMinionApp', ['ngRoute', 'KncMinionApp.directives'])
angular.module('KncMinionApp', ['ngRoute', 'ngCookies', 'KncMinionApp.directives'])


.config(['$routeProvider', ($routeProvider) ->
routeConfigs = [
['/','partials/main.html', minionController]
['/multi','partials/multi.html', multiMinionController]
]
for routeConfig in routeConfigs
route = routeConfig[0]
Expand All @@ -16,7 +17,11 @@ angular.module('KncMinionApp', ['ngRoute', 'KncMinionApp.directives'])
return
])

#.config(['$httpProvider', ($httpProvider) ->
# delete $httpProvider.defaults.headers.common['X-Requested-With']
# return
#])

.run(['$rootScope', ($rootScope) ->
return
])

15 changes: 13 additions & 2 deletions coffee/directives.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
module = angular.module("KncMinionApp.directives", [])

module.directive('ngEnter', () ->
return (scope, element, attrs) ->
element.bind("keydown keypress", (event) ->
if event.which == 13
scope.$apply(() ->
scope.$eval(attrs.ngEnter)
)
event.preventDefault()
)
)

module.directive('d3Graph', ['$window', '$interval', '$timeout', ($window, $interval, $timeout) ->
return {
restrict: 'EA'
Expand Down Expand Up @@ -31,7 +42,7 @@ module.directive('d3Graph', ['$window', '$interval', '$timeout', ($window, $inte
scope.lastValueUpdateCounter = scope.counter

# Remove all datapoints that are too old
limit = new Date(Date.now() - scope.duration * 1000 * 2)
limit = new Date(Date.now() - (scope.duration+5) * 1000)
while scope.data[0]?.date < limit
scope.data.shift()

Expand All @@ -45,7 +56,7 @@ module.directive('d3Graph', ['$window', '$interval', '$timeout', ($window, $inte
rightMargin = if scope.plotCurrent then 50 else 0

millisecondsPerPixel = (scope.duration * 1000) / (width-rightMargin)
scope.updatefrequency = Math.max(250, millisecondsPerPixel * 2)
scope.updatefrequency = Math.max(500, millisecondsPerPixel * 2)

if scope.updateDataPromise?
# Clear old interval
Expand Down
9 changes: 7 additions & 2 deletions coffee/fake_titan.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#
# http://127.0.0.1:8080/build/www/pages/kncminion/#/
#
# It also simulates titans on port 9001,9002 and 9003
# to test multi-titan-monitoring

fs = require("fs")
host = "127.0.0.1"
port = "8080"
ports = [8080,9001,9002,9003]
express = require("express")

app = express()
Expand Down Expand Up @@ -107,6 +109,7 @@ bfgminer_summary = (request,response) ->
response.send(JSON.stringify(data))

bfgminer_procs = (request,response) ->
response.header("Access-Control-Allow-Origin", "*")
data = {
"STATUS": [
{
Expand Down Expand Up @@ -161,4 +164,6 @@ app.get("/cgi-bin/fetch_mining_stat.cgi",fake_mining_stat)
app.get("/cgi-bin/bfgminer_summary.cgi",bfgminer_summary)
app.get("/cgi-bin/bfgminer_procs.cgi",bfgminer_procs)

app.listen(port,host)
for port in ports
console.log("Listening on port " + port)
app.listen(port,host)
11 changes: 9 additions & 2 deletions coffee/minioncontroller.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@minionController = ['$scope','$rootScope','$timeout','$interval', '$http', ($scope, $rootScope, $timeout, $interval, $http) ->
@minionController = ['$scope','$rootScope','$timeout','$interval', '$http', '$location', ($scope, $rootScope, $timeout, $interval, $http, $location) ->



Expand Down Expand Up @@ -60,7 +60,7 @@
minutes = "0" + minutes
if (seconds < 10)
seconds = "0" + seconds
time = hours+':'+minutes+':'+seconds
time = hours+'h '+minutes+'m '+seconds + "s"
if days == 1
time = days + " day " + time
if days > 1
Expand Down Expand Up @@ -126,6 +126,13 @@
$scope.titleimage = "images/minion#{i}.png"
return

$scope.go = (path) ->
$location.path(path)

$scope.navigate = (path) ->
window.location = path


setupValues()
fetchStatus()
fetchSummary()
Expand Down
166 changes: 166 additions & 0 deletions coffee/multiminioncontroller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
@multiMinionController = ['$scope','$rootScope','$timeout','$interval', '$http', '$location', '$cookies', ($scope, $rootScope, $timeout, $interval, $http, $location, $cookies) ->



setupValues = () ->
$scope.titans = []
$scope.hosts = []

$scope.hashrate = undefined
$scope.hashratetimestamp = Date.now()
$scope.intervals = [ { time: 60, text: "1m"}, { time: 600, text: "10m"}, { time: 3600, text: "1 hour"} ]
$scope.selectedInterval = 600

$scope.styles = [ "light", "dark" ]
$rootScope.selectedStyle = $scope.styles[0]

$scope.interpolations = [
{ value: "cardinal", text: "spline" }
{ value: "linear", text: "linear"}
{ value: "step-after", text: "step"}
]
$scope.selectedInterpolation = $scope.interpolations[0].value

$scope.metrics = []
return

titanComparer = (a,b) ->
if a.id == 'localhost'
return -1
if b.id == 'localhost'
return 1
return a.id.localeCompare(b.id)


sortTitans = () ->
$scope.titans.sort(titanComparer)
return


updateStatus = (titanid, data) ->
hashrate = 0
hashratetimestamp = Date.now()
$scope.titans = (t for t in $scope.titans when t.id != titanid)
if data.DEVS?
for die in data.DEVS
hashrate += die["MHS 20s"]
hashrate = parseFloat(hashrate.toFixed(2))
$scope.titans.push({ id: titanid, hashrate: hashrate, timestamp: hashratetimestamp })
sortTitans()
$scope.hashrate = 0
for t in $scope.titans
$scope.hashrate += t.hashrate
$scope.hashrate = parseFloat($scope.hashrate.toFixed(2))
$scope.hashratetimestamp = Date.now()
return

createUpdateFn = (titanid) ->
return (data) ->
updateStatus(titanid,data)
return

toReadableDuration = (s) ->
sec_num = parseInt(s, 10)
days = Math.floor(sec_num / 86400)
hours = Math.floor((sec_num - (days * 86400)) / 3600)
minutes = Math.floor((sec_num - (days * 86400) - (hours * 3600)) / 60)
seconds = sec_num - (days * 86400) - (hours * 3600) - (minutes * 60)

if hours < 10
hours = "0" + hours
if (minutes < 10)
minutes = "0" + minutes
if (seconds < 10)
seconds = "0" + seconds
time = hours+':'+minutes+':'+seconds
if days == 1
time = days + " day " + time
if days > 1
time = days + " days " + time
return time



fetchStatus = () ->
hosts = [ 'localhost' ]
hosts = hosts.concat($scope.hosts)
for host in hosts
titanid = host
url = '/cgi-bin/bfgminer_procs.cgi'
if host != 'localhost'
url = 'http://' + host + url
req = {
url : url
cache: false
method: 'GET'
}
url = ''
$http(req).success(createUpdateFn(titanid))
return



$scope.selectInterval = (interval) ->
$scope.selectedInterval = interval.time
return

$scope.selectStyle = (style) ->
$rootScope.selectedStyle = style
return

$scope.selectInterpolation = (interpolation) ->
$scope.selectedInterpolation = interpolation.value
return

getRandomImage = () ->
imageCount = 22
i = Math.floor((Math.random()*imageCount)+1)
if i < 10
i = "0" + i
return "images/minion#{i}.png"

selectRandomImage = () ->
$scope.titleimage1 = getRandomImage()
$scope.titleimage2 = getRandomImage()
$scope.titleimage3 = getRandomImage()

return

loadHostsFromCookie = () ->
hosts = $cookies.hosts
if hosts?
$scope.hosts = JSON.parse(hosts)

saveHostsToCookie = () ->
$cookies.hosts = JSON.stringify($scope.hosts)

$scope.addNewHost = () ->
$scope.hosts.push($scope.newHost)
$scope.titans.push({ id: $scope.newHost, hashrate: 0, timestamp: Date.now() })
sortTitans()
delete $scope.newHost
saveHostsToCookie()

$scope.go = (path) ->
$location.path(path)

$scope.navigate = (path) ->
window.location = path

$scope.removeTitan = (id) ->
$scope.titans = (t for t in $scope.titans when t.id != id)
$scope.hosts = (h for h in $scope.hosts when h != id)
saveHostsToCookie()


setupValues()
loadHostsFromCookie()
fetchStatus()
$interval(fetchStatus,5000)

selectRandomImage()

$interval(selectRandomImage,60000)

return
]
54 changes: 54 additions & 0 deletions config/etc/lighttpd/lighttpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
server.modules = (
"mod_access",
"mod_accesslog",
"mod_setenv",
"mod_alias",
"mod_auth",
"mod_compress",
"mod_redirect",
# "mod_rewrite",
"mod_cgi",
)

server.document-root = "/var/www/pages"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
#server.username = "root"
#server.groupname = "root"
server.port = 80

server.breakagelog = "/var/log/lighttpd/breakage.log"
accesslog.filename = "/var/log/lighttpd/lighttpd.log"

$HTTP["url"] !~ "^/cgi-bin/bfgminer_procs.cgi" {
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/config/lighttpd-htdigest.user"
auth.require = ( "/" =>
(
"method" => "basic",
"realm" => "KnC Miner configuration",
"require" => "valid-user"
)
)
}

cgi.assign = ( ".cgi" => "/bin/bash" )


index-file.names = ( "index.cgi", "index.php", "index.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".cgi" )

compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

setenv.add-response-header = (
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "GET"
)
Loading

0 comments on commit cfdf87b

Please sign in to comment.