Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#706 websockets #724

Merged
merged 24 commits into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
41879cc
Environ issues
gkadillak Jul 4, 2015
5e198bf
Kernel info, uptime being sent to dashboard
gkadillak Jul 9, 2015
d467c3b
Added styling, removed polling for kernel version
gkadillak Jul 9, 2015
8def48e
Use handler map to set abstract socket connections
gkadillak Jul 10, 2015
e8a1b82
Forgot end of comment
gkadillak Jul 10, 2015
ae3741e
Change the server port number
gkadillak Jul 10, 2015
b71bfcb
Merge branch 'master' of https://github.com/rockstor/rockstor-core in…
gkadillak Jul 10, 2015
ac3e490
update buildout for new changes in library update process. #706
schakrava Jul 10, 2015
fbf3d91
Kernel version, uptime displayed
gkadillak Jul 10, 2015
b2622bd
Merge branch 'issue#706-websockets' of github.com:gkadillak/rockstor-…
gkadillak Jul 10, 2015
e346186
simplify gunicorn parts in buildout.
schakrava Jul 10, 2015
718361d
simplify supervisord config part in buildout. #706
schakrava Jul 11, 2015
57e0b30
simplify django settings part in buildout. #706
schakrava Jul 11, 2015
b922cea
Merge branch 'issue#706-websockets' of https://github.com/gkadillak/r…
schakrava Jul 12, 2015
7540876
Use /run(which is tmpfs) for gunicorn and supervisord pids. #660
schakrava Jul 12, 2015
54eb94c
Fixes to dashboard (null error), socket handler
gkadillak Jul 14, 2015
11f0bb1
Merge branch 'issue#706-websockets' of github.com:gkadillak/rockstor-…
gkadillak Jul 14, 2015
9723c83
dc2 supervisord function got lost in translation
gkadillak Jul 14, 2015
1ec51bd
Log connections, write disconnect code
gkadillak Jul 14, 2015
5c92337
Polling removed from services
gkadillak Jul 14, 2015
998bec8
Update each model in collection via websockets
gkadillak Jul 14, 2015
d2e4160
update jslibs with socketio. #706
schakrava Jul 14, 2015
2c52ee5
Updated frontend to point to shop
gkadillak Jul 14, 2015
6d3ff21
Clean up, remove console.logs
gkadillak Jul 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Kernel info, uptime being sent to dashboard
  • Loading branch information
gkadillak committed Jul 9, 2015
commit 5e198bfb4addbca2442f01fde909e40efa44403c
95 changes: 95 additions & 0 deletions src/rockstor/smart_manager/dc2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from gevent import monkey
monkey.patch_all()
import gevent
from socketio.server import SocketIOServer
from socketio import socketio_manage
from socketio.namespace import BaseNamespace
from socketio.mixins import BroadcastMixin

from django.conf import settings
from system.osi import (uptime, kernel_info)

import logging
logger = logging.getLogger(__name__)


class DashboardNamespace(BaseNamespace, BroadcastMixin):
def initialize(self):
pass


class SysinfoNamespace(BaseNamespace, BroadcastMixin):
start = False
supported_kernel = settings.SUPPORTED_KERNEL_VERSION

def initialize(self):
self.emit("sysinfo", {"sysinfo": "connected"})
self.start = True
gevent.spawn(self.send_uptime)
gevent.spawn(self.send_kernel_info)

def recv_disconnect(self):
self.start = False
self.disconnect(silent=True)

def send_uptime(self):

while self.start:
if not self.start:
break
self.emit('uptime', {'uptime': uptime()})
# seconds not displayed
gevent.sleep(30)

def send_kernel_info(self):
while self.start:
if not self.start:
break
try:
self.emit('kernel_info', {'kernel_info':
kernel_info(self.supported_kernel)})
except:
self.error('unsupported_kernel', 'the kernel is bad')
# kernel information doesn't change that much
gevent.sleep(1000)


class Application(object):
def __init__(self):
self.buffer = []

def __call__(self, environ, start_response):
path = environ['PATH_INFO'].strip('/') or 'index.html'

if path.startswith('/static') or path == 'index.html':
try:
data = open(path).read()
except Exception:
return not_found(start_response)

if path.endswith(".js"):
content_type = "text/javascript"
elif path.endswith(".css"):
content_type = "text/css"
elif path.endswith(".swf"):
content_type = "application/x-shockwave-flash"
else:
content_type = "text/html"

start_response('200 OK', [('Content-Type', content_type)])
return [data]
if path.startswith("socket.io"):
socketio_manage(environ, {'/sysinfo': SysinfoNamespace})
socketio_manage(environ, {'/dashboard': DashboardNamespace})


def not_found(start_response):
start_response('404 Not Found', [])
return ['<h1>Not found</h1>']


def main():
logger.debug('Listening on port http://127.0.0.1:8080 and on port 10843 (flash policy server)')
server = SocketIOServer(('127.0.0.1', 8080), Application(),
resource="socket.io", policy_server=True).serve_forever()

