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'^blog/', include('blog.urls')),
(r'^$', 'jumpserver.views.index'),
(r'^api/user/$', 'jumpserver.views.api_user'),
(r'^skin_config/$', 'jumpserver.views.skin_config'),
(r'^base/$', 'jumpserver.views.base'),
(r'^login/$', 'jumpserver.views.login'),

@ -6,7 +6,9 @@ import json
from django.db.models import Count
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from juser.models import User
@ -36,8 +38,6 @@ def index(request):
path1, path2 = u'仪表盘', 'Dashboard'
dic = {}
li_date, li_str = getDaysByNum(7)
# li_str = json.dumps(li_str)
# print li_str, type(li_str)
today = datetime.datetime.now().day
from_week = datetime.datetime.now() - datetime.timedelta(days=7)
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()
li.append(times)
dic[username] = li
print dic
users = User.objects.all()
hosts = Asset.objects.all()
online_host = Log.objects.filter(is_finished=0)
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):
@ -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'}
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
for group in j_group[0].split():
print group.strip()
c = BisGroup.objects.get(name=group.strip())
groups.append(c)
j_type = login_types[j_type]
print j_type
j_idc = IDC.objects.get(name=j_idc)
print j_idc
print
a = Asset.objects.get(id=j_id)
if j_type == 'M':
a.ip = j_ip

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

Loading…
Cancel
Save