From faf1a4856ffb94e471e34fa88f0f1c90cf1146ec Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Tue, 29 Nov 2016 11:51:27 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/Aries/src/App.less | 1 + .../src/functions/Overview/OverviewConf.js | 159 ++++++++++++--- .../Aries/src/functions/Overview/index.jsx | 189 +++++++++++++----- .../Aries/src/functions/Overview/index.less | 73 ++++++- 4 files changed, 337 insertions(+), 85 deletions(-) diff --git a/package/Aries/src/App.less b/package/Aries/src/App.less index fcb9bb3..2f6f2d2 100644 --- a/package/Aries/src/App.less +++ b/package/Aries/src/App.less @@ -41,6 +41,7 @@ html, body, #app { } > .content { padding: 20px; + margin-bottom: 20px; > div { animation: fade .25s cubic-bezier(.455,.03,.515,.955); } diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index 7a9a84d..b71ff86 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -1,46 +1,157 @@ import conf from 'public/Conf/Conf' const OverviewConf={ - //概览基础数据 + //概览基础数据定义 overviewData:[{ - title:"HDFS", + title: "HDFS", + id: "hdfs", content: [ - {label:"使用百分比:",value:"hdfs_disk_used"}, - {label:"分享个数:",value:"hdfs_shares"}, - {label:"datanode健康状态:",value:"hdfs_datanodes"} + { + name: "hdfs使用率", + stateName: "hdfs_disk_used", + value: { + used: "${used}", + nonUsed: "${nonUsed}" + }, + type: "pie", + desc: "已使用: ${used} ${unit} \ + 剩余: ${nonUsed} ${unit}" + }, + { + name: "hdfs分享个数", + value: "${hdfs_shares}", + stateName: "hdfs_shares", + desc: "${hdfs_shares} 个目录被分享." + }, + { + name: "dn存活状态", + stateName: "hdfs_datanodes", + value: "${lives} / ${total}", + desc: "健康: ${lives}. 异常: ${dead}" + } ] },{ - title:"CODIS", + title: "CODIS", + id: "codis", content: [ - {label:"codis集群总数:",value:"codis_count"}, - {label:"codis内存使用率:",value:"codis_memory_used"}, + { + name: "codis集群总数", + stateName: "codis_count", + value: "${lives} / ${total}", + desc: "正常: ${lives}. \ + 异常: ${dead}" + }, + { + name: "Codis 内存使用率", + stateName: "codis_memory_used", + value: { + used: "${used}", + nonUsed: "${nonUsed}" + }, + type: "pie", + desc: "已使用: ${used} ${unit}, \ + 剩余: ${nonUsed} ${unit}" + }, ] },{ - title:"K8SP", + title: "K8SP", + id: "k8s", content: [ - {label:"pod个数:",value:"k8sp_pod_count"}, - {label:"rc个数:",value:"k8sp_rc_count"}, - {label:"service状态:",value:"k8sp_service_status_count"}, - {label:"node个数:",value:"k8sp_nodes_count"} + { + name: "pod个数", + stateName: "k8sp_pod_count", + value: "${lives} / ${total}", + desc: "正常: ${lives}. 异常: ${dead}" + }, + { + name: "rc个数", + stateName: "k8sp_rc_count", + value: "${lives} / ${total}", + desc: "正常: ${lives}. 异常: ${dead}" + }, + { + name: "service状态", + stateName: "k8sp_service_status_count", + value: "${k8sp_service_status_count}", + desc: "${k8sp_service_status_count} 状态." + }, + { + name: "node个数", + stateName: "k8sp_nodes_count", + value: "${lives} / ${total}", + desc: "正常: ${lives} 异常: ${dead}" + } ] },{ - title:"BDMS", + title: "BDMS", + id: "bdms", content: [ - {label:"今日正在运行的任务:",value:"bdms_running_count"}, - {label:"今日执行成功的任务:",value:"bdms_success_count"}, - {label:"今日运行失败的任务:",value:"bdms_failed_count"}, - {label:"今日总任务:",value:"bdms_task_count"} + { + type: "pieSubarea", + name: "BDMS任务运行图:", + stateName: "bdms_task_count", + desc: " 待运行: ${waiting} 个,\n \ + 运行中: ${running} 个,\n \ + 运行成功: ${success} 个,\n \ + 运行失败: ${failed} 个,\n \ + 总任务: ${total} 个", + value: [ + { + name: "待运行", + value: "${waiting}", + }, + { + name: "运行中", + value: "${running}", + }, + { + name: "执行成功", + value: "${success}", + }, + { + name: "运行失败", + value: "${failed}", + }, + /*{ + name: "今日总任务", + value: "${total}", + }*/ + ] + + } ] },{ - title:"OPENSTACK", + title: "OPENSTACK", + id: "openstack", content: [ - {label:"虚拟机:",value:"openstack_vm_count"}, - {label:"镜像个数:",value:"openstack_image_count"}, - {label:"云硬盘个数:",value:"openstack_disk_count"} + { + name: "虚拟机状态", + stateName: "openstack_vm_count", + value: "${total}", + desc: "正常: ${lives} 异常: ${dead}.", + }, + { + name: "镜像个数", + stateName: "openstack_image_count", + value: "${openstack_image_count}", + desc: "共保存了 ${openstack_image_count} 个镜像." + }, + { + name: "云硬盘个数", + stateName: "openstack_disk_count", + value: "${openstack_disk_count}", + desc: "共分配了 ${openstack_disk_count} 个磁盘." + } ] },{ - title:"用户", + title: "用户", + id: "user", content: [ - {label:"当前space成员个数:",value:"userAuth_member_count"}, + { + name: "成员个数", + stateName: "userAuth_member_count", + value: "${userAuth_member_count}", + desc: "当前空间共有 ${userAuth_member_count} 人." + }, ] }], //从location中获取cur_space diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 6a13d2d..4b777e9 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -1,71 +1,159 @@ import React from 'react' -import { Checkbox } from 'bfd/Checkbox' import './index.less' import { Row, Col } from 'bfd/Layout' import auth from 'public/auth' -import OverviewConf from './OverviewConf' import Fetch from 'bfd/Fetch' +import echarts from 'echarts' +import OverviewConf from './OverviewConf' +import EchartsUtil from 'public/Template/Echarts/EchartsUtil' +import common from 'public/Template/echarts/common' export default React.createClass({ getInitialState:function(){ return { random: 0, - hdfs_disk_used: 0, //HDFS使用百分比 + //hdfs_disk_used: 0, //HDFS使用百分比 + hdfs_disk_used: { + used: 100, + nonUsed: 50, + unit: "TB", + total: 0, + }, hdfs_shares: 0, //HDFS分享文件的个数 - hdfs_datanodes: "0/0", //HDFS datanode健康状态(99/100) - codis_count: "0/0", //Codis 集群总个数(10/11,正常集群/总集群) - codis_memory_used: 0, //Codis 内存使用率50% - k8sp_pod_count: "0/0", //Pod个数(9/10) - k8sp_rc_count: "0/0", //rc(9/10) + //hdfs_datanodes: "0/0", //HDFS datanode健康状态(99/100) + hdfs_datanodes: { + lives: 0, + dead: 0, + total: 0 + }, + //codis_count: "0/0", //Codis 集群总个数(10/11,正常集群/总集群) + codis_count: { + lives: 0, + dead: 0, + total: 0, + }, + //codis_memory_used: 0, //Codis 内存使用率50% + codis_memory_used:{ + used: 100, + nonUsed: 50, + unit: "GB" + }, + //k8sp_pod_count: "0/0", //Pod个数(9/10) + k8sp_pod_count: { + lives: 0, + dead: 0, + total: 0 + }, + //k8sp_rc_count: "0/0", //rc(9/10) + k8sp_rc_count: { + lives: 0, + dead: 0, + total: 0 + }, k8sp_service_status_count: 0, //Service状态 - k8sp_nodes_count: 0, //Node个数 - bdms_running_count: 0, //今日正在运行的任务 - bdms_success_count: 0, //今日执行成功的任务 - bdms_failed_count: 0, //今日运行失败的任务 - bdms_task_count: 0, //今日总任务 - openstack_vm_count: "0/0", //虚拟机(9/10) + //k8sp_nodes_count: 0, //Node个数 + k8sp_nodes_count: { + lives: 0, + dead: 0, + total: 0 + }, + bdms_task_count: { + running: 0, //运行中 + waiting: 0, //等待中 + success: 0, //成功 + failed: 0, //失败 + total: 0 //总数 + }, + //openstack_vm_count: "0/0", //虚拟机(9/10) + openstack_vm_count:{ + lives: 0, //正常 + dead: 0, //异常 + total: 0, //总数 + }, openstack_image_count: 0, //镜像个数 openstack_disk_count: 0, //云硬盘个数 userAuth_member_count: 0, //当前space成员个数 }; }, - index:function(){ - let cur_space = auth.user.cur_space; - let type = auth.user.type; - if(cur_space== "" && type < 1){ - return
您还不属于任何space.请联系space管理员进行添加.
- } - if(cur_space== "" && type >0){ - return
您还没有创建任何space.请先创建space
- } - //展示 + echartsMapping:{}, + index(){ let data = OverviewConf.overviewData; - let overviewBody = data.map((component,index)=>{ - let title = component.title; - let contentData = component.content; - let contentComponent = contentData.map((d,i)=>{ - let value = d.value; - return - {d.label} - {this.state[value]} - - }); - //全部组件的数据 - return -
-
{title}
-
- {contentComponent} + let overviewBody = data.map(function(item,index){ + //渲染图表div. + let cid = item.id; + let content = item.content.map(function(item,index){ + let id = `echarts_${cid}_${index}` + let echart_div = ""; + item = common.tempPreHandler(item,this.state[item.stateName]); + switch(item.type){ + case "pie": + echart_div =
; + case "pieSubarea": + echart_div =
+ break; + default: + echart_div =
+ {item.value} +
+ } + //渲染描述 + let echart_desc =
{item.desc}
+ return
+
+ {item.name}
+ {echart_div} + {echart_desc}
- - - }); - return {overviewBody} + },this); + return content + },this); + return
{overviewBody}
}, - refresh(){ - let random = parseInt(100000*Math.random()) - this.setState({random:random}); + echartsData(type,item){ + //获取echart数据 + let data = item.value; + switch(type.toLocaleLowerCase()){ + /* + case "gauge": + data = {name: "", data: [{value: this.state[value], name: ""}]}; + break; + case "pienumber": + data = {name:value, text:this.state[value]}; + break; + */ + case "pie": + break; + case "piesubarea": + //组合需要单独处理 + console.log(data); + break; + default: + console.log(`该类型图表暂不支持! type:${type}`); + break; + } + return data; + }, + componentDidMount: function () { + //从模版中取数据渲染 + let data = OverviewConf.overviewData; + data.map(function(item,index){ + //渲染图表div. + let title = item.title; + let cid = item.id; + let content = item.content.map(function(item,index){ + let id = `echarts_${cid}_${index}` + let type = item.type; + //根据不用的图表渲染不同的数据 + //let data = {name: "", data: [{value: 50, name: item.name}]}; + if( type != undefined ){ + let data = this.echartsData(type,item); + let option = EchartsUtil.renderOptionData(type,data); + this.echartsMapping[index] = echarts.init(document.getElementById(id)).setOption(option); + } + },this); + return content + },this); }, requestArgs:{ pageName : "Overview", @@ -149,18 +237,17 @@ export default React.createClass({ let openstack_url = this.getUrlData({ type: "OPENSTACK_OVERVIEW", spaceName: spaceName }); - - //根据space获取对应的指标信息 - let conent = this.index(); return (
- {conent} + {this.index()} + {/* + */}
) } diff --git a/package/Aries/src/functions/Overview/index.less b/package/Aries/src/functions/Overview/index.less index 0108c7b..752a392 100644 --- a/package/Aries/src/functions/Overview/index.less +++ b/package/Aries/src/functions/Overview/index.less @@ -1,14 +1,67 @@ .overview { - .common{ - min-height: 200px; - border: 1px solid #D4D4D4; - margin-top: 10px; - .title{ - border-bottom: 1px solid #D4D4D4; - padding: 5px 10px 0px; - } - .content{ - padding: 5px 10px 5px; + div.container-div{ + width: 185px; + height: 165px; + float: left; + position: relative; + min-height: 1px; + margin: 0 auto; + margin-right: 10px; + margin-bottom: 10px; + border: 1px solid #ddd; + &:hover{ + cursor: move; + .container-body{ + display: none; + } + .diagram-div{ + display: none; + } + .chart-hover{ + display: block; + //z-index: 100; + } + } + .diagram-div{ + width: 185px; + height: 130px; + } + + .container-head{ + padding: 8px 5px 5px 5px; + font-weight: bold; + text-align: left; + color: #000; + font-size: 15px; + } + + .container-body{ + font-size: 35px; + text-align: center; + color: #5ab400; + font-weight: bold; + padding-top: 30px; + } + + .chart-hover{ + /* + position: absolute; + top: 0; + left:0; + right: 0; + bottom: 0; + opacity: 0; + transition: 0.1s all ease-in-out; + */ + background-color: #fff; + display: none; + width: 100%; + padding: 8px 5px 5px 5px; + font-weight: bold; + text-align: center;; + color: #000; + font-size: 15px; + transition: 0.1s all ease-in-out; } } } From 24cc53d69e9f2b1e9c7c491afff46f00ac2437bd Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Tue, 29 Nov 2016 11:58:58 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Template/Echarts/EchartsUtil.js | 38 +++++++++ .../src/public/Template/Echarts/common.js | 64 +++++++++++++++ .../Aries/src/public/Template/Echarts/pie.js | 78 +++++++++++++++++++ .../src/public/Template/Echarts/pieSubarea.js | 45 +++++++++++ 4 files changed, 225 insertions(+) create mode 100644 package/Aries/src/public/Template/Echarts/EchartsUtil.js create mode 100644 package/Aries/src/public/Template/Echarts/common.js create mode 100644 package/Aries/src/public/Template/Echarts/pie.js create mode 100644 package/Aries/src/public/Template/Echarts/pieSubarea.js diff --git a/package/Aries/src/public/Template/Echarts/EchartsUtil.js b/package/Aries/src/public/Template/Echarts/EchartsUtil.js new file mode 100644 index 0000000..4b5412f --- /dev/null +++ b/package/Aries/src/public/Template/Echarts/EchartsUtil.js @@ -0,0 +1,38 @@ +import gauge from './gauge' +import pieNumber from './pieNumber' +import pieSubarea from './pieSubarea' +import pie from './pie' +/* + *echarts数据渲染工具类 + */ +const EchartsUtil = { + /* + * 渲染echarts中的数据. + * type: 图表类型. echartsType中的key集合 + * data: 模版中对应的值 + */ + renderOptionData(type,data){ + let tempData = ""; + switch(type.toLocaleLowerCase()){ + /* + case "gauge": + tempData = gauge.renderOption(data); + break; + case "pienumber": + tempData = pieNumber.renderOption(data); + break; + */ + case "pie": + tempData = pie.renderOption(data); + break; + case "piesubarea": + tempData = pieSubarea.renderOption(data); + break; + default: + console.log("不包含对应的echarts 模版数据: "+type); + } + return tempData; + }, +} + +export default EchartsUtil; diff --git a/package/Aries/src/public/Template/Echarts/common.js b/package/Aries/src/public/Template/Echarts/common.js new file mode 100644 index 0000000..a089e97 --- /dev/null +++ b/package/Aries/src/public/Template/Echarts/common.js @@ -0,0 +1,64 @@ +const common = { + /* + * 替换单个模版字符串 + * demo: + * params: + * temp: {id:1,name:{ n1:"${args.t1}", n2:{nn2:"${args.date.month}",nn3:"${args.date.day}"}}} + * args: {t1:1,date:{ month:2, day:3}} + * result: {id:1,name:{ n1:1, n2:{nn2:2,nn3:3}} + * + */ + tempVariReplace(jsonValue, args){ + let reg = /\${[\w|.]+}/g; + //只替换字符串模版 + let tempVari = typeof(jsonValue) == "string" ? jsonValue.match(reg): null; + tempVari != null && tempVari.forEach((tempVariName,index)=>{ + debugger; + //模版变量变量名 + let regStr = `/\\${tempVariName}/g`; + let reg = eval(regStr); + //模版变量变量值 + let name = /\${([\w|.]+)}/.exec(tempVariName)[1]; + let names =name.split("."); + let tempVarValue = common.getObjectAttr(names,args); + jsonValue = jsonValue.replace(reg, JSON.stringify(tempVarValue)); + }) + try{ + jsonValue = JSON.parse(jsonValue); + }catch(err){ + console.log(`${jsonValue} is not object`); + } + return jsonValue; + }, + tempPreHandler(temp,args){ + if(typeof(temp) != "object"){ + //替换字符串中的变量 + temp = common.tempVariReplace(temp, args); + return temp; + } + //遍历args对象,找到模版变量,然后直接替换模版变量 "${item}" + Object.keys(temp).forEach(function(item, index){ + let jsonValue = temp[item]; + if(typeof(jsonValue) == "object"){ + temp[item] = common.tempPreHandler(jsonValue,args); + }else{ + temp[item] = common.tempVariReplace(jsonValue,args); + return temp + } + }); + return temp; + }, + getObjectAttr(arr, obj){ + let value = obj; + //获取obj的属性对应的值,属性可以是多个层级 + if( typeof(obj) != "object"){ + return value; + } + arr.forEach((item,index)=>{ + value = value[item]; + }); + return value; + } +} + +export default common; diff --git a/package/Aries/src/public/Template/Echarts/pie.js b/package/Aries/src/public/Template/Echarts/pie.js new file mode 100644 index 0000000..fb3ce1d --- /dev/null +++ b/package/Aries/src/public/Template/Echarts/pie.js @@ -0,0 +1,78 @@ +import common from './common' +import echarts from 'echarts' +const pie = { + option: { + legend: { + orient: 'vertical', + left: 'left', + }, + series : [ + { + type: 'pie', + radius : ['50%', '80%'], + center: ['50%','50%'], + hoverAnimation:false, + label: { + normal: { + show: true, + formatter: function(params){return params.percent.toFixed(0)+"%"}, + } + }, + itemStyle: { + normal: { + borderColor: "#ddd", + borderWidth: 2, + color : + new echarts.graphic.RadialGradient(0.5, 0.5, 0.5, [{ + offset: 0.6, color: 'red' // 0% 处的颜色 + }, { + offset: 1, color: 'red' // 100% 处的颜色 + }], false + ) + + } + }, + data:[ + { + value:"${used}", + label: { + normal: { + position: "center", + textStyle: { + color: 'red', + fontSize: 25, + fontStyle: 'normal', + fontWeight: 'bold', + fontFamily: "Helvetica Neue" + + } + } + } + }, + { + value:"${nonUsed}", + tooltip: { + show: false + }, + itemStyle: { + normal: { + color: '#fff' + } + }, + } + ] + } + ] +}, + //渲染option的函数 + renderOption(data){ + //let tempOption = {id:1,name:{ n1:"${args.t1}", n2:{nn2:"${args.date.month}",nn3:"${args.date.day}"}}}; + //let args = {t1:1,date:{ month:2, day:3}} + //let option = common.tempPreHandler(tempOption,args); + let option = common.tempPreHandler(this.option,data); + console.log(option); + return option; + } +} + +export default pie; diff --git a/package/Aries/src/public/Template/Echarts/pieSubarea.js b/package/Aries/src/public/Template/Echarts/pieSubarea.js new file mode 100644 index 0000000..ead406c --- /dev/null +++ b/package/Aries/src/public/Template/Echarts/pieSubarea.js @@ -0,0 +1,45 @@ +//饼图分区模版数据 +import common from './common' +const pieSubarea = { + option: { + legend: { + orient: 'vertical', + x: 'left', + }, + hoverAnimation:false, + series: [{ + type: 'pie', + center: ['50%','50%'], + radius: ['50%', '80%'], + data: "${data}" + }] + }, + formtarData(data){ + return data.map((item,index)=>{ + return { + value: item.value, + name: item.name, + label: { + normal: { + show: false + } + }, + labelLine: { + normal: { + show: false + } + } + } + }); + }, + //渲染option的函数 + renderOption(data){ + data = this.formtarData(data); + console.log(data); + let option = common.tempPreHandler(this.option,{data:data}); + console.log(option); + return option; + } +} + +export default pieSubarea; From 1a573fbbf9e98d10f83a9fb7a6d9e8ee477be06d Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Tue, 29 Nov 2016 14:49:56 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/functions/Overview/OverviewConf.js | 51 +++++------ .../Aries/src/functions/Overview/index.jsx | 91 +++++-------------- .../public/Template/Echarts/EchartsUtil.js | 10 -- .../src/public/Template/Echarts/common.js | 61 ++++++++----- .../Aries/src/public/Template/Echarts/pie.js | 4 +- .../src/public/Template/Echarts/pieSubarea.js | 6 +- 6 files changed, 87 insertions(+), 136 deletions(-) diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index b71ff86..ba5667b 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -7,14 +7,15 @@ const OverviewConf={ content: [ { name: "hdfs使用率", - stateName: "hdfs_disk_used", + stateName: "hdfs_disk", value: { used: "${used}", nonUsed: "${nonUsed}" }, type: "pie", desc: "已使用: ${used} ${unit} \ - 剩余: ${nonUsed} ${unit}" + 剩余: ${nonUsed} ${unit} \ + 总共: ${total} ${unit}" }, { name: "hdfs分享个数", @@ -35,21 +36,22 @@ const OverviewConf={ content: [ { name: "codis集群总数", - stateName: "codis_count", + stateName: "codis_cluster", value: "${lives} / ${total}", desc: "正常: ${lives}. \ 异常: ${dead}" }, { name: "Codis 内存使用率", - stateName: "codis_memory_used", + stateName: "codis_memory", value: { used: "${used}", nonUsed: "${nonUsed}" }, type: "pie", desc: "已使用: ${used} ${unit}, \ - 剩余: ${nonUsed} ${unit}" + 剩余: ${nonUsed} ${unit} \ + 总共: ${total} ${unit}" }, ] },{ @@ -58,25 +60,25 @@ const OverviewConf={ content: [ { name: "pod个数", - stateName: "k8sp_pod_count", + stateName: "k8sp_pod", value: "${lives} / ${total}", desc: "正常: ${lives}. 异常: ${dead}" }, { name: "rc个数", - stateName: "k8sp_rc_count", + stateName: "k8sp_rc", value: "${lives} / ${total}", desc: "正常: ${lives}. 异常: ${dead}" }, { name: "service状态", - stateName: "k8sp_service_status_count", - value: "${k8sp_service_status_count}", - desc: "${k8sp_service_status_count} 状态." + stateName: "k8sp_service", + value: "${k8sp_service}", + desc: "${k8sp_service} 状态." }, { name: "node个数", - stateName: "k8sp_nodes_count", + stateName: "k8sp_nodes", value: "${lives} / ${total}", desc: "正常: ${lives} 异常: ${dead}" } @@ -88,7 +90,7 @@ const OverviewConf={ { type: "pieSubarea", name: "BDMS任务运行图:", - stateName: "bdms_task_count", + stateName: "bdms_task", desc: " 待运行: ${waiting} 个,\n \ 运行中: ${running} 个,\n \ 运行成功: ${success} 个,\n \ @@ -111,12 +113,7 @@ const OverviewConf={ name: "运行失败", value: "${failed}", }, - /*{ - name: "今日总任务", - value: "${total}", - }*/ ] - } ] },{ @@ -125,21 +122,21 @@ const OverviewConf={ content: [ { name: "虚拟机状态", - stateName: "openstack_vm_count", + stateName: "openstack_vm", value: "${total}", desc: "正常: ${lives} 异常: ${dead}.", }, { name: "镜像个数", - stateName: "openstack_image_count", - value: "${openstack_image_count}", - desc: "共保存了 ${openstack_image_count} 个镜像." + stateName: "openstack_image", + value: "${openstack_image}", + desc: "共保存了 ${openstack_image} 个镜像." }, { name: "云硬盘个数", - stateName: "openstack_disk_count", - value: "${openstack_disk_count}", - desc: "共分配了 ${openstack_disk_count} 个磁盘." + stateName: "openstack_disk", + value: "${openstack_disk}", + desc: "共分配了 ${openstack_disk} 个磁盘." } ] },{ @@ -148,9 +145,9 @@ const OverviewConf={ content: [ { name: "成员个数", - stateName: "userAuth_member_count", - value: "${userAuth_member_count}", - desc: "当前空间共有 ${userAuth_member_count} 人." + stateName: "userAuth_member", + value: "${userAuth_member}", + desc: "当前空间共有 ${userAuth_member} 人." }, ] }], diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 4b777e9..2f15578 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -7,72 +7,66 @@ import echarts from 'echarts' import OverviewConf from './OverviewConf' import EchartsUtil from 'public/Template/Echarts/EchartsUtil' import common from 'public/Template/echarts/common' +import update from 'react-update' export default React.createClass({ getInitialState:function(){ return { random: 0, - //hdfs_disk_used: 0, //HDFS使用百分比 - hdfs_disk_used: { + hdfs_disk: { //hdfs磁盘 used: 100, nonUsed: 50, unit: "TB", - total: 0, + total: 150, }, hdfs_shares: 0, //HDFS分享文件的个数 - //hdfs_datanodes: "0/0", //HDFS datanode健康状态(99/100) - hdfs_datanodes: { + hdfs_datanodes: { //hdfs datanode状态 lives: 0, dead: 0, total: 0 }, - //codis_count: "0/0", //Codis 集群总个数(10/11,正常集群/总集群) - codis_count: { + codis_cluster: { lives: 0, dead: 0, total: 0, }, - //codis_memory_used: 0, //Codis 内存使用率50% - codis_memory_used:{ + codis_memory:{ used: 100, nonUsed: 50, - unit: "GB" + unit: "GB", + total: 150 }, - //k8sp_pod_count: "0/0", //Pod个数(9/10) - k8sp_pod_count: { + k8sp_pod: { lives: 0, dead: 0, total: 0 }, - //k8sp_rc_count: "0/0", //rc(9/10) - k8sp_rc_count: { + k8sp_rc: { lives: 0, dead: 0, total: 0 }, - k8sp_service_status_count: 0, //Service状态 - //k8sp_nodes_count: 0, //Node个数 - k8sp_nodes_count: { + k8sp_service: 0, //Service状态 + k8sp_nodes: { lives: 0, dead: 0, total: 0 }, - bdms_task_count: { + bdms_task: { running: 0, //运行中 waiting: 0, //等待中 success: 0, //成功 failed: 0, //失败 total: 0 //总数 }, - //openstack_vm_count: "0/0", //虚拟机(9/10) - openstack_vm_count:{ + openstack_vm:{ lives: 0, //正常 dead: 0, //异常 total: 0, //总数 }, - openstack_image_count: 0, //镜像个数 - openstack_disk_count: 0, //云硬盘个数 - userAuth_member_count: 0, //当前space成员个数 + openstack_image: 0, //镜像个数 + openstack_disk: 0, //云硬盘个数 + userAuth_member: 0, //当前space成员个数 }; }, echartsMapping:{}, @@ -114,14 +108,6 @@ export default React.createClass({ //获取echart数据 let data = item.value; switch(type.toLocaleLowerCase()){ - /* - case "gauge": - data = {name: "", data: [{value: this.state[value], name: ""}]}; - break; - case "pienumber": - data = {name:value, text:this.state[value]}; - break; - */ case "pie": break; case "piesubarea": @@ -168,54 +154,21 @@ export default React.createClass({ return OverviewConf.getUrlData(this.requestArgs); }, getBdmsData(data){ - this.setState({ - bdms_running_count: data.today_running_task, - bdms_success_count: data.today_succeed_task, - bdms_failed_count: data.today_failed_task, - bdms_task_count: data.today_total_task - }); + }, getK8spData(data){ - let k8sp_pod_count = `${data.pod.count}/${data.pod.total}`; - let k8sp_rc_count = `${data.rc.count}/${data.rc.total}`; - let k8sp_service_status_count = `${data.service.count}`; - let k8sp_nodes_count = data.node.count; - this.setState({ - k8sp_pod_count: k8sp_pod_count, - k8sp_rc_count: k8sp_rc_count, - k8sp_service_status_count: k8sp_service_status_count, - k8sp_nodes_count: k8sp_nodes_count - }); + }, getCodisData(data){ - let codis_count = `${data.nice_codis_count}/${data.all_codis_count}`; - let codis_memory_used = data.memory_used_count.toFixed(2)/data.memory_total_count; - codis_memory_used = `${codis_memory_used.toFixed(2)*100} %`; - this.setState({ - codis_count: codis_count, - codis_memory_used: codis_memory_used, - }); }, getOpenstackData(data){ - this.setState({ - openstack_vm_count:data.vm, - openstack_image_count:data.image, - openstack_disk_count:data.volume - }); + }, getHdfsData(data){ - let hdfs_disk_used = data.hdfs_disk_used * 100; - hdfs_disk_used = hdfs_disk_used.toFixed(2); - this.setState({ - hdfs_disk_used: `${hdfs_disk_used} %`, - hdfs_shares: data.hdfs_shares, - hdfs_datanodes: data.hdfs_datanodes - }); + }, getUserAuthData(data){ - this.setState({ - userAuth_member_count: data.count - }); + }, render() { let spaceName = OverviewConf.getCurSpace(this); diff --git a/package/Aries/src/public/Template/Echarts/EchartsUtil.js b/package/Aries/src/public/Template/Echarts/EchartsUtil.js index 4b5412f..e3d9cf3 100644 --- a/package/Aries/src/public/Template/Echarts/EchartsUtil.js +++ b/package/Aries/src/public/Template/Echarts/EchartsUtil.js @@ -1,5 +1,3 @@ -import gauge from './gauge' -import pieNumber from './pieNumber' import pieSubarea from './pieSubarea' import pie from './pie' /* @@ -14,14 +12,6 @@ const EchartsUtil = { renderOptionData(type,data){ let tempData = ""; switch(type.toLocaleLowerCase()){ - /* - case "gauge": - tempData = gauge.renderOption(data); - break; - case "pienumber": - tempData = pieNumber.renderOption(data); - break; - */ case "pie": tempData = pie.renderOption(data); break; diff --git a/package/Aries/src/public/Template/Echarts/common.js b/package/Aries/src/public/Template/Echarts/common.js index a089e97..3ee6488 100644 --- a/package/Aries/src/public/Template/Echarts/common.js +++ b/package/Aries/src/public/Template/Echarts/common.js @@ -1,13 +1,37 @@ const common = { /* - * 替换单个模版字符串 - * demo: - * params: + * 递归替换 json(or string) 对象的每个value中的模版变量. + * 示例: * temp: {id:1,name:{ n1:"${args.t1}", n2:{nn2:"${args.date.month}",nn3:"${args.date.day}"}}} * args: {t1:1,date:{ month:2, day:3}} - * result: {id:1,name:{ n1:1, n2:{nn2:2,nn3:3}} + * 返回: {id:1,name:{ n1:1, n2:{nn2:2,nn3:3}} * */ + tempPreHandler(temp,args){ + if(typeof(temp) != "object"){ + //替换字符串中的变量 + temp = common.tempVariReplace(temp, args); + return temp; + } + //遍历args对象,找到模版变量,然后直接替换模版变量 "${item}" + Object.keys(temp).forEach(function(item, index){ + let jsonValue = temp[item]; + if(typeof(jsonValue) == "object"){ + temp[item] = common.tempPreHandler(jsonValue,args); + }else{ + temp[item] = common.tempVariReplace(jsonValue,args); + return temp + } + }); + return temp; + }, + /* + * 替换单个模版字符串 + * 示例 + * jsonValue : "abc_${date.month}" + * args: {date:{ month:1}} + * 返回: "abc_1" + */ tempVariReplace(jsonValue, args){ let reg = /\${[\w|.]+}/g; //只替换字符串模版 @@ -30,28 +54,16 @@ const common = { } return jsonValue; }, - tempPreHandler(temp,args){ - if(typeof(temp) != "object"){ - //替换字符串中的变量 - temp = common.tempVariReplace(temp, args); - return temp; - } - //遍历args对象,找到模版变量,然后直接替换模版变量 "${item}" - Object.keys(temp).forEach(function(item, index){ - let jsonValue = temp[item]; - if(typeof(jsonValue) == "object"){ - temp[item] = common.tempPreHandler(jsonValue,args); - }else{ - temp[item] = common.tempVariReplace(jsonValue,args); - return temp - } - }); - return temp; - }, + /* + * 取出 json 中 指定属性的值.允许嵌套 + * 示例 + * arr: ["date","month"] + * obj: {"date":{"month":1}} + * 返回: 1 + */ getObjectAttr(arr, obj){ let value = obj; - //获取obj的属性对应的值,属性可以是多个层级 - if( typeof(obj) != "object"){ + if(typeof(obj) != "object"){ return value; } arr.forEach((item,index)=>{ @@ -59,6 +71,7 @@ const common = { }); return value; } + } export default common; diff --git a/package/Aries/src/public/Template/Echarts/pie.js b/package/Aries/src/public/Template/Echarts/pie.js index fb3ce1d..41d2ea5 100644 --- a/package/Aries/src/public/Template/Echarts/pie.js +++ b/package/Aries/src/public/Template/Echarts/pie.js @@ -1,5 +1,6 @@ import common from './common' import echarts from 'echarts' +// echarts 百分比饼图模版数据 const pie = { option: { legend: { @@ -66,9 +67,6 @@ const pie = { }, //渲染option的函数 renderOption(data){ - //let tempOption = {id:1,name:{ n1:"${args.t1}", n2:{nn2:"${args.date.month}",nn3:"${args.date.day}"}}}; - //let args = {t1:1,date:{ month:2, day:3}} - //let option = common.tempPreHandler(tempOption,args); let option = common.tempPreHandler(this.option,data); console.log(option); return option; diff --git a/package/Aries/src/public/Template/Echarts/pieSubarea.js b/package/Aries/src/public/Template/Echarts/pieSubarea.js index ead406c..df17fb4 100644 --- a/package/Aries/src/public/Template/Echarts/pieSubarea.js +++ b/package/Aries/src/public/Template/Echarts/pieSubarea.js @@ -1,5 +1,5 @@ -//饼图分区模版数据 import common from './common' +//echarts 饼图分区模版数据 const pieSubarea = { option: { legend: { @@ -14,7 +14,7 @@ const pieSubarea = { data: "${data}" }] }, - formtarData(data){ + formatterData(data){ return data.map((item,index)=>{ return { value: item.value, @@ -34,7 +34,7 @@ const pieSubarea = { }, //渲染option的函数 renderOption(data){ - data = this.formtarData(data); + data = this.formatterData(data); console.log(data); let option = common.tempPreHandler(this.option,{data:data}); console.log(option); From 54ee8811305ffb87b15f394f88bec5f10cf4c496 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Tue, 29 Nov 2016 17:13:08 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/functions/Overview/OverviewConf.js | 52 +++++++++---------- .../Aries/src/functions/Overview/index.jsx | 44 ++++++++++------ .../src/public/Template/Echarts/common.js | 9 ++-- 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index ba5667b..b9eb45c 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -6,28 +6,28 @@ const OverviewConf={ id: "hdfs", content: [ { - name: "hdfs使用率", + name: "HDFS使用率", stateName: "hdfs_disk", value: { used: "${used}", nonUsed: "${nonUsed}" }, type: "pie", - desc: "已使用: ${used} ${unit} \ - 剩余: ${nonUsed} ${unit} \ + desc: "已使用: ${used} ${unit}
\ + 剩余: ${nonUsed} ${unit}
\ 总共: ${total} ${unit}" }, { - name: "hdfs分享个数", + name: "HDFS分享个数", value: "${hdfs_shares}", stateName: "hdfs_shares", desc: "${hdfs_shares} 个目录被分享." }, { - name: "dn存活状态", + name: "DN存活状态", stateName: "hdfs_datanodes", value: "${lives} / ${total}", - desc: "健康: ${lives}. 异常: ${dead}" + desc: "健康: ${lives}
异常: ${dead}" } ] },{ @@ -35,10 +35,10 @@ const OverviewConf={ id: "codis", content: [ { - name: "codis集群总数", + name: "Codis 集群", stateName: "codis_cluster", value: "${lives} / ${total}", - desc: "正常: ${lives}. \ + desc: "正常: ${lives}
\ 异常: ${dead}" }, { @@ -49,8 +49,8 @@ const OverviewConf={ nonUsed: "${nonUsed}" }, type: "pie", - desc: "已使用: ${used} ${unit}, \ - 剩余: ${nonUsed} ${unit} \ + desc: "已使用: ${used} ${unit}
\ + 剩余: ${nonUsed} ${unit}
\ 总共: ${total} ${unit}" }, ] @@ -59,28 +59,28 @@ const OverviewConf={ id: "k8s", content: [ { - name: "pod个数", + name: "Pod个数", stateName: "k8sp_pod", value: "${lives} / ${total}", - desc: "正常: ${lives}. 异常: ${dead}" + desc: "正常: ${lives}
异常: ${dead}" }, { - name: "rc个数", + name: "RC个数", stateName: "k8sp_rc", value: "${lives} / ${total}", - desc: "正常: ${lives}. 异常: ${dead}" + desc: "正常: ${lives}
异常: ${dead}" }, { - name: "service状态", + name: "Service状态", stateName: "k8sp_service", value: "${k8sp_service}", desc: "${k8sp_service} 状态." }, { - name: "node个数", + name: "Node个数", stateName: "k8sp_nodes", value: "${lives} / ${total}", - desc: "正常: ${lives} 异常: ${dead}" + desc: "正常: ${lives}
异常: ${dead}" } ] },{ @@ -91,10 +91,10 @@ const OverviewConf={ type: "pieSubarea", name: "BDMS任务运行图:", stateName: "bdms_task", - desc: " 待运行: ${waiting} 个,\n \ - 运行中: ${running} 个,\n \ - 运行成功: ${success} 个,\n \ - 运行失败: ${failed} 个,\n \ + desc: " 待运行: ${waiting} 个
\ + 运行中: ${running} 个
\ + 运行成功: ${success} 个
\ + 运行失败: ${failed} 个
\ 总任务: ${total} 个", value: [ { @@ -123,20 +123,20 @@ const OverviewConf={ { name: "虚拟机状态", stateName: "openstack_vm", - value: "${total}", - desc: "正常: ${lives} 异常: ${dead}.", + value: "${lives} / ${total}", + desc: "正常: ${lives}
异常: ${dead}", }, { name: "镜像个数", stateName: "openstack_image", value: "${openstack_image}", - desc: "共保存了 ${openstack_image} 个镜像." + desc: "共保存了 ${openstack_image} 个镜像" }, { name: "云硬盘个数", stateName: "openstack_disk", value: "${openstack_disk}", - desc: "共分配了 ${openstack_disk} 个磁盘." + desc: "共分配了 ${openstack_disk} 个磁盘" } ] },{ @@ -147,7 +147,7 @@ const OverviewConf={ name: "成员个数", stateName: "userAuth_member", value: "${userAuth_member}", - desc: "当前空间共有 ${userAuth_member} 人." + desc: "当前空间共有 ${userAuth_member} 人" }, ] }], diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 2f15578..f225b57 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -10,14 +10,14 @@ import common from 'public/Template/echarts/common' import update from 'react-update' export default React.createClass({ - getInitialState:function(){ + getInitialState: function(){ return { random: 0, hdfs_disk: { //hdfs磁盘 - used: 100, - nonUsed: 50, + used: 0, + nonUsed: 0, unit: "TB", - total: 150, + total: 0, }, hdfs_shares: 0, //HDFS分享文件的个数 hdfs_datanodes: { //hdfs datanode状态 @@ -30,7 +30,7 @@ export default React.createClass({ dead: 0, total: 0, }, - codis_memory:{ + codis_memory: { used: 100, nonUsed: 50, unit: "GB", @@ -59,7 +59,7 @@ export default React.createClass({ failed: 0, //失败 total: 0 //总数 }, - openstack_vm:{ + openstack_vm: { lives: 0, //正常 dead: 0, //异常 total: 0, //总数 @@ -91,7 +91,7 @@ export default React.createClass({
} //渲染描述 - let echart_desc =
{item.desc}
+ let echart_desc =
return
{item.name} @@ -109,10 +109,7 @@ export default React.createClass({ let data = item.value; switch(type.toLocaleLowerCase()){ case "pie": - break; case "piesubarea": - //组合需要单独处理 - console.log(data); break; default: console.log(`该类型图表暂不支持! type:${type}`); @@ -130,8 +127,6 @@ export default React.createClass({ let content = item.content.map(function(item,index){ let id = `echarts_${cid}_${index}` let type = item.type; - //根据不用的图表渲染不同的数据 - //let data = {name: "", data: [{value: 50, name: item.name}]}; if( type != undefined ){ let data = this.echartsData(type,item); let option = EchartsUtil.renderOptionData(type,data); @@ -154,21 +149,36 @@ export default React.createClass({ return OverviewConf.getUrlData(this.requestArgs); }, getBdmsData(data){ - + let total = data.running + data.waiting + data.failed + data.success; + data["total"] = total; + this.setState({ bdms_task: data}); }, getK8spData(data){ - + this.setState({ k8sp_rc: data.rc, + k8sp_pod: data.pod, + k8sp_nodes: data.node, + k8sp_service: data.service + }); }, getCodisData(data){ + this.setState({ codis_cluster: data.codis_cluster, + codis_memory: data.codis_memory + }); }, getOpenstackData(data){ - + this.setState({ openstack_disk: data.openstack_disk, + openstack_image: data.openstack_image, + openstack_vm: data.openstack_vm + }); }, getHdfsData(data){ - + this.setState({ hdfs_datanodes: data.hdfs_datanodes, + hdfs_disk: data.hdfs_disk, + hdfs_shares: data.hdfs_shares + }); }, getUserAuthData(data){ - + this.setState({ userAuth_member: data.userAuth_member}); }, render() { let spaceName = OverviewConf.getCurSpace(this); diff --git a/package/Aries/src/public/Template/Echarts/common.js b/package/Aries/src/public/Template/Echarts/common.js index 3ee6488..d0e4462 100644 --- a/package/Aries/src/public/Template/Echarts/common.js +++ b/package/Aries/src/public/Template/Echarts/common.js @@ -2,8 +2,8 @@ const common = { /* * 递归替换 json(or string) 对象的每个value中的模版变量. * 示例: - * temp: {id:1,name:{ n1:"${args.t1}", n2:{nn2:"${args.date.month}",nn3:"${args.date.day}"}}} - * args: {t1:1,date:{ month:2, day:3}} + * temp: {id:1,name:{n1:"${t1}", n2:{nn2:"${date.month}",nn3:"${date.day}"}}} + * args: {t1:1,date:{month:2, day:3}} * 返回: {id:1,name:{ n1:1, n2:{nn2:2,nn3:3}} * */ @@ -55,7 +55,7 @@ const common = { return jsonValue; }, /* - * 取出 json 中 指定属性的值.允许嵌套 + * 取出 json 中 指定属性的值 * 示例 * arr: ["date","month"] * obj: {"date":{"month":1}} @@ -70,8 +70,7 @@ const common = { value = value[item]; }); return value; - } - + }, } export default common; From f74530bb0e56271f9b9e22c812dfb7fda99d3293 Mon Sep 17 00:00:00 2001 From: zd1990 Date: Wed, 30 Nov 2016 10:40:24 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9openstack=E6=A6=82?= =?UTF-8?q?=E8=A7=88API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aries/openstack/rests.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Aries/openstack/rests.py b/Aries/openstack/rests.py index 3d17aeb..8d08b20 100644 --- a/Aries/openstack/rests.py +++ b/Aries/openstack/rests.py @@ -66,13 +66,14 @@ def get(self,request,format=None): class overview(APIView): def get(self, request, format=None): - ret = {'vm':'0/0','image':0,'volume':0} + ret = {'openstack_vm':{"lives":0,"dead":0},'openstack_image':0,'openstack_disk':0} login(request) username = request.user.username total,running = num_get_vm(request,username) - ret['vm'] = "%s/%s"%(running,total) - ret['image'] = num_get_image(request,username) - ret['volume'] = num_get_volume(request,username) + ret['openstack_vm']['lives'] = running + ret['openstack_vm']['dead'] = total - running + ret['openstack_image'] = num_get_image(request,username) + ret['openstack_disk'] = num_get_volume(request,username) ret = json_data(ret) return packageResponse(ret) From 876a924b77e5c8f3bad7f9713efc379273197fe9 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Wed, 30 Nov 2016 11:00:22 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aries/src/functions/Overview/index.jsx | 22 ++- .../src/public/Template/Echarts/common.js | 3 +- .../Aries/src/public/Template/Echarts/pie.js | 127 +++++++++--------- .../src/public/Template/Echarts/pieSubarea.js | 30 ++--- 4 files changed, 95 insertions(+), 87 deletions(-) diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index f225b57..b060146 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -15,9 +15,9 @@ export default React.createClass({ random: 0, hdfs_disk: { //hdfs磁盘 used: 0, - nonUsed: 0, + nonUsed: 1, unit: "TB", - total: 0, + total: 1, }, hdfs_shares: 0, //HDFS分享文件的个数 hdfs_datanodes: { //hdfs datanode状态 @@ -31,10 +31,10 @@ export default React.createClass({ total: 0, }, codis_memory: { - used: 100, - nonUsed: 50, + used: 1, + nonUsed: 1, unit: "GB", - total: 150 + total: 2 }, k8sp_pod: { lives: 0, @@ -71,6 +71,14 @@ export default React.createClass({ }, echartsMapping:{}, index(){ + let cur_space = auth.user.cur_space; + let type = auth.user.type; + if(cur_space== "" && type < 1){ + return
您还不属于任何space.请联系space管理员进行添加.
+ } + if(cur_space== "" && type >0){ + return
您还没有创建任何space.请先创建space
+ } let data = OverviewConf.overviewData; let overviewBody = data.map(function(item,index){ //渲染图表div. @@ -203,14 +211,14 @@ export default React.createClass({ return (
{this.index()} - {/* + {/* */} - */} +
) } diff --git a/package/Aries/src/public/Template/Echarts/common.js b/package/Aries/src/public/Template/Echarts/common.js index d0e4462..c247b2d 100644 --- a/package/Aries/src/public/Template/Echarts/common.js +++ b/package/Aries/src/public/Template/Echarts/common.js @@ -37,7 +37,6 @@ const common = { //只替换字符串模版 let tempVari = typeof(jsonValue) == "string" ? jsonValue.match(reg): null; tempVari != null && tempVari.forEach((tempVariName,index)=>{ - debugger; //模版变量变量名 let regStr = `/\\${tempVariName}/g`; let reg = eval(regStr); @@ -50,7 +49,7 @@ const common = { try{ jsonValue = JSON.parse(jsonValue); }catch(err){ - console.log(`${jsonValue} is not object`); + //console.log(`${jsonValue} is not object`); } return jsonValue; }, diff --git a/package/Aries/src/public/Template/Echarts/pie.js b/package/Aries/src/public/Template/Echarts/pie.js index 41d2ea5..6442b4b 100644 --- a/package/Aries/src/public/Template/Echarts/pie.js +++ b/package/Aries/src/public/Template/Echarts/pie.js @@ -2,73 +2,74 @@ import common from './common' import echarts from 'echarts' // echarts 百分比饼图模版数据 const pie = { - option: { - legend: { - orient: 'vertical', - left: 'left', - }, - series : [ - { - type: 'pie', - radius : ['50%', '80%'], - center: ['50%','50%'], - hoverAnimation:false, - label: { - normal: { - show: true, - formatter: function(params){return params.percent.toFixed(0)+"%"}, - } - }, - itemStyle: { - normal: { - borderColor: "#ddd", - borderWidth: 2, - color : - new echarts.graphic.RadialGradient(0.5, 0.5, 0.5, [{ - offset: 0.6, color: 'red' // 0% 处的颜色 - }, { - offset: 1, color: 'red' // 100% 处的颜色 - }], false - ) + getOption(){ + return { + legend: { + orient: 'vertical', + left: 'left', + }, + series : [ + { + type: 'pie', + radius : ['50%', '80%'], + center: ['50%','50%'], + hoverAnimation:false, + label: { + normal: { + show: true, + formatter: function(params){return params.percent.toFixed(0)+"%"}, + } + }, + itemStyle: { + normal: { + borderColor: "#ddd", + borderWidth: 2, + color : + new echarts.graphic.RadialGradient(0.5, 0.5, 0.5, [{ + offset: 0.6, color: 'red' // 0% 处的颜色 + }, { + offset: 1, color: 'red' // 100% 处的颜色 + }], false + ) - } - }, - data:[ - { - value:"${used}", - label: { - normal: { - position: "center", - textStyle: { - color: 'red', - fontSize: 25, - fontStyle: 'normal', - fontWeight: 'bold', - fontFamily: "Helvetica Neue" + } + }, + data:[ + { + value:"${used}", + label: { + normal: { + position: "center", + textStyle: { + color: 'red', + fontSize: 25, + fontStyle: 'normal', + fontWeight: 'bold', + fontFamily: "Helvetica Neue" - } - } - } - }, - { - value:"${nonUsed}", - tooltip: { - show: false - }, - itemStyle: { - normal: { - color: '#fff' - } - }, - } - ] - } - ] -}, + } + } + } + }, + { + value:"${nonUsed}", + tooltip: { + show: false + }, + itemStyle: { + normal: { + color: '#fff' + } + }, + } + ] + } + ] + } + }, //渲染option的函数 renderOption(data){ - let option = common.tempPreHandler(this.option,data); - console.log(option); + let option = common.tempPreHandler(this.getOption(),data); return option; } } diff --git a/package/Aries/src/public/Template/Echarts/pieSubarea.js b/package/Aries/src/public/Template/Echarts/pieSubarea.js index df17fb4..90749b1 100644 --- a/package/Aries/src/public/Template/Echarts/pieSubarea.js +++ b/package/Aries/src/public/Template/Echarts/pieSubarea.js @@ -1,18 +1,20 @@ import common from './common' //echarts 饼图分区模版数据 const pieSubarea = { - option: { - legend: { - orient: 'vertical', - x: 'left', - }, - hoverAnimation:false, - series: [{ - type: 'pie', - center: ['50%','50%'], - radius: ['50%', '80%'], - data: "${data}" - }] + getOption(){ + return { + legend: { + orient: 'vertical', + x: 'left', + }, + hoverAnimation:false, + series: [{ + type: 'pie', + center: ['50%','50%'], + radius: ['50%', '80%'], + data: "${data}" + }] + } }, formatterData(data){ return data.map((item,index)=>{ @@ -35,9 +37,7 @@ const pieSubarea = { //渲染option的函数 renderOption(data){ data = this.formatterData(data); - console.log(data); - let option = common.tempPreHandler(this.option,{data:data}); - console.log(option); + let option = common.tempPreHandler(this.getOption(),{data:data}); return option; } } From 61548aa0552e188ddee8bf72e0d28355d89879f9 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Wed, 30 Nov 2016 11:01:31 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E5=8F=96=E6=B6=88react=20update=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/Aries/src/functions/Overview/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index b060146..14c93c4 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -7,7 +7,6 @@ import echarts from 'echarts' import OverviewConf from './OverviewConf' import EchartsUtil from 'public/Template/Echarts/EchartsUtil' import common from 'public/Template/echarts/common' -import update from 'react-update' export default React.createClass({ getInitialState: function(){ From a126b5ef58e3df161c3977ba1cbd1310bd20b288 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Wed, 30 Nov 2016 11:05:44 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E6=8F=90=E4=BA=A4packagejson=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/Aries/package.json | 89 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/package/Aries/package.json b/package/Aries/package.json index fee91a7..6f3bb77 100644 --- a/package/Aries/package.json +++ b/package/Aries/package.json @@ -1,46 +1,47 @@ { - "scripts": { - "lint": "eslint --ext .jsx,.js src || true", - "build": "cross-env NODE_ENV=production webpack -p --progress --colors --bail", - "start": "node-dev server.js", - "theme": "node bin/theme.js -#ff7043:#42a5f5 -#ff5722:#55a8fd -#f4511e:#1e88e5" - }, - "dependencies": { - "antd": "^1.8.0", - "bfd-bootstrap": "0.0.22", - "bfd-ui": "^0.10.0", - "echarts": "^3.2.3", - "js-cookie": "^2.1.2", - "less": "^2.7.1", - "less-loader": "^2.2.3", - "react-copy-to-clipboard": "^4.2.2", - "react-markdown": "^2.4.2", - "uuid": "^2.0.2", - "vis": "^4.16.1" - }, - "devDependencies": { - "autoprefixer": "^6.3.6", - "babel-cli": "^6.3.17", - "babel-loader": "^6.2.0", - "babel-plugin-antd": "^0.4.1", - "babel-plugin-transform-runtime": "~6.4.3", - "babel-preset-es2015": "^6.3.13", - "babel-preset-react": "^6.3.13", - "babel-preset-stage-0": "^6.3.13", - "cross-env": "^1.0.8", - "ejs": "^2.4.1", - "eslint": "^1.10.3", - "eslint-loader": "^1.3.0", - "eslint-plugin-react": "^4.2.3", - "express": "^4.13.3", - "install": "^0.8.1", - "node-dev": "^3.1.0", - "npm": "^3.9.5", - "postcss-loader": "^0.8.2", - "rimraf": "^2.5.2", - "underscore": "^1.8.3", - "webpack": "^1.12.9", - "webpack-dev-middleware": "^1.4.0", - "webpack-livereload-plugin": "^0.8.1" - } + "scripts": { + "lint": "eslint --ext .jsx,.js src || true", + "build": "cross-env NODE_ENV=production webpack -p --progress --colors --bail", + "start": "node-dev server.js", + "theme": "node bin/theme.js -#ff7043:#42a5f5 -#ff5722:#55a8fd -#f4511e:#1e88e5" + }, + "dependencies": { + "antd": "^1.8.0", + "bfd-bootstrap": "0.0.22", + "bfd-ui": "^0.10.0", + "echarts": "^3.2.3", + "js-cookie": "^2.1.2", + "less": "^2.7.1", + "less-loader": "^2.2.3", + "react-copy-to-clipboard": "^4.2.2", + "react-markdown": "^2.4.2", + "react-update": "^0.4.2", + "uuid": "^2.0.2", + "vis": "^4.16.1" + }, + "devDependencies": { + "autoprefixer": "^6.3.6", + "babel-cli": "^6.3.17", + "babel-loader": "^6.2.0", + "babel-plugin-antd": "^0.4.1", + "babel-plugin-transform-runtime": "~6.4.3", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-stage-0": "^6.3.13", + "cross-env": "^1.0.8", + "ejs": "^2.4.1", + "eslint": "^1.10.3", + "eslint-loader": "^1.3.0", + "eslint-plugin-react": "^4.2.3", + "express": "^4.13.3", + "install": "^0.8.1", + "node-dev": "^3.1.0", + "npm": "^3.9.5", + "postcss-loader": "^0.8.2", + "rimraf": "^2.5.2", + "underscore": "^1.8.3", + "webpack": "^1.12.9", + "webpack-dev-middleware": "^1.4.0", + "webpack-livereload-plugin": "^0.8.1" + } } From 4044d652eae5386c5cbb81aa86e17b0cce384d98 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Wed, 30 Nov 2016 11:29:14 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=86=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/Aries/src/functions/Overview/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 14c93c4..7b16a9e 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -6,7 +6,7 @@ import Fetch from 'bfd/Fetch' import echarts from 'echarts' import OverviewConf from './OverviewConf' import EchartsUtil from 'public/Template/Echarts/EchartsUtil' -import common from 'public/Template/echarts/common' +import common from 'public/Template/Echarts/common' export default React.createClass({ getInitialState: function(){ From 870ebd60fd4d0676c2541b8bd3bbc37f1f0f8710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=94=80?= Date: Wed, 30 Nov 2016 18:42:18 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9k8s=20overview=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aries/kd_agent/toolsmanager.py | 5 ++++ Aries/kd_agent/views.py | 43 ++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Aries/kd_agent/toolsmanager.py b/Aries/kd_agent/toolsmanager.py index fb17781..a392a23 100644 --- a/Aries/kd_agent/toolsmanager.py +++ b/Aries/kd_agent/toolsmanager.py @@ -83,6 +83,11 @@ def get_ingress_detail_info( namespace,params={} ): url = '/apis/extensions/v1beta1/namespaces/%s/ingresses' % namespace return K8sRequestManager.get_k8s_data( url,params ) + @staticmethod + def get_node_detail_info(): + url = '/api/v1/nodes' + return K8sRequestManager.get_k8s_data( url,{} ) + # 根据原生的API获取k8s的数据 @staticmethod def get_k8s_data(url,params = {},timeout = 10 ): diff --git a/Aries/kd_agent/views.py b/Aries/kd_agent/views.py index fed6040..da584ce 100644 --- a/Aries/kd_agent/views.py +++ b/Aries/kd_agent/views.py @@ -34,14 +34,19 @@ def get_overview_k8s_pod_info(namespace): if pod_detail_info['code'] == RETU_INFO_ERROR: kd_logger.error( 'call get_overview_k8s_pod_info query k8s pod data error : %s' % pod_detail_info['msg'] ) else: + total = len(pod_detail_info['data']['items']) count = 0 - total = 0 for item in pod_detail_info['data']['items']: containerStatuses = item['status'].get('containerStatuses',[]) - total += len(containerStatuses) + + is_all_container_running = True for cItem in containerStatuses: - if cItem['state'].get( 'running' ) != None: - count += 1 + if cItem['state'].get( 'running' ) == None: + is_all_container_running = False + break + + count += 1 if is_all_container_running else 0 + retu_data['count'] = count retu_data['total'] = total return retu_data @@ -71,19 +76,37 @@ def get_overview_k8s_rc_info(namespace): return retu_data # node要从influxdb中获取数量,但是当前无法获取,因此该函数的实现暂时先搁置。 -def get_overview_k8s_node_info(namespace): - retu_data = { 'count':0 } +def get_overview_k8s_node_info(): + retu_data = { 'total':0,'count':0 } + node_detail_data = KRM.get_node_detail_info() + if node_detail_data['code'] == RETU_INFO_ERROR: + kd_logger.error( 'call get_overview_k8s_node_info query k8s node data error : %s' % node_detail_data['msg'] ) + else: + total = len(node_detail_data['data']['items']) + count = 0 + for item in node_detail_data['data']['items']: + for condition in item['status']['conditions']: + if condition['type'] == 'Ready' and condition['status'] == 'True': + count += 1 + break + retu_data['count'] = count + retu_data['total'] = total return retu_data @csrf_exempt @return_http_json @trans_return_json def get_k8soverview_info(request,namespace): + pod = get_overview_k8s_pod_info(namespace) + rc = get_overview_k8s_rc_info(namespace) + service = get_overview_k8s_service_info(namespace) + node = get_overview_k8s_node_info() + retu_data = { - 'pod': get_overview_k8s_pod_info(namespace) , - 'rc': get_overview_k8s_rc_info(namespace), - 'service': get_overview_k8s_service_info(namespace), - 'node': get_overview_k8s_node_info(namespace) + 'k8sp_pod':{ 'lives':pod['count'],'dead':pod['total']-pod['count'] }, + 'k8sp_rc':{ 'current':rc['count'],'desired':rc['total'] }, + 'k8sp_service':{ 'count':service['count'] } , + 'k8sp_nodes': { 'lives':node['count'],'dead':node['total']-node['count'] } } kd_logger.info( 'call get_overview_k8s_rc_info query k8s overview info : %s' % retu_data ) return generate_success( data=retu_data ) From 8c434e141f1b1455ca8c4fe9eef5de4fa65714f1 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Wed, 30 Nov 2016 19:43:46 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aries/hdfs/function.py | 10 +++++-- Aries/hdfs/service.py | 62 ++++++++++++++++++++++++++---------------- Aries/hdfs/tools.py | 16 ++++++----- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/Aries/hdfs/function.py b/Aries/hdfs/function.py index 41be466..2a44f9f 100644 --- a/Aries/hdfs/function.py +++ b/Aries/hdfs/function.py @@ -225,7 +225,7 @@ def list_status_share(self,request,path): 'name': source_path.split("/")[-1], 'create_time': datetime.datetime.fromtimestamp(item.get('modificationTime')/1000).strftime("%Y-%m-%d %H:%M:%S"), 'is_dir': 0, - 'size' : unitTransform(item.get('length'),0,unit) if item.get('type') == "FILE" else "-" + 'size' : self.getSize(item.get('length'),0,unit) if item.get('type') == "FILE" else "-" }] else: #目录分享 @@ -242,7 +242,7 @@ def list_status_share(self,request,path): 'name': item.get('pathSuffix'), 'create_time': datetime.datetime.fromtimestamp(item.get('modificationTime')/1000).strftime("%Y-%m-%d %H:%M:%S"), 'is_dir': 0 if item.get('type') == "FILE" else 1, - 'size': unitTransform(item.get('length'),0,unit) if item.get('type') == "FILE" else "-", + 'size': self.getSize(item.get('length'),0,unit) if item.get('type') == "FILE" else "-", } for item in result if item.get('pathSuffix') != ".Trash" ] else: @@ -295,13 +295,17 @@ def list_status(self, path, request): 'name': item.get('pathSuffix'), 'create_time': datetime.datetime.fromtimestamp(item.get('modificationTime')/1000).strftime("%Y-%m-%d %H:%M:%S"), 'is_dir': 0 if item.get('type') == "FILE" else 1, - 'size': unitTransform(item.get('length'),0,unit) if item.get('type') == "FILE" else "-", + 'size': self.getSize(item.get('length'),0,unit) if item.get('type') == "FILE" else "-", } for item in result if item.get('pathSuffix') != ".Trash" ] self.returned['data'] = {"totalList":totalList,"totalPageNum":len(totalList),"currentPage":1} hdfs_logger.info("liststatus:%s" %self.returned['data']) return self.returned + def getSize(self, size, index, unit): + size, index, unit = unitTransform(size, index, unit) + return "%s %s" % (size, unit) + def _copy_file(self, src_path, dest_path, username): o_type = FileOperatorType.objects.get(name='cp') log_pk = self._insert_operate_log( diff --git a/Aries/hdfs/service.py b/Aries/hdfs/service.py index b30ba8d..2884295 100644 --- a/Aries/hdfs/service.py +++ b/Aries/hdfs/service.py @@ -15,6 +15,7 @@ from hdfs.function import HDFS from django.http import HttpResponse from tools import * +import math import requests from requests.auth import HTTPBasicAuth @@ -575,37 +576,52 @@ def getOverview(request): result = {} result["code"] = StatusCode["SUCCESS"] data = {} - #使用百分比 - space = getObjByAttr(Space,"name",spaceName) + unitList = ["GB", "TB", "PB"] + # 使用百分比 + space = getObjByAttr(Space, "name", spaceName) + hdfs_disk = { + "used": 0, + "nonUsed": 0, + "unit": "GB" + } if space: capacity = space[0].capacity capacity = eval(capacity) - used = capacity["used"] - total = capacity["total"] - try: - hdfs_disk_used = round(float(used)/float(total),2) - except Exception,e: - ac_logger.error(e) - hdfs_disk_used = 0 - else: - hdfs_disk_used = 0 - #分享个数 + used = float(capacity["used"]) + total = float(capacity["total"]) + total, index, unit = unitTransform(total, 0, unitList) + total = round(total, 2) + used = round(used/math.pow(1024, index), 2) + print total + print used + non_used = round(total - used, 2) + hdfs_disk["used"] = used + hdfs_disk["nonUsed"] = non_used + hdfs_disk["unit"] = unit + + # 分享个数 try: - hdfs_shares = DataShare.objects.filter(space_name = spaceName).count() - except Exception,e: - ac_logger.error("hdfs_shares is get failed. so set default 0.") + hdfs_shares = DataShare.objects.filter(space_name=spaceName).count() + except Exception, e: + ac_logger.error("hdfs_shares is get failed. so set default 0. %s" %e) hdfs_shares = 0 - #datanode状态个数 + + # datanode状态个数 + hdfs_datanodes = { + "lives": 0, + "dead": 0 + } try: - extendUrl = "services/HDFS/components/DATANODE" - dic = requestEval(extendUrl) + extend_url = "services/HDFS/components/DATANODE" + dic = requestEval(extend_url) total_count = dic["ServiceComponentInfo"]["total_count"] - started_count = dic["ServiceComponentInfo"]["started_count"] - hdfs_datanodes = "{0}/{1}".format(started_count,total_count) - except Exception,e: + lives = dic["ServiceComponentInfo"]["started_count"] + dead = total_count - lives + hdfs_datanodes["lives"] = lives + hdfs_datanodes["dead"] = dead + except Exception, e: ac_logger.error(e) - hdfs_datanodes = "0/0" - data["hdfs_disk_used"] = hdfs_disk_used + data["hdfs_disk"] = hdfs_disk data["hdfs_shares"] = hdfs_shares data["hdfs_datanodes"] = hdfs_datanodes result["data"] = data diff --git a/Aries/hdfs/tools.py b/Aries/hdfs/tools.py index 7a2e07e..4aa028f 100644 --- a/Aries/hdfs/tools.py +++ b/Aries/hdfs/tools.py @@ -130,17 +130,19 @@ def sharePath(shareId,path): real_path = os.path.realpath("%s/%s/%s/%s" %(os.path.sep,space_path,source_path,path)) return real_path,source_path -def unitTransform(size,index,unit): +def unitTransform(size, index, unit): if size/1024.0 > 1024: b = size/1024.0 index = index+1 - return unitTransform(b,index,unit) + return unitTransform(b, index, unit) elif size/1024.0 < 1: - return "{0} {1}".format(round(size,1),unit[index]) - elif size/1024.0 >1 and size/1024.0 < 1024: + # return "{0} {1}".format(round(size,1),unit[index]) + return round(size, 1), index, unit[index] + elif (size/1024.0 > 1) and (size/1024.0 < 1024): b = size/1024.0 - index = index+1 - return "{0} {1}".format(round(b,1),unit[index]) + index = index + 1 + return round(b, 1), index, unit[index] + # return "{0} {1}".format(round(b,1),unit[index]) @print_request def test(a,b): @@ -151,7 +153,7 @@ def test2(a,b): print a,b if __name__=="__main__": - unitTransform(1025,0,["KB","MB","GB","TB"]) + print unitTransform(1025,0,["KB","MB","GB","TB"]) #print "aaa" #test(3,4) #test2(3,4) From add51d04b01fd2f0340587755fd766c87564301b Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Thu, 1 Dec 2016 14:17:36 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dechart=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aries/user_auth/service.py | 2 +- .../src/functions/Overview/OverviewConf.js | 294 +++++++++--------- .../Aries/src/functions/Overview/index.jsx | 78 ++++- 3 files changed, 211 insertions(+), 163 deletions(-) diff --git a/Aries/user_auth/service.py b/Aries/user_auth/service.py index 391bf7d..b5a4a95 100644 --- a/Aries/user_auth/service.py +++ b/Aries/user_auth/service.py @@ -37,7 +37,7 @@ def getOverview(request): except Exception,e: ac_logger.info(e) count = 0; - data["count"] = count + data["userAuth_member"] = count result["code"] = 200 result["data"] = data return result diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index b9eb45c..d20ba24 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -1,156 +1,158 @@ import conf from 'public/Conf/Conf' const OverviewConf={ //概览基础数据定义 - overviewData:[{ - title: "HDFS", - id: "hdfs", - content: [ - { - name: "HDFS使用率", - stateName: "hdfs_disk", - value: { - used: "${used}", - nonUsed: "${nonUsed}" - }, - type: "pie", - desc: "已使用: ${used} ${unit}
\ - 剩余: ${nonUsed} ${unit}
\ - 总共: ${total} ${unit}" - }, - { - name: "HDFS分享个数", - value: "${hdfs_shares}", - stateName: "hdfs_shares", - desc: "${hdfs_shares} 个目录被分享." - }, - { - name: "DN存活状态", - stateName: "hdfs_datanodes", - value: "${lives} / ${total}", - desc: "健康: ${lives}
异常: ${dead}" - } - ] - },{ - title: "CODIS", - id: "codis", + getOverviewData(){ + return [{ + title: "HDFS", + id: "hdfs", content: [ - { - name: "Codis 集群", - stateName: "codis_cluster", - value: "${lives} / ${total}", - desc: "正常: ${lives}
\ - 异常: ${dead}" - }, - { - name: "Codis 内存使用率", - stateName: "codis_memory", - value: { - used: "${used}", - nonUsed: "${nonUsed}" + { + name: "HDFS使用率", + stateName: "hdfs_disk", + value: { + used: "${used}", + nonUsed: "${nonUsed}" + }, + type: "pie", + desc: "已使用: ${used} ${unit}
\ + 剩余: ${nonUsed} ${unit}
\ + 总共: ${total} ${unit}" }, - type: "pie", - desc: "已使用: ${used} ${unit}
\ - 剩余: ${nonUsed} ${unit}
\ - 总共: ${total} ${unit}" - }, - ] - },{ - title: "K8SP", - id: "k8s", - content: [ - { - name: "Pod个数", - stateName: "k8sp_pod", - value: "${lives} / ${total}", - desc: "正常: ${lives}
异常: ${dead}" - }, - { - name: "RC个数", - stateName: "k8sp_rc", - value: "${lives} / ${total}", - desc: "正常: ${lives}
异常: ${dead}" - }, - { - name: "Service状态", - stateName: "k8sp_service", - value: "${k8sp_service}", - desc: "${k8sp_service} 状态." - }, - { - name: "Node个数", - stateName: "k8sp_nodes", - value: "${lives} / ${total}", - desc: "正常: ${lives}
异常: ${dead}" - } + { + name: "HDFS分享个数", + value: "${hdfs_shares}", + stateName: "hdfs_shares", + desc: "${hdfs_shares} 个目录被分享." + }, + { + name: "DN存活状态", + stateName: "hdfs_datanodes", + value: "${lives} / ${total}", + desc: "健康: ${lives}
异常: ${dead}" + } ] - },{ - title: "BDMS", - id: "bdms", - content: [ - { - type: "pieSubarea", - name: "BDMS任务运行图:", - stateName: "bdms_task", - desc: " 待运行: ${waiting} 个
\ - 运行中: ${running} 个
\ - 运行成功: ${success} 个
\ - 运行失败: ${failed} 个
\ - 总任务: ${total} 个", - value: [ - { - name: "待运行", - value: "${waiting}", - }, - { - name: "运行中", - value: "${running}", - }, - { - name: "执行成功", - value: "${success}", - }, - { - name: "运行失败", - value: "${failed}", + },{ + title: "CODIS", + id: "codis", + content: [ + { + name: "Codis 集群", + stateName: "codis_cluster", + value: "${lives} / ${total}", + desc: "正常: ${lives}
\ + 异常: ${dead}" + }, + { + name: "Codis 内存使用率", + stateName: "codis_memory", + value: { + used: "${used}", + nonUsed: "${nonUsed}" }, - ] - } - ] - },{ - title: "OPENSTACK", - id: "openstack", - content: [ - { - name: "虚拟机状态", - stateName: "openstack_vm", - value: "${lives} / ${total}", - desc: "正常: ${lives}
异常: ${dead}", - }, - { - name: "镜像个数", - stateName: "openstack_image", - value: "${openstack_image}", - desc: "共保存了 ${openstack_image} 个镜像" - }, - { - name: "云硬盘个数", - stateName: "openstack_disk", - value: "${openstack_disk}", - desc: "共分配了 ${openstack_disk} 个磁盘" - } - ] - },{ - title: "用户", - id: "user", - content: [ - { - name: "成员个数", - stateName: "userAuth_member", - value: "${userAuth_member}", - desc: "当前空间共有 ${userAuth_member} 人" - }, - ] - }], + type: "pie", + desc: "已使用: ${used} ${unit}
\ + 剩余: ${nonUsed} ${unit}
\ + 总共: ${total} ${unit}" + }, + ] + },{ + title: "K8SP", + id: "k8s", + content: [ + { + name: "Pod个数", + stateName: "k8sp_pod", + value: "${lives} / ${total}", + desc: "正常: ${lives}
异常: ${dead}" + }, + { + name: "RC个数", + stateName: "k8sp_rc", + value: "${lives} / ${total}", + desc: "正常: ${lives}
异常: ${dead}" + }, + { + name: "Service状态", + stateName: "k8sp_service", + value: "${k8sp_service}", + desc: "${k8sp_service} 状态." + }, + { + name: "Node个数", + stateName: "k8sp_nodes", + value: "${lives} / ${total}", + desc: "正常: ${lives}
异常: ${dead}" + } + ] + },{ + title: "BDMS", + id: "bdms", + content: [ + { + type: "pieSubarea", + name: "BDMS任务运行图:", + stateName: "bdms_task", + desc: " 待运行: ${waiting} 个
\ + 运行中: ${running} 个
\ + 运行成功: ${success} 个
\ + 运行失败: ${failed} 个
\ + 总任务: ${total} 个", + value: [ + { + name: "待运行", + value: "${waiting}", + }, + { + name: "运行中", + value: "${running}", + }, + { + name: "执行成功", + value: "${success}", + }, + { + name: "运行失败", + value: "${failed}", + }, + ] + } + ] + },{ + title: "OPENSTACK", + id: "openstack", + content: [ + { + name: "虚拟机状态", + stateName: "openstack_vm", + value: "${lives} / ${total}", + desc: "正常: ${lives}
异常: ${dead}", + }, + { + name: "镜像个数", + stateName: "openstack_image", + value: "${openstack_image}", + desc: "共保存了 ${openstack_image} 个镜像" + }, + { + name: "云硬盘个数", + stateName: "openstack_disk", + value: "${openstack_disk}", + desc: "共分配了 ${openstack_disk} 个磁盘" + } + ] + },{ + title: "用户", + id: "user", + content: [ + { + name: "成员个数", + stateName: "userAuth_member", + value: "${userAuth_member}", + desc: "当前空间共有 ${userAuth_member} 人" + }, + ] + }] + }, //从location中获取cur_space getCurSpace(_this){ return conf.getCurSpace(_this); diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 7b16a9e..b85ee3e 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -10,6 +10,7 @@ import common from 'public/Template/Echarts/common' export default React.createClass({ getInitialState: function(){ + this.echartsMapping = {}; return { random: 0, hdfs_disk: { //hdfs磁盘 @@ -30,10 +31,10 @@ export default React.createClass({ total: 0, }, codis_memory: { - used: 1, + used: 0, nonUsed: 1, unit: "GB", - total: 2 + total: 1 }, k8sp_pod: { lives: 0, @@ -78,7 +79,7 @@ export default React.createClass({ if(cur_space== "" && type >0){ return
您还没有创建任何space.请先创建space
} - let data = OverviewConf.overviewData; + let data = OverviewConf.getOverviewData(); let overviewBody = data.map(function(item,index){ //渲染图表div. let cid = item.id; @@ -125,8 +126,9 @@ export default React.createClass({ return data; }, componentDidMount: function () { + console.log(this); //从模版中取数据渲染 - let data = OverviewConf.overviewData; + let data = OverviewConf.getOverviewData(); data.map(function(item,index){ //渲染图表div. let title = item.title; @@ -137,7 +139,11 @@ export default React.createClass({ if( type != undefined ){ let data = this.echartsData(type,item); let option = EchartsUtil.renderOptionData(type,data); - this.echartsMapping[index] = echarts.init(document.getElementById(id)).setOption(option); + let stateName = item.stateName + //存储echarts对象和指标的映射关系.方便后面的实时数据更新 + let echart = echarts.init(document.getElementById(id)); + echart.setOption(option); + this.echartsMapping[stateName] = echart; } },this); return content @@ -155,10 +161,37 @@ export default React.createClass({ this.requestArgs.random = this.state.random; return OverviewConf.getUrlData(this.requestArgs); }, + getConfItem(stateName){ + let itemData = null; + OverviewConf.getOverviewData().forEach(function(item,index){ + let content = item.content; + content.forEach(function(arr,index){ + if(arr.stateName == stateName){ + itemData = arr; + } + }); + }) + return itemData; + }, + /* + * 刷新 Echarts 图表数据 + */ + reloadEcharts(stateName,data){ + let item = this.getConfItem(stateName); + if(item == null){ + console.log(`未知的stateName:${stateName}`); + return ; + } + let type = item.type; + let value = common.tempPreHandler(item.value,data); + let echartsData = EchartsUtil.renderOptionData(type,value); + let echart = this.echartsMapping[stateName]; + echart.setOption(echartsData); + }, getBdmsData(data){ - let total = data.running + data.waiting + data.failed + data.success; - data["total"] = total; + data["total"] = data.running + data.waiting + data.failed + data.success; this.setState({ bdms_task: data}); + this.reloadEcharts("bdms_task",data); }, getK8spData(data){ this.setState({ k8sp_rc: data.rc, @@ -168,21 +201,33 @@ export default React.createClass({ }); }, getCodisData(data){ - this.setState({ codis_cluster: data.codis_cluster, - codis_memory: data.codis_memory + let codis_memory = data.codis_memory; + let codis_cluster = data.codis_cluster; + codis_cluster["total"] = codis_cluster.lives + codis_cluster.dead; + codis_memory["total"] = codis_memory.used + codis_memory.nonUsed; + this.setState({ codis_cluster: codis_cluster, + codis_memory: codis_memory }); + this.reloadEcharts("codis_memory",codis_memory); }, getOpenstackData(data){ + let openstack_vm = data.openstack_vm; + openstack_vm["total"] = openstack_vm.lives + openstack_vm.dead; this.setState({ openstack_disk: data.openstack_disk, openstack_image: data.openstack_image, openstack_vm: data.openstack_vm }); }, getHdfsData(data){ - this.setState({ hdfs_datanodes: data.hdfs_datanodes, - hdfs_disk: data.hdfs_disk, + let hdfs_disk = data.hdfs_disk; + let hdfs_datanodes = data.hdfs_datanodes; + hdfs_datanodes["total"] = hdfs_datanodes.lives + hdfs_datanodes.dead; + hdfs_disk["total"] = hdfs_disk.used + hdfs_disk.nonUsed; + this.setState({ hdfs_datanodes: hdfs_datanodes, + hdfs_disk: hdfs_disk, hdfs_shares: data.hdfs_shares }); + this.reloadEcharts("hdfs_disk",hdfs_disk); }, getUserAuthData(data){ this.setState({ userAuth_member: data.userAuth_member}); @@ -207,17 +252,18 @@ export default React.createClass({ let openstack_url = this.getUrlData({ type: "OPENSTACK_OVERVIEW", spaceName: spaceName }); + let content = this.index(); return (
- {this.index()} - {/* */} - + {content} - + {/* + + - + */}
) } From a2052f5535fdcd34846f2de2718389620137febb Mon Sep 17 00:00:00 2001 From: "zhijie.lv" <401379957@qq.com> Date: Thu, 1 Dec 2016 14:53:16 +0800 Subject: [PATCH 13/16] codis overview update --- Aries/codis/rests.py | 60 ++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/Aries/codis/rests.py b/Aries/codis/rests.py index b282d30..bf70f31 100644 --- a/Aries/codis/rests.py +++ b/Aries/codis/rests.py @@ -233,37 +233,7 @@ def post(self, request, format=None): "msg":"Error" } finally: - return packageResponse(result) - - -class CodisOverview(APIView): - ''' - 获取概览信息 - ''' - def get(self, request, format=None): - query_url = opentsdb_url + "/api/query/" - host_list = Host.objects.all() - allcodis_count = Codis.objects.all().count() - badcodis_count = 0 - memory_used_count = 0 - memory_total_count = 0 - for host in host_list: - memory_used_count += host.memory_used - memory_total_count += host.memory_total - badcodis_query_args = {"start":"6h-ago","end":"","queries":[{"metric":"codis.badcluster","aggregator": "sum",\ - "tags":{"bad":"true"}}]} - badcodis = requests.post(query_url,data=json.dumps(badcodis_query_args),timeout=10) - for k,v in json.loads(badcodis.text)[0]['dps'].items(): - badcodis_count = v - break - data = {"memory_used_count":memory_used_count,"memory_total_count":memory_total_count,\ - "all_codis_count":allcodis_count,"nice_codis_count":allcodis_count-badcodis_count} - result={ - "msg":"OK", - "code":200, - "data":data - } - return packageResponse(result) + return packageResponse(result) class CodisOverview(APIView): @@ -287,19 +257,37 @@ def get(self, request, format=None): for k,v in json.loads(badcodis.text)[0]['dps'].items(): badcodis_count = v break - data = {"memory_used_count":memory_used_count,"memory_total_count":memory_total_count,\ - "all_codis_count":allcodis_count,"nice_codis_count":allcodis_count-badcodis_count} + data = { + "codis_cluster": { + "lives": allcodis_count - badcodis_count, + "dead": badcodis_count, + }, + "codis_memory": { + "used": memory_used_count, + "nonUsed": memory_total_count - memory_used_count, + "unit": "GB", + } + } result={ "msg":"OK", "code":200, "data":data } except Exception, e: - data = {"memory_used_count": memory_used_count, "memory_total_count": memory_total_count, \ - "all_codis_count": allcodis_count, "nice_codis_count": allcodis_count - badcodis_count} + data = { + "codis_cluster": { + "lives": allcodis_count - badcodis_count, + "dead": badcodis_count, + }, + "codis_memory": { + "used": memory_used_count, + "nonUsed": memory_total_count - memory_used_count, + "unit": "GB", + } + } result = { "msg": "Error, error request from opentsdb", - "code": 200, + "code": 201, "data": data } ac_logger.error("Error, error request from opentsdb %s" % e) From 121eb5e855774ad27372ebbcd017396df6ac86cb Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Thu, 8 Dec 2016 14:07:57 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E6=89=93=E5=BC=80=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/functions/Overview/OverviewConf.js | 37 +------------------ .../Aries/src/functions/Overview/index.jsx | 8 +--- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index d20ba24..eaff6f9 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -68,8 +68,8 @@ const OverviewConf={ { name: "RC个数", stateName: "k8sp_rc", - value: "${lives} / ${total}", - desc: "正常: ${lives}
异常: ${dead}" + value: "${current} / ${desired}", + desc: "当前: ${current}
预期: ${desired}" }, { name: "Service状态", @@ -84,39 +84,6 @@ const OverviewConf={ desc: "正常: ${lives}
异常: ${dead}" } ] - },{ - title: "BDMS", - id: "bdms", - content: [ - { - type: "pieSubarea", - name: "BDMS任务运行图:", - stateName: "bdms_task", - desc: " 待运行: ${waiting} 个
\ - 运行中: ${running} 个
\ - 运行成功: ${success} 个
\ - 运行失败: ${failed} 个
\ - 总任务: ${total} 个", - value: [ - { - name: "待运行", - value: "${waiting}", - }, - { - name: "运行中", - value: "${running}", - }, - { - name: "执行成功", - value: "${success}", - }, - { - name: "运行失败", - value: "${failed}", - }, - ] - } - ] },{ title: "OPENSTACK", id: "openstack", diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index b85ee3e..6dc670e 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -42,9 +42,8 @@ export default React.createClass({ total: 0 }, k8sp_rc: { - lives: 0, - dead: 0, - total: 0 + current: 0, + desired: 0, }, k8sp_service: 0, //Service状态 k8sp_nodes: { @@ -258,12 +257,9 @@ export default React.createClass({ {content} - {/* - - */}
) } From 19fe115e77a2d47b56766ab49c6c8b634f9309b3 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Fri, 9 Dec 2016 15:07:39 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dk8s=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aries/src/functions/Overview/OverviewConf.js | 4 ++-- package/Aries/src/functions/Overview/index.jsx | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package/Aries/src/functions/Overview/OverviewConf.js b/package/Aries/src/functions/Overview/OverviewConf.js index eaff6f9..5dfbbe1 100644 --- a/package/Aries/src/functions/Overview/OverviewConf.js +++ b/package/Aries/src/functions/Overview/OverviewConf.js @@ -74,8 +74,8 @@ const OverviewConf={ { name: "Service状态", stateName: "k8sp_service", - value: "${k8sp_service}", - desc: "${k8sp_service} 状态." + value: "${count}", + desc: "${count} 状态." }, { name: "Node个数", diff --git a/package/Aries/src/functions/Overview/index.jsx b/package/Aries/src/functions/Overview/index.jsx index 6dc670e..aa2f83b 100644 --- a/package/Aries/src/functions/Overview/index.jsx +++ b/package/Aries/src/functions/Overview/index.jsx @@ -45,7 +45,9 @@ export default React.createClass({ current: 0, desired: 0, }, - k8sp_service: 0, //Service状态 + k8sp_service: { + count: 0 + }, //Service状态 k8sp_nodes: { lives: 0, dead: 0, @@ -193,10 +195,14 @@ export default React.createClass({ this.reloadEcharts("bdms_task",data); }, getK8spData(data){ - this.setState({ k8sp_rc: data.rc, - k8sp_pod: data.pod, - k8sp_nodes: data.node, - k8sp_service: data.service + let k8sp_pod = data.k8sp_pod; + k8sp_pod["total"] = k8sp_pod.lives + k8sp_pod.dead; + let k8sp_nodes = data.k8sp_nodes; + k8sp_nodes["total"] = k8sp_nodes.lives + k8sp_nodes.dead; + this.setState({ k8sp_rc: data.k8sp_rc, + k8sp_pod: k8sp_pod, + k8sp_nodes: k8sp_nodes, + k8sp_service: data.k8sp_service }); }, getCodisData(data){ From 287a316487c9ecc1604f3c9ce302d2e4deb0a586 Mon Sep 17 00:00:00 2001 From: LuPan2015 <874325293@qq.com> Date: Fri, 9 Dec 2016 17:55:19 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aries/hdfs/service.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Aries/hdfs/service.py b/Aries/hdfs/service.py index 2884295..be8856d 100644 --- a/Aries/hdfs/service.py +++ b/Aries/hdfs/service.py @@ -592,8 +592,6 @@ def getOverview(request): total, index, unit = unitTransform(total, 0, unitList) total = round(total, 2) used = round(used/math.pow(1024, index), 2) - print total - print used non_used = round(total - used, 2) hdfs_disk["used"] = used hdfs_disk["nonUsed"] = non_used