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