containter stats
This commit is contained in:
parent
f26e36daf1
commit
7be5a8fa95
3 changed files with 63 additions and 17 deletions
15
app/cloud/controllers/servers/server.py
Normal file
15
app/cloud/controllers/servers/server.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
# import datetime
|
||||
from app import models
|
||||
|
||||
|
||||
class ControllerServerStatistics:
|
||||
def write(self, container_id, cpu, memory, net_tx, net_rx, net_total):
|
||||
models.ContainersStatistics.create(
|
||||
container=str(container_id),
|
||||
cpu=cpu,
|
||||
memory=memory,
|
||||
net_tx=net_tx,
|
||||
net_rx=net_rx,
|
||||
net_total=net_total
|
||||
)
|
||||
return True
|
|
@ -1,14 +1,12 @@
|
|||
# coding: utf-8
|
||||
|
||||
import json
|
||||
# import uuid
|
||||
# from flask import Response
|
||||
from flask import request
|
||||
from flask import Blueprint
|
||||
from flask import jsonify
|
||||
# from app import models
|
||||
from app.cloud.controllers.tasks.server import ControllerTasksServer
|
||||
# from .controllers import ControllerRulesStatistics
|
||||
from app.cloud.controllers.servers.server import ControllerServerStatistics
|
||||
from app.cloud.controllers.containers.server import ControllerContainersServer
|
||||
|
||||
viewServerAPI = Blueprint('server_api', __name__, url_prefix='/server_api')
|
||||
|
||||
|
@ -63,16 +61,18 @@ def task_status_update():
|
|||
|
||||
@viewServerAPI.route('/report/container_status', methods=['POST'])
|
||||
def report_container_status():
|
||||
node_id = request.args.get('node_id')
|
||||
node_secret = request.args.get('node_secret')
|
||||
server_api = ControllerTasksServer(node_id, node_secret)
|
||||
node_id = request.form['node_id']
|
||||
node_secret = request.form['node_secret']
|
||||
|
||||
# print request.form['node_id']
|
||||
# auth request
|
||||
if not server_api.auth():
|
||||
if not ControllerTasksServer(node_id, node_secret).auth():
|
||||
# status: 403 - access denied
|
||||
return jsonify({'status': 403})
|
||||
|
||||
"""
|
||||
{
|
||||
"container_id": "16459f60-a1ee-11e5-9108-28d244e159e9",
|
||||
"cpu_use": 644394623336,
|
||||
"memory_use": 614473728,
|
||||
"link": "vethB2RLMU"
|
||||
|
@ -81,6 +81,37 @@ def report_container_status():
|
|||
"total_bytes": 1097776429
|
||||
}
|
||||
"""
|
||||
status = json.loads(request.form['status'])
|
||||
statistics = json.loads(request.form['status'])
|
||||
# print statistics
|
||||
container_id = statistics['container_id']
|
||||
|
||||
if 'cpu_use' not in statistics:
|
||||
return False
|
||||
if 'memory_use' not in statistics:
|
||||
return False
|
||||
if 'tx_bytes' not in statistics:
|
||||
return False
|
||||
if 'rx_bytes' not in statistics:
|
||||
return False
|
||||
if 'total_bytes' not in statistics:
|
||||
return False
|
||||
|
||||
# print container_id, ,
|
||||
|
||||
if ControllerContainersServer().exists(container_id):
|
||||
ControllerServerStatistics().write(
|
||||
container_id,
|
||||
statistics['cpu_use'],
|
||||
statistics['memory_use'],
|
||||
int(statistics['tx_bytes']),
|
||||
int(statistics['rx_bytes']),
|
||||
int(statistics['total_bytes'])
|
||||
|
||||
# int(statistics['rx_bytes']) / 1024 / 1024,
|
||||
# int(statistics['total_bytes']) / 1024 / 1024
|
||||
)
|
||||
# import datetime
|
||||
# print container_id
|
||||
# print ControllerContainersServer().exists(container_id)
|
||||
# print datetime.datetime.now
|
||||
return jsonify({})
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
import datetime
|
||||
from peewee import PostgresqlDatabase
|
||||
from peewee import Model, UUIDField, CharField, ForeignKeyField, IntegerField, DateTimeField, TextField, FloatField
|
||||
|
||||
from peewee import Model, UUIDField, CharField, ForeignKeyField, IntegerField
|
||||
from peewee import DateTimeField, TextField, FloatField, BigIntegerField
|
||||
from app.settings import settings
|
||||
|
||||
# connect to database
|
||||
|
@ -133,12 +133,12 @@ class Containers(PgSQLModel):
|
|||
|
||||
class ContainersStatistics(PgSQLModel):
|
||||
container = ForeignKeyField(Containers)
|
||||
timestamp = DateTimeField()
|
||||
cpu = IntegerField(default=0)
|
||||
memory = IntegerField(default=0)
|
||||
net_tx = IntegerField(default=0)
|
||||
net_rx = IntegerField(default=0)
|
||||
net_total = IntegerField(default=0)
|
||||
created = DateTimeField(default=datetime.datetime.now)
|
||||
cpu = BigIntegerField(default=0, null=False)
|
||||
memory = BigIntegerField(default=0, null=False)
|
||||
net_tx = BigIntegerField(default=0, null=False)
|
||||
net_rx = BigIntegerField(default=0, null=False)
|
||||
net_total = BigIntegerField(default=0, null=False)
|
||||
|
||||
|
||||
class Tasks(PgSQLModel):
|
||||
|
|
Loading…
Add table
Reference in a new issue