赞
踩
- #导包
- from flask import Flask
- #相当于把菜单整合到平台中
- app=Flask(__name__,template_folder="myfolder")
- #调用主程序
- if __name__=="__main__":
- #相当于app理解成外卖小哥,代替本人去购餐送餐
- app.run()
- #导包
- from flask import Flask
- #相当于把菜单整合到平台中
- app=Flask(__name__,template_folder="myfolder")
- #理解成点餐,点餐必须有一地址,还有一个功能,功能里面必须有返回
- #下面的功能表示在页面显示Hello World,必须访问是/hello才可以
- #显示文字
- @app.route("/hello")
- def hello():
- return "Hello World!"
- #调用主程序
- if __name__=="__main__":
- #相当于app理解成外卖小哥,代替本人
- app.run()
- from flask import Flask,render_template
- #相当于把菜单整合到平台中,整合时指定网页的模板位置,携带参数template_folder
- app=Flask(__name__,template_folder="myfolder")
- #显示页面,需要使用render_template
- @app.route("/index")
- def myindex():
- return render_template("index.html")
- if __name__=="__main__":
- #相当于app理解成外卖小哥,代替本人去购餐送餐
- app.run()
- from flask import Flask,render_template
- #导入json模块
- import json
- #相当于把菜单整合到平台中,整合时指定网页的模板位置,携带参数template_folder
- app=Flask(__name__)
- #返回json数据,企业常用
- @app.route("/json")
- def myjson():
- a=a={"书名":"三国演义","作者":"罗贯中"}
- #dumps把json数据转成字符串
- return json.dumps(a,ensure_ascii=False)
- if __name__=="__main__":
- #相当于app理解成外卖小哥,代替本人去购餐送餐
- app.run()
./hive --service metastore
./hiveserver2
./beeline
!connect “jdbc:hive2://192.168.110.156:10000”
- <property>
- <name>hadoop.proxyuser.root.hosts</name>
- <value>*</value>
- </property>
- <property>
- <name>hadoop.proxyuser.root.groups</name>
- <value>*</value>
- </property>
0: jdbc:hive2://192.168.110.156:10000>
pip3 install impyla
- #连接hive2的服务器
- conn=connect(host="192.168.110.156",port=10000,user="root",password="admin",auth_mechanism="PLAIN")
- #连接后,获取游标,标志指示数据库的当前记录
- cursor=conn.cursor()
- #游标帮助我们执持HQL语句
- cursor.execute("select hour(sysdate),max(cpu_us) from system group by hour(sysdate)")
- #查询的结果在cursor.fetchall方法中
- results=cursor.fetchall()
- #构造json数据
- a_json={"result":results,"status":200}
- #返回前端json数据集
- return json.dumps(a_json,ensure_ascii=False)
- @app.route("/link")
- def link():
- try:
- #连接hive2的服务器
- conn=connect(host="192.168.110.156",port=10000,user="root",password="admin",auth_mechanism="PLAIN")
- #连接后,获取游标,标志指示数据库的当前记录
- cursor=conn.cursor()
- #游标帮助我们执持HQL语句
- cursor.execute("select hour(sysdate),max(cpu_us) from system group by hour(sysdate)")
- #查询的结果在cursor.fetchall方法中
- results=cursor.fetchall()
- a_json={"result":results,"status":200}
- print(a_json)
- return json.dumps(a_json,ensure_ascii=False)
- except:
- return json.dumps({"result":"网络连接错误","status":404},ensure_ascii=False)

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
var chartDom=document.getElementById(“mydiv1”)
myChart=echars.init(chartDom)
- option = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: 50,
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- myChart.setOption(option)

- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.3.3/echarts.js"></script>
- </head>
- <body>
- <script>
- var chartDom = document.getElementById('mydiv1');
- var myChart = echarts.init(chartDom);
- var option;
-
- option = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: 50,
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- myChart.setOption(option)
- </script>
- </body>

