refactor(系统设置): 系统参数设置下增加监控配置Tab
This commit is contained in:
parent
7b6de572b3
commit
195a715888
|
@ -0,0 +1,5 @@
|
||||||
|
package io.metersphere.commons.constants;
|
||||||
|
|
||||||
|
public class SystemParam {
|
||||||
|
public static final String PROMETHEUS_HOST = "prometheus.host";
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import io.metersphere.base.domain.SystemParameter;
|
||||||
import io.metersphere.base.domain.UserHeader;
|
import io.metersphere.base.domain.UserHeader;
|
||||||
import io.metersphere.commons.constants.ParamConstants;
|
import io.metersphere.commons.constants.ParamConstants;
|
||||||
import io.metersphere.commons.constants.RoleConstants;
|
import io.metersphere.commons.constants.RoleConstants;
|
||||||
|
import io.metersphere.commons.constants.SystemParam;
|
||||||
import io.metersphere.controller.request.HeaderRequest;
|
import io.metersphere.controller.request.HeaderRequest;
|
||||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||||
import io.metersphere.ldap.domain.LdapInfo;
|
import io.metersphere.ldap.domain.LdapInfo;
|
||||||
|
@ -56,6 +57,11 @@ public class SystemParameterController {
|
||||||
return SystemParameterService.getBaseInfo();
|
return SystemParameterService.getBaseInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/prometheus/host")
|
||||||
|
public String getPrometheusInfo() {
|
||||||
|
return SystemParameterService.getValue(SystemParam.PROMETHEUS_HOST);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/system/header")
|
@PostMapping("/system/header")
|
||||||
public SystemHeader getHeader(@RequestBody SystemHeader systemHeader) {
|
public SystemHeader getHeader(@RequestBody SystemHeader systemHeader) {
|
||||||
return SystemParameterService.getHeader(systemHeader.getType());
|
return SystemParameterService.getHeader(systemHeader.getType());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.base.domain.TestResource;
|
||||||
import io.metersphere.base.mapper.LoadTestMapper;
|
import io.metersphere.base.mapper.LoadTestMapper;
|
||||||
import io.metersphere.base.mapper.LoadTestReportMapper;
|
import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
|
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
|
||||||
|
import io.metersphere.commons.constants.SystemParam;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
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.controller.request.MetricRequest;
|
||||||
import io.metersphere.performance.dto.MetricData;
|
import io.metersphere.performance.dto.MetricData;
|
||||||
import io.metersphere.performance.dto.Monitor;
|
import io.metersphere.performance.dto.Monitor;
|
||||||
|
import io.metersphere.service.SystemParameterService;
|
||||||
import io.metersphere.service.TestResourceService;
|
import io.metersphere.service.TestResourceService;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
@ -38,7 +39,6 @@ import java.util.*;
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class MetricQueryService {
|
public class MetricQueryService {
|
||||||
|
|
||||||
@Value("${prometheus.host:http://127.0.0.1:9090}")
|
|
||||||
private String prometheusHost;
|
private String prometheusHost;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -53,9 +53,13 @@ public class MetricQueryService {
|
||||||
private ExtLoadTestReportMapper extLoadTestReportMapper;
|
private ExtLoadTestReportMapper extLoadTestReportMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestResourceService testResourceService;
|
private TestResourceService testResourceService;
|
||||||
|
@Resource
|
||||||
|
private SystemParameterService systemParameterService;
|
||||||
|
|
||||||
|
|
||||||
public List<MetricData> queryMetricData(MetricRequest metricRequest) {
|
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<>();
|
List<MetricData> metricDataList = new ArrayList<>();
|
||||||
long endTime = metricRequest.getEndTime();
|
long endTime = metricRequest.getEndTime();
|
||||||
long startTime = metricRequest.getStartTime();
|
long startTime = metricRequest.getStartTime();
|
||||||
|
|
|
@ -206,6 +206,11 @@ public class SystemParameterService {
|
||||||
return ldap;
|
return ldap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key System Param
|
||||||
|
* @return 系统key对应的值 | ""
|
||||||
|
*/
|
||||||
public String getValue(String key) {
|
public String getValue(String key) {
|
||||||
SystemParameter param = systemParameterMapper.selectByPrimaryKey(key);
|
SystemParameter param = systemParameterMapper.selectByPrimaryKey(key);
|
||||||
if (param == null || StringUtils.isBlank(param.getParamValue())) {
|
if (param == null || StringUtils.isBlank(param.getParamValue())) {
|
||||||
|
|
|
@ -192,6 +192,10 @@ VALUES ('metersphere.module.reportStat', 'ENABLE', 'text', 1);
|
||||||
INSERT INTO system_parameter (param_key, param_value, type, sort)
|
INSERT INTO system_parameter (param_key, param_value, type, sort)
|
||||||
VALUES ('metersphere.module.testTrack', 'ENABLE', 'text', 1);
|
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
|
alter table load_test_report
|
||||||
add max_users VARCHAR(10) null;
|
add max_users VARCHAR(10) null;
|
||||||
|
|
|
@ -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>
|
|
@ -11,6 +11,9 @@
|
||||||
<el-tab-pane :label="$t('system_parameter_setting.ldap_setting')" name="ldap">
|
<el-tab-pane :label="$t('system_parameter_setting.ldap_setting')" name="ldap">
|
||||||
<ldap-setting/>
|
<ldap-setting/>
|
||||||
</el-tab-pane>
|
</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">
|
<el-tab-pane v-if="hasLicense()" :label="$t('display.title')" name="display">
|
||||||
<ms-display/>
|
<ms-display/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
@ -29,6 +32,7 @@ import EmailSetting from "./EmailSetting";
|
||||||
import LdapSetting from "./LdapSetting";
|
import LdapSetting from "./LdapSetting";
|
||||||
import BaseSetting from "./BaseSetting";
|
import BaseSetting from "./BaseSetting";
|
||||||
import {hasLicense} from '@/common/js/utils';
|
import {hasLicense} from '@/common/js/utils';
|
||||||
|
import PrometheusSetting from "@/business/components/settings/system/PrometheusSetting";
|
||||||
|
|
||||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||||
const display = requireComponent.keys().length > 0 ? requireComponent("./display/Display.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 {
|
export default {
|
||||||
name: "SystemParameterSetting",
|
name: "SystemParameterSetting",
|
||||||
components: {
|
components: {
|
||||||
|
PrometheusSetting,
|
||||||
BaseSetting,
|
BaseSetting,
|
||||||
EmailSetting,
|
EmailSetting,
|
||||||
LdapSetting,
|
LdapSetting,
|
||||||
|
|
|
@ -253,6 +253,12 @@ export default {
|
||||||
url: 'Website URL',
|
url: 'Website URL',
|
||||||
url_tip: 'example:http://localhost:8081',
|
url_tip: 'example:http://localhost:8081',
|
||||||
url_is_null: 'The current site URL cannot be empty'
|
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: {
|
workspace: {
|
||||||
|
|
|
@ -255,6 +255,12 @@ export default {
|
||||||
url_tip: '例如:http://localhost:8081',
|
url_tip: '例如:http://localhost:8081',
|
||||||
url_is_null: '当前站点URL不能为空'
|
url_is_null: '当前站点URL不能为空'
|
||||||
},
|
},
|
||||||
|
prometheus_config: '监控配置',
|
||||||
|
prometheus: {
|
||||||
|
host: 'Prometheus地址',
|
||||||
|
host_tip: '例如:http://ms-prometheus:9090',
|
||||||
|
host_is_null: 'Prometheus地址不能为空'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
custom_field: {
|
custom_field: {
|
||||||
case_status: '用例状态',
|
case_status: '用例状态',
|
||||||
|
|
|
@ -254,6 +254,12 @@ export default {
|
||||||
url: '當前站點URL',
|
url: '當前站點URL',
|
||||||
url_tip: '例如:http://localhost:8081',
|
url_tip: '例如:http://localhost:8081',
|
||||||
url_is_null: '當前站點URL不能為空'
|
url_is_null: '當前站點URL不能為空'
|
||||||
|
},
|
||||||
|
prometheus_config: '監控配置',
|
||||||
|
prometheus: {
|
||||||
|
host: 'Prometheus地址',
|
||||||
|
host_tip: '例如:http://ms-prometheus:9090',
|
||||||
|
host_is_null: 'Prometheus地址不能為空'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
workspace: {
|
workspace: {
|
||||||
|
|
Loading…
Reference in New Issue