pull/6/head
halcyon 10 years ago
parent cf8af114fe
commit 3c70512d8e

@ -6,6 +6,7 @@ urlpatterns = patterns('',
# url(r'^$', 'jumpserver.views.home', name='home'), # url(r'^$', 'jumpserver.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
(r'^$', 'jumpserver.views.index'), (r'^$', 'jumpserver.views.index'),
(r'^api/user/$', 'jumpserver.views.api_user'),
(r'^skin_config/$', 'jumpserver.views.skin_config'), (r'^skin_config/$', 'jumpserver.views.skin_config'),
(r'^base/$', 'jumpserver.views.base'), (r'^base/$', 'jumpserver.views.base'),
(r'^login/$', 'jumpserver.views.login'), (r'^login/$', 'jumpserver.views.login'),

@ -6,7 +6,9 @@ import json
from django.db.models import Count from django.db.models import Count
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.core.paginator import Paginator, EmptyPage, InvalidPage
from juser.models import User from juser.models import User
@ -36,8 +38,6 @@ def index(request):
path1, path2 = u'仪表盘', 'Dashboard' path1, path2 = u'仪表盘', 'Dashboard'
dic = {} dic = {}
li_date, li_str = getDaysByNum(7) li_date, li_str = getDaysByNum(7)
# li_str = json.dumps(li_str)
# print li_str, type(li_str)
today = datetime.datetime.now().day today = datetime.datetime.now().day
from_week = datetime.datetime.now() - datetime.timedelta(days=7) from_week = datetime.datetime.now() - datetime.timedelta(days=7)
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()]) week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
@ -51,12 +51,17 @@ def index(request):
times = user_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count() times = user_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
li.append(times) li.append(times)
dic[username] = li dic[username] = li
print dic
users = User.objects.all() users = User.objects.all()
hosts = Asset.objects.all() hosts = Asset.objects.all()
online_host = Log.objects.filter(is_finished=0) online_host = Log.objects.filter(is_finished=0)
online_user = online_host.distinct() online_user = online_host.distinct()
return render_to_response('index.html', locals()) return render_to_response('index.html', locals(), context_instance=RequestContext(request))
def api_user(request):
users = Log.objects.filter(is_finished=0).count()
ret = {'users': users}
return HttpResponse(json.dumps(ret))
def skin_config(request): def skin_config(request):
@ -76,14 +81,10 @@ def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_com
is_active = {u'': '1', u'': '2'} is_active = {u'': '1', u'': '2'}
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'} login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
for group in j_group[0].split(): for group in j_group[0].split():
print group.strip()
c = BisGroup.objects.get(name=group.strip()) c = BisGroup.objects.get(name=group.strip())
groups.append(c) groups.append(c)
j_type = login_types[j_type] j_type = login_types[j_type]
print j_type
j_idc = IDC.objects.get(name=j_idc) j_idc = IDC.objects.get(name=j_idc)
print j_idc
print
a = Asset.objects.get(id=j_id) a = Asset.objects.get(id=j_id)
if j_type == 'M': if j_type == 'M':
a.ip = j_ip a.ip = j_ip

@ -60,7 +60,7 @@
</div> </div>
<div id="high" style="width:100%;height:400px;"></div> <div id="high" style="width:100%;height:400px;"></div>
</br> </br>
<div id="dynamic" style="width:100%;height:400px;"></div> <div id="dynamic" style="width:100%;height:400px; margin-top:170px"></div>
</div> </div>
</div> </div>
@ -102,8 +102,10 @@ $(function () {
}, },
series: [ series: [
{% for k,v in dic.items %} {% for k,v in dic.items %}
{name: '{{ k }}', {
data: {{ v }}}, name: '{{ k }}',
data: {{ v }}
},
{% endfor %} {% endfor %}
] ]
}); });
@ -123,27 +125,30 @@ $(function () {
marginRight: 10, marginRight: 10,
events: { events: {
load: function () { load: function () {
// set up the updating of the chart each second
var series = this.series[0]; var series = this.series[0];
setInterval(function () { setInterval(function () {
jQuery.getJSON('api/user/', function (data) {
var users = data.users;
var x = (new Date()).getTime(), // current time var x = (new Date()).getTime(), // current time
y = Math.random(); y = users;
console.log(users)
series.addPoint([x, y], true, true); series.addPoint([x, y], true, true);
}, 1000); });
}, 3000);
} }
} }
}, },
title: { title: {
text: 'Live random data' text: '实时在线用户统计'
}, },
xAxis: { xAxis: {
type: 'datetime', type: 'datetime',
tickPixelInterval: 150 tickPixelInterval: 150
}, },
yAxis: { yAxis: {
min: 0,
title: { title: {
text: 'Value' text: '用户数量'
}, },
plotLines: [{ plotLines: [{
value: 0, value: 0,
@ -155,7 +160,7 @@ $(function () {
formatter: function() { formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+ return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+ Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2); Highcharts.numberFormat(this.y);
} }
}, },
legend: { legend: {
@ -165,7 +170,7 @@ $(function () {
enabled: false enabled: false
}, },
series: [{ series: [{
name: 'Random data', name: '实时在线用户数量',
data: (function() { data: (function() {
// generate an array of random data // generate an array of random data
var data = [], var data = [],
@ -175,7 +180,7 @@ $(function () {
for (i = -19; i <= 0; i++) { for (i = -19; i <= 0; i++) {
data.push({ data.push({
x: time + i * 1000, x: time + i * 1000,
y: Math.random() y: 0
}); });
} }
return data; return data;

Loading…
Cancel
Save