#27 статистика сетевой нагрузки
This commit is contained in:
parent
c2839eaf46
commit
c807525ec5
3 changed files with 35 additions and 22 deletions
|
@ -9,14 +9,17 @@
|
|||
$.each( data.network, function( key, val ) {
|
||||
items.push({
|
||||
x: new Date(val.year, val.month, val.day, val.hour, val.minute),
|
||||
y: val.read_bytes
|
||||
y: val.read_bytes_diff
|
||||
});
|
||||
});
|
||||
$("#chartContainer").CanvasJSChart({
|
||||
axisY:{
|
||||
title: "Трафик за сутки (Мб)"
|
||||
},
|
||||
data: [
|
||||
{
|
||||
toolTipContent: "{y} мбайт",
|
||||
type: "line",
|
||||
type: "stepLine",
|
||||
markerSize: 5,
|
||||
color: "#F08080",
|
||||
dataPoints: items
|
||||
|
@ -35,7 +38,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="chartContainer" style="height: 300px; width: 100%;">
|
||||
<div class="large-12 columns">
|
||||
<h4>Сетевой трафик</h4>
|
||||
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -317,6 +317,28 @@ def stats(vm_id):
|
|||
vm_details=vm_details)
|
||||
|
||||
|
||||
def calc_diff_list(data_list):
|
||||
"""
|
||||
:param data_list:
|
||||
:return:
|
||||
"""
|
||||
# массив с результатами вычисления
|
||||
diff = list()
|
||||
# добавля
|
||||
# diff.append(data_list[0])
|
||||
for cur, prev in zip(data_list, data_list[1:]):
|
||||
# print prev, cur
|
||||
a = cur['read_bytes'] if cur['read_bytes'] else 0
|
||||
b = prev['read_bytes'] if prev['read_bytes'] else 0
|
||||
|
||||
calc = int(b) - int(a)
|
||||
# diff.append(calc if calc > 0 else calc * -1)
|
||||
cur['read_bytes_diff'] = (calc if calc > 0 else calc * -1)
|
||||
diff.append(cur)
|
||||
# diff.__delitem__(0)
|
||||
return diff
|
||||
|
||||
|
||||
@viewVMs.route('/stats/<uuid:vm_id>.json')
|
||||
@requires_login
|
||||
def stats_json(vm_id):
|
||||
|
@ -325,33 +347,19 @@ def stats_json(vm_id):
|
|||
if not ControllerVMS(session['user_id']).exists(vm_id):
|
||||
return jsonify(status=1, message='instance not exists')
|
||||
|
||||
cnt = 0
|
||||
l = 0
|
||||
# stats_items = list()
|
||||
statistics = list()
|
||||
for s in SWSStatisticsClient().get_vm(vm_id).get('items'):
|
||||
reported = dateutil.parser.parse(s.get('time'))
|
||||
read_bytes = int(s.get('stats', {}).get('network', {}).get('read_bytes', 0))
|
||||
n = read_bytes
|
||||
# stats_items.append(read_bytes)
|
||||
|
||||
# if l - int(s.get('stats', {}).get('network', {}).get('read_bytes', 0)) < 0:
|
||||
# n = l
|
||||
# else:
|
||||
# n = l - int(s.get('stats', {}).get('network', {}).get('read_bytes', 0))
|
||||
#
|
||||
# l = int(s.get('stats', {}).get('network', {}).get('read_bytes', 0))
|
||||
# print reported, read_bytes, l, n
|
||||
|
||||
# if cnt == 0:
|
||||
# cnt += 1
|
||||
# continue
|
||||
statistics.append(dict(
|
||||
year=reported.strftime('%Y'),
|
||||
month=reported.strftime('%m'),
|
||||
day=reported.strftime('%d'),
|
||||
hour=reported.strftime('%H'),
|
||||
minute=reported.strftime('%M'),
|
||||
read_bytes=n,
|
||||
# write_bytes=s['stats']['network']['write_bytes'],
|
||||
read_bytes=read_bytes / 1024 / 1024,
|
||||
))
|
||||
|
||||
return jsonify(network=statistics, status=0)
|
||||
return jsonify(network=calc_diff_list(statistics), status=0)
|
||||
|
|
|
@ -2,7 +2,7 @@ import requests
|
|||
|
||||
|
||||
class SWSStatisticsClient(object):
|
||||
def get_vm(self, vm_id, limit=25):
|
||||
def get_vm(self, vm_id, limit=96):
|
||||
r = requests.get('http://localhost:8089/stats/v1/compute/vms/%s' % vm_id, params={'limit': limit})
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
|
|
Loading…
Add table
Reference in a new issue