37 changes: 1 addition & 36 deletions src/rockstor/storageadmin/static/storageadmin/js/rockstor.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,42 +441,7 @@ function fetchKernelInfo() {
}
});
}

function displayLoadAvg(data) {
var n = parseInt(data.results[0]['uptime']);
var load_1 = parseFloat(data.results[0]['load_1']);
var load_5 = parseFloat(data.results[0]['load_5']);
var load_15 = parseFloat(data.results[0]['load_15']);
var secs = n % 60;
var mins = Math.round(n/60) % 60;
var hrs = Math.round(n / (60*60)) % 24;
var days = Math.round(n / (60*60*24)) % 365;
var yrs = Math.round(n / (60*60*24*365));
var str = 'Uptime: ';
if (RockStorGlobals.kernel) {
str = 'Linux: ' + RockStorGlobals.kernel + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + str;
}
if (yrs == 1) {
str += yrs + ' year, ';
} else if (yrs > 1) {
str += yrs + ' years, ';
}
if (days == 1) {
str += days + ' day, ';
} else if (days > 1) {
str += days + ' days, ';
}
if (hrs < 10) {
str += '0';
}
str += hrs + ':';
if (mins < 10) {
str += '0';
}
str += mins;
str += ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Load: ' + load_1 + ', ' + load_5 + ', ' + load_15;
$('#appliance-loadavg').html(str);
}
*/

function fetchServerTime() {
RockStorGlobals.serverTimeTimer = window.setInterval(function() {
Expand Down
56 changes: 49 additions & 7 deletions src/rockstor/storageadmin/static/storageadmin/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,12 @@ var AppRouter = Backbone.Router.extend({
if (RockStorGlobals.currentAppliance == null) {
setApplianceName();
}
if (!RockStorGlobals.loadAvgDisplayed) {
updateLoadAvg();
}
if (!RockStorGlobals.serverTimeFetched) {
fetchServerTime();
}
if (!RockStorGlobals.browserChecked) {
checkBrowser();
}
if (!RockStorGlobals.kernel) {
fetchKernelInfo();
}

// set a timer to get current rockstor version and checkif there is an
// update available
Expand Down Expand Up @@ -887,5 +881,53 @@ $(document).ready(function() {
$('#contrib-form').submit()
$('#donate-modal').modal('hide');
});
Rockstorsocket = io.connect('/dashboard', {secure: 'false', url: 'http://192.168.56.105:8080'});
var $loadavg = $('#appliance-loadavg');
var socket = io.connect('/sysinfo', {'secure': true});


socket.on('sysinfo', function(data) {
console.log(data);
});

socket.on('uptime', function(data) {
displayLoadAvg(data);
});

socket.on('kernel_info', function(data) {
$loadavg.text('Linux: ' + data.kernel_info);
});

socket.on('unsupported_kernel', function() {
console.log('unsupported kernel');
});
});


function displayLoadAvg(data) {
var n = parseInt(data.uptime);
var secs = n % 60;
var mins = Math.round(n/60) % 60;
var hrs = Math.round(n / (60*60)) % 24;
var days = Math.round(n / (60*60*24)) % 365;
var yrs = Math.round(n / (60*60*24*365));
var str = 'Uptime: ';
if (yrs == 1) {
str += yrs + ' year, ';
} else if (yrs > 1) {
str += yrs + ' years, ';
}
if (days == 1) {
str += days + ' day, ';
} else if (days > 1) {
str += days + ' days, ';
}
if (hrs < 10) {
str += '0';
}
str += hrs + ':';
if (mins < 10) {
str += '0';
}
str += mins;
$('#uptime').text(str);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<li><a id="donate_nav" href="#"><i class="fa fa-heart fa-lg" style="color:#BA0707" ></i> Donate</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#version" id="version-msg"></a></li>
<li><a href="#version" id="version-msg"></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span id="user-name"></span>
<span class="fa fa-power-off fa-lg fa-inverse"></i>
Expand Down
5 changes: 4 additions & 1 deletion src/rockstor/storageadmin/templates/storageadmin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<script src="/static/js/lib/moment.min.js"></script>
<script src="/static/js/lib/simple-slider.min.js"></script>
<script src="/static/js/lib/chosen.jquery.js"></script>
<script src="/static/js/lib/socket.io.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.6/socket.io.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkadillak Sorry if I've got the wrong end of the stick but shouldn't we copy this library "socket.io.min.js" to our local stash (/static/js/lib/) as what if someone is on a network with limited / or no internet access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is merely me being lazy, @phillxnet. Once the code gets pushed to production, the hard copy of the file will be referenced.

<script src="/static/storageadmin/js/storageadmin.js"></script>
</head>
<body>
Expand All @@ -126,7 +126,10 @@
</div> <!-- navbar -->
<div id="appliance-breadcrumb">
<a id="appliance-name" href="#"></a>
<div id="uptime"></div>
<div id="appliance-loadavg"></div>


</div>

<div id="wrapper1">
Expand Down