diff --git a/nezha-fronted/src/components/common/language/en.js b/nezha-fronted/src/components/common/language/en.js index 49c654ff1..055d9f278 100644 --- a/nezha-fronted/src/components/common/language/en.js +++ b/nezha-fronted/src/components/common/language/en.js @@ -30,7 +30,9 @@ const en = { select: 'Select',//'选择' ok: 'Ok',//OK all: 'All',//'全选' - other: 'Others'//"其他" + other: 'Others',//"其他" + query: 'Query', //查询 + back: 'Back' //返回 }, dashboard:{ title:'Dashboard', @@ -418,7 +420,11 @@ const en = { path: 'Path',//"路径" asset: 'Device',//"设备" lastUpdate: 'Last update time',//"最后更新时间" - moduleParameter: 'Module parameter'//"组件参数" + moduleParameter: 'Module parameter',//"组件参数" + addGraph: 'Add Graph', //添加图标 + element: 'Element', + value: 'Value', + promExpr: 'Please input expression' }, metrics: { metrics: 'Metrics',//"指标" diff --git a/nezha-fronted/src/components/page/project/project.vue b/nezha-fronted/src/components/page/project/project.vue index d780af684..a9c1afc00 100644 --- a/nezha-fronted/src/components/page/project/project.vue +++ b/nezha-fronted/src/components/page/project/project.vue @@ -112,8 +112,14 @@   {{$t('overall.edit')}}    +   {{$t('overall.view')}} + class="nz-icon nz-icon-view">  {{$t('overall.view')}} + + + +  {{$t('overall.query')}} + {{dateFormat(scope.row.lastUpdate)}} {{scope.row.state == 1 ? 'up' : ''}}{{scope.row.state == 0 ? 'down' : ''}} @@ -124,6 +130,65 @@ + +
+
+ + +
+ + + + +
+
+ +
+
+ + + + + + + + + +
+ + @@ -183,7 +248,7 @@ label: this.$t('config.account.option'), prop: 'option', show: true, - width: 140 + width: 200 } ], endpointTableData: [], @@ -251,6 +316,11 @@ }], }, viewAssetState:false, + curEndpoint:null, + endpointQueryTabData:[],//endpoint 查询列表数据 + queryExpression:'', + metricList: [], // metric列表 + formatTime:'',//查询endpoint的时间 } }, methods: { @@ -383,6 +453,7 @@ this.endpointSearchLabel = {moduleId: ''}; this.metricSearchLabel = {moduleId: ''}; this.$refs.projectSearch.clearSearch(); + this.tableShow=1; }, //弹出endpoint编辑页 @@ -430,7 +501,6 @@ this.$refs['assetEditUnit'].tabView = false } }, - //搜索 endpointSearch: function(searchObj) { this.endpointSearchLabel = {}; @@ -507,12 +577,109 @@ this.viewAssetState=true; this.$refs.assetEditUnit.getAssetData(id); this.$refs.assetEditUnit.tabView=true; - } + }, + showEndpoint:function(endpoint){ + if(endpoint){ + this.curEndpoint=endpoint; + this.formatTime=''; + } + this.endpointQueryTabData=[]; + this.$get("/prom/api/v1/query?query={job='ed_"+this.curEndpoint.id+"'}&time="+this.formatTime).then(response=>{ + if(response.status==="success"){ + let results=response.data.result; + for (let result of results){ + // {"metric":{"instance":"192.168.40.126:9100","__name__":"scrape_duration_seconds","module":"node_exporter","project":"kafka","asset":"192.168.40.126","job":"ed_1","dc":"dc5"},"value":[1580782176.522,"0.000560761"]} + let temp=result.metric.__name__; + delete result.metric.__name__; + temp+=JSON.stringify(result.metric); + let edpQueryData={element:temp,value:result.value[1]} + this.endpointQueryTabData.push(edpQueryData); + } + this.tableShow=3; + } + }) + }, + changeTime:function(size,unit){ + let time=this.getTime(size,unit); + this.formatTime=time; + this.showEndpoint(); + }, + pickTime:function(){ + console.log(this.formatTime) + this.showEndpoint(); + }, + getTime:function(size,unit){//计算时间 + let now=!this.formatTime? new Date():new Date(this.formatTime); + if(unit){ + switch (unit) { + case 'y': + now.setFullYear(now.getFullYear()+size); + break; + case 'M': + now.setMonth(now.getMonth()+size); + break; + case 'd': + now.setDate(now.getDate()+size); + break; + case 'h': + now.setHours(now.getHours()+size); + break; + case 'm': + now.setMinutes(now.getMinutes()+size); + break; + case 's': + now.setSeconds(now.getSeconds()+size); + break; + default: + console.error('unit error'); + } + }else{ + now.setSeconds(now.getSeconds()+size); + } + let year=now.getFullYear(); + let month=now.getMonth()+1; + month=month<10?"0"+month:month; + let day=now.getDate(); + day=day<10?"0"+day:day; + let hour=now.getHours(); + hour=hour<10?"0"+hour:hour; + let minute=now.getMinutes(); + minute=minute<10?"0"+minute:minute; + let second=now.getSeconds(); + second=second<10?"0"+second:second; + let current=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second; + return current; + }, + querySearch(queryString, cb) { + let metricList=this.metricList; + // 调用 callback 返回建议列表的数据 + let results=queryString?metricList.filter(this.createFilter(queryString)):metricList; + cb(results) + }, + createFilter(queryString) { + return (metric) => { + return (metric.metric.toLowerCase().indexOf(queryString.toLowerCase()) != -1); + }; + }, + handleSelect(item) { + console.log(item); + }, + // 获取metric列表 + getSuggestMetric() { + this.$get('metric', {pageNo: 1, pageSize: -1}).then(response => { + if (response.code === 200) { + this.metricList = response.data.list; + }else { + this.metricList = []; + } + }) + }, }, created() { this.currentProject = this.$store.state.currentProject; this.getModuleList(); this.getMetricsTableData(); + this.getSuggestMetric(); }, mounted() { setTimeout(()=>{