- get方式的ajax使用格式如下。
- $.get(“地址”,function(res){
- 请求成功后的内容
- })
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.3.3/echarts.js"></script>
- </head>
- <body>
- <h1>20点cpu的峰值</h1>
- <div style="width:400px;height:400px" id="mydiv1"></div>
- <script>
- var chartDom = document.getElementById('mydiv1');
- var myChart = echarts.init(chartDom);
- var option;
- //由于成功以后改value值,ajax请求成功后改变表盘的值,数据采用GET方式
- $.get("/link",function(res){
- //把option放在成功里,表示成功后加载数据
- //前端打印console.log
- console.log(res[0])
- //通过结果res[0]是一个"{",表示res是一个字符串
- //前端把res转换成json
- res=JSON.parse(res)
- //由于res.result是一个列表,列表第一个元素是由两个元素组成的列表,两个元素中第二个元素是20点的cpu峰值
- console.log(res.result[0][1])
- option = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: res.result[0][1],
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- //把option给图表
- myChart.setOption(option);
- })
-
- //myChart.setOption(option);
- </script>
- </body>
- </html>

- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.3.3/echarts.js"></script>
- </head>
- <body>
- <h1>20点cpu的峰值</h1>
- <div style="width:400px;height:400px" id="mydiv1"></div>
- <h1>21点cpu的峰值</h1>
- <div style="width:400px;height:400px" id="mydiv2"></div>
- <h1>22点cpu的峰值</h1>
- <div style="width:400px;height:400px" id="mydiv3"></div>
- <h1>23点cpu的峰值</h1>
- <div style="width:400px;height:400px" id="mydiv4"></div>
- <script>
- var chartDom = document.getElementById('mydiv1');
- var chartDom1 = document.getElementById('mydiv2');
- var chartDom2 = document.getElementById('mydiv3');
- var chartDom3 = document.getElementById('mydiv4');
- var myChart = echarts.init(chartDom);
- var myChart1= echarts.init(chartDom1);
- var myChart2= echarts.init(chartDom2);
- var myChart3= echarts.init(chartDom3);
- //由于成功以后改value值,ajax请求成功后改变表盘的值,数据采用GET方式
- $.get("/link",function(res){
- //把option放在成功里,表示成功后加载数据
- //前端打印console.log
- console.log(res[0])
- //通过结果res[0]是一个"{",表示res是一个字符串
- //前端把res转换成json
- res=JSON.parse(res)
- //由于res.result是一个列表,列表第一个元素是由两个元素组成的列表,两个元素中第二个元素是20点的cpu峰值
- console.log(res.result[0][1])
- option = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: res.result[0][1],
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- //复制option ,修改变量名option1
- option1 = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: res.result[1][1],
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- //复制option ,修改变量名option2
- option2 = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: res.result[2][1],
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- //复制option ,修改变量名option3
- option3 = {
- tooltip: {
- formatter: '{a} <br/>{b} : {c}%'
- },
- series: [
- {
- name: 'Pressure',
- type: 'gauge',
- progress: {
- show: true
- },
- detail: {
- valueAnimation: true,
- formatter: '{value}'
- },
- data: [
- {
- value: res.result[3][1],
- name: 'SCORE'
- }
- ]
- }
- ]
- };
- //把option给图表
- myChart.setOption(option);
- myChart1.setOption(option1);
- myChart2.setOption(option2);
- myChart3.setOption(option3);
- })
-
- //myChart.setOption(option);
- </script>
- </body>
- </html>

- from flask import Flask,render_template
- #导入json模入
- import json
- #导入impyla中的dbapi
- from impala.dbapi import connect
- #相当于把菜单整合到平台中
- app=Flask(__name__,template_folder="myfolder")
- #定义根路径,专门访问myweb.html
- @app.route("/")
- def index():
- return render_template("myweb.html")
- #定义一个连接hive的接口地址
- @app.route("/link")
- def link():
- try:
- #连接hive2的服务器
- conn=connect(host="192.168.110.156",port=10000,user="root",password="admin",auth_mechanism="PLAIN")
- #连接后,获取游标,标志指示数据库的当前记录
- cursor=conn.cursor()
- #游标帮助我们执持HQL语句
- cursor.execute("select hour(sysdate),max(cpu_us) from system group by hour(sysdate)")
- #查询的结果在cursor.fetchall方法中
- results=cursor.fetchall()
- a_json={"result":results,"status":200}
- print(a_json)
- return json.dumps(a_json,ensure_ascii=False)
- except:
- return json.dumps({"result":"网络连接错误","status":404},ensure_ascii=False)
-
- if __name__=="__main__":
- #相当于app理解成外卖小哥,代替本人去购餐送餐
- app.run()

https://github.com/wawacode/system_info_bigdata_analyse
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。