refactor(系统设置): 系统参数设置下增加监控配置Tab

This commit is contained in:
shiziyuan9527 2021-04-19 17:15:30 +08:00 committed by 刘瑞斌
parent 7b6de572b3
commit 195a715888
10 changed files with 159 additions and 2 deletions

View File

@ -0,0 +1,5 @@
package io.metersphere.commons.constants;
public class SystemParam {
public static final String PROMETHEUS_HOST = "prometheus.host";
}

View File

@ -5,6 +5,7 @@ import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.domain.UserHeader;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.constants.SystemParam;
import io.metersphere.controller.request.HeaderRequest;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.ldap.domain.LdapInfo;
@ -56,6 +57,11 @@ public class SystemParameterController {
return SystemParameterService.getBaseInfo();
}
@GetMapping("/prometheus/host")
public String getPrometheusInfo() {
return SystemParameterService.getValue(SystemParam.PROMETHEUS_HOST);
}
@PostMapping("/system/header")
public SystemHeader getHeader(@RequestBody SystemHeader systemHeader) {
return SystemParameterService.getHeader(systemHeader.getType());

View File

@ -11,6 +11,7 @@ import io.metersphere.base.domain.TestResource;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.SystemParam;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.DateUtils;
import io.metersphere.commons.utils.LogUtil;
@ -22,9 +23,9 @@ import io.metersphere.performance.controller.request.MetricQuery;
import io.metersphere.performance.controller.request.MetricRequest;
import io.metersphere.performance.dto.MetricData;
import io.metersphere.performance.dto.Monitor;
import io.metersphere.service.SystemParameterService;
import io.metersphere.service.TestResourceService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
@ -38,7 +39,6 @@ import java.util.*;
@Transactional(rollbackFor = Exception.class)
public class MetricQueryService {
@Value("${prometheus.host:http://127.0.0.1:9090}")
private String prometheusHost;
@Resource
@ -53,9 +53,13 @@ public class MetricQueryService {
private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource
private TestResourceService testResourceService;
@Resource
private SystemParameterService systemParameterService;
public List<MetricData> queryMetricData(MetricRequest metricRequest) {
String host = systemParameterService.getValue(SystemParam.PROMETHEUS_HOST);
prometheusHost = StringUtils.isNotBlank(host) ? host : "http://ms-prometheus:9090";
List<MetricData> metricDataList = new ArrayList<>();
long endTime = metricRequest.getEndTime();
long startTime = metricRequest.getStartTime();

View File

@ -206,6 +206,11 @@ public class SystemParameterService {
return ldap;
}
/**
* @param key System Param
* @return 系统key对应的值 ""
*/
public String getValue(String key) {
SystemParameter param = systemParameterMapper.selectByPrimaryKey(key);
if (param == null || StringUtils.isBlank(param.getParamValue())) {

View File

@ -192,6 +192,10 @@ VALUES ('metersphere.module.reportStat', 'ENABLE', 'text', 1);
INSERT INTO system_parameter (param_key, param_value, type, sort)
VALUES ('metersphere.module.testTrack', 'ENABLE', 'text', 1);
-- init prometheus host
INSERT INTO system_parameter (param_key, param_value, type, sort)
VALUES ('prometheus.host', 'http://ms-prometheus:9090', 'text', 1);
-- 报告新增的字段
alter table load_test_report
add max_users VARCHAR(10) null;

View File

@ -0,0 +1,110 @@
<template>
<div v-loading="result.loading">
<el-form :model="formInline" :rules="rules" ref="formInline" class="demo-form-inline"
:disabled="show" v-loading="loading" size="small">
<el-row>
<el-col>
<el-form-item :label="$t('system_config.prometheus.host')" prop="host">
<el-input v-model="formInline.host" :placeholder="$t('system_config.prometheus.host_tip')"/>
<i>({{ $t('commons.examples') }}:http://ms-prometheus:9090)</i>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div>
<el-button @click="edit" v-if="showEdit" size="small">{{ $t('commons.edit') }}</el-button>
<el-button type="success" @click="save('formInline')" v-if="showSave" :disabled="disabledSave" size="small">
{{ $t('commons.save') }}
</el-button>
<el-button @click="cancel" type="info" v-if="showCancel" size="small">{{ $t('commons.cancel') }}</el-button>
</div>
</div>
</template>
<script>
export default {
name: "PrometheusSetting",
data() {
return {
formInline: {host: ''},
input: '',
visible: true,
result: {},
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledSave: false,
loading: false,
rules: {
host: [
{
required: true,
message: this.$t('system_config.prometheus.host_is_null'),
trigger: ['change', 'blur']
},
],
}
}
},
created() {
this.query()
},
methods: {
query() {
this.result = this.$get("/system/prometheus/host", response => {
this.formInline.host = response.data;
this.$nextTick(() => {
this.$refs.formInline.clearValidate();
})
})
},
edit() {
this.showEdit = false;
this.showSave = true;
this.showCancel = true;
this.show = false;
},
save(formInline) {
this.showEdit = true;
this.showCancel = false;
this.showSave = false;
this.show = true;
let param = [
{paramKey: "prometheus.host", paramValue: this.formInline.host, type: "text", sort: 1},
];
this.$refs[formInline].validate(valid => {
if (valid) {
this.result = this.$post("/system/save/base", param, response => {
if (response.success) {
this.$success(this.$t('commons.save_success'));
} else {
this.$message.error(this.$t('commons.save_failed'));
}
});
} else {
return false;
}
})
},
cancel() {
this.showEdit = true;
this.showCancel = false;
this.showSave = false;
this.show = true;
this.query();
}
}
}
</script>
<style scoped>
.el-form {
min-height: 300px;
}
</style>

View File

@ -11,6 +11,9 @@
<el-tab-pane :label="$t('system_parameter_setting.ldap_setting')" name="ldap">
<ldap-setting/>
</el-tab-pane>
<el-tab-pane :label="$t('system_config.prometheus_config')" name="prometheus">
<prometheus-setting/>
</el-tab-pane>
<el-tab-pane v-if="hasLicense()" :label="$t('display.title')" name="display">
<ms-display/>
</el-tab-pane>
@ -29,6 +32,7 @@ import EmailSetting from "./EmailSetting";
import LdapSetting from "./LdapSetting";
import BaseSetting from "./BaseSetting";
import {hasLicense} from '@/common/js/utils';
import PrometheusSetting from "@/business/components/settings/system/PrometheusSetting";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const display = requireComponent.keys().length > 0 ? requireComponent("./display/Display.vue") : {};
@ -38,6 +42,7 @@ const module = requireComponent.keys().length > 0 ? requireComponent("./module/M
export default {
name: "SystemParameterSetting",
components: {
PrometheusSetting,
BaseSetting,
EmailSetting,
LdapSetting,

View File

@ -253,6 +253,12 @@ export default {
url: 'Website URL',
url_tip: 'examplehttp://localhost:8081',
url_is_null: 'The current site URL cannot be empty'
},
prometheus_config: 'Prometheus Host',
prometheus: {
host: 'Prometheus Host',
host_tip: 'example: http://ms-prometheus:9090',
host_is_null: 'Prometheus Host cannot be empty'
}
},
workspace: {

View File

@ -255,6 +255,12 @@ export default {
url_tip: '例如http://localhost:8081',
url_is_null: '当前站点URL不能为空'
},
prometheus_config: '监控配置',
prometheus: {
host: 'Prometheus地址',
host_tip: '例如:http://ms-prometheus:9090',
host_is_null: 'Prometheus地址不能为空'
}
},
custom_field: {
case_status: '用例状态',

View File

@ -254,6 +254,12 @@ export default {
url: '當前站點URL',
url_tip: '例如http://localhost:8081',
url_is_null: '當前站點URL不能為空'
},
prometheus_config: '監控配置',
prometheus: {
host: 'Prometheus地址',
host_tip: '例如:http://ms-prometheus:9090',
host_is_null: 'Prometheus地址不能為空'
}
},
workspace: {