Browse Source

add online users and cpus

windows
Florian N 12 years ago
parent
commit
b4994c9a6b
  1. 36
      main/views.py
  2. 11
      templates/main.html
  3. 16
      templates/users.html

36
main/views.py

@ -1,4 +1,4 @@
import socket, platform, os
import socket, platform, os, multiprocessing
from datetime import timedelta
@ -75,7 +75,39 @@ def get_ipaddress():
data = str(err)
return data
def get_cpus():
"""
Get the number of CPUs and model/type
"""
try:
pipe = os.popen("cat /proc/cpuinfo |" + "grep 'model name'")
data = pipe.read().strip().split(':',2)[-1]
pipe.close()
cpus = multiprocessing.cpu_count()
data = {'cpus': cpus, 'type': data}
except Exception, err:
data = str(err)
return data
def get_users():
"""
Get the current logged in users
"""
try:
pipe = os.popen("who |" + "awk '{print $1, $2, $6}'")
data = pipe.read().strip().split()
pipe.close()
except Exception, err:
data = str(err)
return data
def get_traffic(request):
"""
Get the traffic for the specified interface
@ -161,7 +193,9 @@ def getall(request):
return render_to_response('main.html', {'getuptime': get_uptime(),
'gethostname': get_hostname(),
'getplatform': get_platform(),
'getcpus': get_cpus(),
'getdisk': get_disk(),
'getip': get_ipaddress(),
'getusers': get_users(),
'time_refresh': time_refresh
}, context_instance=RequestContext(request))

11
templates/main.html

@ -11,7 +11,6 @@
<link href="{% static "css/bootstrap-responsive.min.css" %}" rel="stylesheet">
<link href="{% static "css/dashboard.css" %}" rel="stylesheet">
<link href="{% static "css/style.css" %}" rel="stylesheet">
<link href="{% static "css/odometer.css" %}" rel="stylesheet">
{% block style %}{% endblock %}
</head>
<body>
@ -72,6 +71,7 @@
<b>OS:</b> <span class=""></span>{{ getplatform }}<br>
<b>Uptime:</b> <span class="" id="os-uptime"></span>{{ uptime }} Hours<br>
<b>Hostname:</b> <span class=""></span>{{ gethostname }}<br>
<b>CPU(s):</b> <span class=""></span>{{ getcpus.cpus }} x {{ getcpus.type }}
<br><br>
</div>
</div>
@ -113,14 +113,13 @@
</div>
</div>
<!-- /widget-header -->
<div class="widget-content" id="getdisk">
<div class="widget-content">
{% include 'disk.html' %}
</div>
<!-- /widget-content -->
</div>
<!-- /widget -->
</div>
<div class="span6">
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-bolt"></i>
@ -208,10 +207,7 @@
</div>
<!-- /widget-header -->
<div class="widget-content">
<table id="online_dashboard" class="table table-hover table-bordered table-condensed" >
</table>
{% include 'users.html' %}
</div>
<!-- /widget-content -->
</div>
@ -263,7 +259,6 @@
<script src="{% static "js/bootstrap.js" %}"></script>
<script src="{% static "js/jquery.dataTables.min.js" %}"></script>
<script src="{% static "js/Chart.min.js" %}"></script>
<script src="{% static "js/odometer.js" %}"></script>
<script type="text/javascript">
function get_os_data(url, element) {

16
templates/users.html

@ -0,0 +1,16 @@
<table class="table table-hover table-condensed table-bordered" >
<thead>
<tr>
<th>User</th>
<th>TTY</th>
<th>Logged in from</th>
</tr>
</thead>
<tbody>
{% for user in getusers %}
{% cycle '<tr>' '' ''%}
<td>{{user}}</td>
{% cycle '' '' '</tr>' %}
{% endfor %}
</tbody>
</table>
Loading…
Cancel
Save