|
|
@ -16,20 +16,21 @@ app.secret_key = 'SecretKey' # 设置Secret Key
|
|
|
|
def index_404():
|
|
|
|
def index_404():
|
|
|
|
return render_template('page/404.html',)
|
|
|
|
return render_template('page/404.html',)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##注销页面
|
|
|
|
@app.route("/logout") #host:post/logout:
|
|
|
|
@app.route("/logout") #host:post/logout:
|
|
|
|
def logout():
|
|
|
|
def logout():
|
|
|
|
session.clear() # 清除会话数据
|
|
|
|
session.clear() # 清除会话数据
|
|
|
|
# session['logged_out'] = True
|
|
|
|
# session['logged_out'] = True
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
|
|
|
##注册页面
|
|
|
|
@app.route("/register")
|
|
|
|
@app.route("/register")
|
|
|
|
def register():
|
|
|
|
def register():
|
|
|
|
return render_template('page/register.html',)
|
|
|
|
return render_template('page/register.html',)
|
|
|
|
|
|
|
|
##登录页面
|
|
|
|
@app.route("/login")
|
|
|
|
@app.route("/login")
|
|
|
|
def login():
|
|
|
|
def login():
|
|
|
|
return render_template('page/login.html',)
|
|
|
|
return render_template('page/login.html',)
|
|
|
|
|
|
|
|
##登录接口,通过Ajax实现异步交互
|
|
|
|
@app.route("/api_login", methods=['GET'])
|
|
|
|
@app.route("/api_login", methods=['GET'])
|
|
|
|
def api_login():
|
|
|
|
def api_login():
|
|
|
|
username =request.args.get('username')
|
|
|
|
username =request.args.get('username')
|
|
|
@ -94,14 +95,14 @@ def logins():
|
|
|
|
@app.route("/index_echarts")
|
|
|
|
@app.route("/index_echarts")
|
|
|
|
def index_echarts():
|
|
|
|
def index_echarts():
|
|
|
|
return render_template('index.html',)
|
|
|
|
return render_template('index.html',)
|
|
|
|
|
|
|
|
##告警
|
|
|
|
@app.route("/warings")
|
|
|
|
@app.route("/warings")
|
|
|
|
def warings():
|
|
|
|
def warings():
|
|
|
|
if session['quanxian'] == 1:
|
|
|
|
if session['quanxian'] == 1:
|
|
|
|
return render_template('page/warings.html')
|
|
|
|
return render_template('page/warings.html')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render_template('page/404.html')
|
|
|
|
return render_template('page/404.html')
|
|
|
|
|
|
|
|
##管理员权限
|
|
|
|
@app.route("/admin")
|
|
|
|
@app.route("/admin")
|
|
|
|
def admin():
|
|
|
|
def admin():
|
|
|
|
username = session['username']
|
|
|
|
username = session['username']
|
|
|
@ -113,7 +114,7 @@ def admin():
|
|
|
|
@app.route("/log")
|
|
|
|
@app.route("/log")
|
|
|
|
def log():
|
|
|
|
def log():
|
|
|
|
return render_template('page/table.html',)
|
|
|
|
return render_template('page/table.html',)
|
|
|
|
|
|
|
|
##用户权限
|
|
|
|
@app.route("/user")
|
|
|
|
@app.route("/user")
|
|
|
|
def user():
|
|
|
|
def user():
|
|
|
|
if session['quanxian'] ==1:
|
|
|
|
if session['quanxian'] ==1:
|
|
|
@ -220,9 +221,9 @@ def api_log():
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/api_warings", methods=['GET'])
|
|
|
|
@app.route("/api_warings", methods=['GET'])
|
|
|
|
def api_warings():
|
|
|
|
def api_warings():
|
|
|
|
# 假设每页显示10条记录
|
|
|
|
# 设置页面数据量
|
|
|
|
LIMIT_PER_PAGE =int(request.args.get('limit'))
|
|
|
|
LIMIT_PER_PAGE =int(request.args.get('limit'))
|
|
|
|
# 假设我们要查询第3页的数据
|
|
|
|
# 查询页面数据
|
|
|
|
PAGE = int(request.args.get('page'))
|
|
|
|
PAGE = int(request.args.get('page'))
|
|
|
|
# 计算 OFFSET
|
|
|
|
# 计算 OFFSET
|
|
|
|
OFFSET = (PAGE - 1) * LIMIT_PER_PAGE
|
|
|
|
OFFSET = (PAGE - 1) * LIMIT_PER_PAGE
|
|
|
@ -353,7 +354,6 @@ def api_msg():
|
|
|
|
INSERT INTO my_table(CPU, neicun, disk, shang, xia, jiqihao)
|
|
|
|
INSERT INTO my_table(CPU, neicun, disk, shang, xia, jiqihao)
|
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# 替换 %s 为你想要插入的数据
|
|
|
|
|
|
|
|
data = (int(cpu), memory_percent, usage_percent,shang, xia, '业务2号机')
|
|
|
|
data = (int(cpu), memory_percent, usage_percent,shang, xia, '业务2号机')
|
|
|
|
cursor.execute(sql, data)
|
|
|
|
cursor.execute(sql, data)
|
|
|
|
# 执行 SQL 语句
|
|
|
|
# 执行 SQL 语句
|
|
|
@ -365,7 +365,6 @@ def api_msg():
|
|
|
|
# 替换 %s 为你想要插入的数据
|
|
|
|
# 替换 %s 为你想要插入的数据
|
|
|
|
data = (int(cpu), memory_percent, usage_percent, shang, xia, '业务2号机','CPU负载过高')
|
|
|
|
data = (int(cpu), memory_percent, usage_percent, shang, xia, '业务2号机','CPU负载过高')
|
|
|
|
cursor.execute(sql, data)
|
|
|
|
cursor.execute(sql, data)
|
|
|
|
# 提交事务
|
|
|
|
|
|
|
|
db.commit()
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
|
|
|
|
print("数据插入成功!")
|
|
|
|
print("数据插入成功!")
|
|
|
@ -386,7 +385,7 @@ def api_msg():
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/delete_username", methods=['GET'])
|
|
|
|
@app.route("/delete_username", methods=['GET'])
|
|
|
|
def delete_username():
|
|
|
|
def delete_username():
|
|
|
|
# 假设每页显示10条记录
|
|
|
|
# 假设每页显示10条记录,通过设置最大单词读取数,优化数据库性能
|
|
|
|
id =request.args.get('id')
|
|
|
|
id =request.args.get('id')
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -462,5 +461,6 @@ def get_disk_usage(disk_path='/'):
|
|
|
|
usage_percent = (used / total) * 100
|
|
|
|
usage_percent = (used / total) * 100
|
|
|
|
return used, free,usage_percent
|
|
|
|
return used, free,usage_percent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##设置URL
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host='127.0.0.1', port='7000')
|
|
|
|
app.run(debug=True, host='127.0.0.1', port='7000')
|
|
|
|