-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(overview): move monitoring integration to a new module in co…
…nfig
- Loading branch information
1 parent
2131f35
commit 8f694c4
Showing
8 changed files
with
243 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
monitoringPlatform: { | ||
zh: '监控平台', | ||
en: 'Monitoring platform', | ||
}, | ||
monitoringPlatformFormItemLabel: { | ||
zh: '请选择需要更新配置的监控平台', | ||
en: 'Please select the monitoring platform for which you need to update the configuration', | ||
}, | ||
dataReportingInterval: { | ||
zh: '数据上报时间间隔', | ||
en: 'Data reporting interval', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<template> | ||
<div class="monitoring-integration app-wrapper"> | ||
<el-card class="config-card" v-loading="isDataLoading"> | ||
<el-row> | ||
<el-col :span="12"> | ||
<el-form label-position="top"> | ||
<el-form-item :label="tl('monitoringPlatformFormItemLabel')"> | ||
<el-radio-group class="platform-radio-group" v-model="selectedPlatform"> | ||
<el-row :gutter="28"> | ||
<el-col v-for="item in platformOpts" :key="item.label" :span="12"> | ||
<el-radio class="platform-radio-radio" :label="item.label" border> | ||
<img class="img-platform" height="52" :src="item.img" :alt="item.label" /> | ||
<span class="platform-name"> {{ item.label }} </span> | ||
</el-radio> | ||
</el-col> | ||
</el-row> | ||
</el-radio-group> | ||
</el-form-item> | ||
<template v-if="selectedPlatform === PROMETHEUS"> | ||
<el-form-item :label="t('Base.isEnabled')"> | ||
<el-switch v-model="prometheusFormData.enable" /> | ||
</el-form-item> | ||
<el-form-item label="Pushgateway Server"> | ||
<el-input v-model="prometheusFormData.push_gateway_server" /> | ||
</el-form-item> | ||
<el-form-item :label="tl('dataReportingInterval')"> | ||
<TimeInputWithUnitSelectVue v-model="prometheusFormData.interval" /> | ||
</el-form-item> | ||
</template> | ||
<template v-else> | ||
<el-form-item :label="t('Base.isEnabled')"> | ||
<el-switch v-model="statsDFormData.enable" /> | ||
</el-form-item> | ||
<el-form-item :label="t('Base.server')"> | ||
<el-input v-model="statsDFormData.server" /> | ||
</el-form-item> | ||
<el-form-item :label="tl('dataReportingInterval')"> | ||
<TimeInputWithUnitSelectVue v-model="statsDFormData.flush_time_interval" /> | ||
</el-form-item> | ||
</template> | ||
<el-button type="primary" :loading="isSubmitting" @click="submit"> | ||
{{ $t('Base.update') }} | ||
</el-button> | ||
</el-form> | ||
</el-col> | ||
</el-row> | ||
</el-card> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { getPrometheus, getStatsD, setPrometheus, setStatsD } from '@/api/common' | ||
import promImg from '@/assets/img/prom.png' | ||
import statsDImg from '@/assets/img/statsd.png' | ||
import TimeInputWithUnitSelectVue from '@/components/TimeInputWithUnitSelect.vue' | ||
import useI18nTl from '@/hooks/useI18nTl' | ||
import { Prometheus, StatsD } from '@/types/dashboard' | ||
import { ElMessage } from 'element-plus' | ||
import { ref, Ref } from 'vue' | ||
const PROMETHEUS = 'Prometheus' | ||
const STATS_D = 'StatsD' | ||
const { tl, t } = useI18nTl('MonitoringIntegration') | ||
const platformOpts = [ | ||
{ | ||
label: PROMETHEUS, | ||
value: PROMETHEUS, | ||
img: promImg, | ||
}, | ||
{ | ||
label: STATS_D, | ||
value: STATS_D, | ||
img: statsDImg, | ||
}, | ||
] | ||
const selectedPlatform = ref(platformOpts[0].value) | ||
const prometheusFormData: Ref<Prometheus> = ref({ | ||
enable: false, | ||
interval: '15s', | ||
push_gateway_server: '', | ||
}) | ||
const statsDFormData: Ref<StatsD> = ref({ | ||
enable: false, | ||
flush_time_interval: '10s', | ||
sample_time_interval: '10s', | ||
server: '', | ||
}) | ||
const isDataLoading = ref(false) | ||
const loadIntegration = async function () { | ||
isDataLoading.value = true | ||
let [prometheusRes, statsRes] = await Promise.allSettled([getPrometheus(), getStatsD()]) | ||
if (prometheusRes?.status == 'fulfilled') { | ||
prometheusFormData.value = prometheusRes.value | ||
} | ||
if (statsRes?.status == 'fulfilled') { | ||
statsDFormData.value = statsRes.value | ||
} | ||
isDataLoading.value = false | ||
} | ||
const isSubmitting = ref(false) | ||
const updatePrometheus = async function () { | ||
try { | ||
isSubmitting.value = true | ||
await setPrometheus(prometheusFormData.value) | ||
ElMessage.success(t('Base.updateSuccess')) | ||
} catch (error) { | ||
loadIntegration() | ||
} finally { | ||
isSubmitting.value = false | ||
} | ||
} | ||
const updateStatsD = async function () { | ||
try { | ||
isSubmitting.value = true | ||
await setStatsD(statsDFormData.value) | ||
ElMessage.success(t('Base.updateSuccess')) | ||
} catch (error) { | ||
loadIntegration() | ||
} finally { | ||
isSubmitting.value = false | ||
} | ||
} | ||
const submit = async () => { | ||
if (selectedPlatform.value === PROMETHEUS) { | ||
await updatePrometheus() | ||
} else { | ||
await updateStatsD() | ||
} | ||
} | ||
loadIntegration() | ||
</script> | ||
|
||
<style lang="scss"> | ||
.monitoring-integration { | ||
.platform-radio-group { | ||
width: 100%; | ||
.el-row { | ||
width: 80%; | ||
} | ||
} | ||
.platform-radio-radio { | ||
width: 100%; | ||
height: auto; | ||
.el-radio__input { | ||
display: none; | ||
} | ||
.el-radio__label { | ||
display: flex; | ||
align-items: center; | ||
padding-top: 8px; | ||
padding-bottom: 8px; | ||
} | ||
.img-platform { | ||
margin-right: 8px; | ||
} | ||
.platform-name { | ||
overflow: hidden; | ||
word-break: break-all; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
} | ||
</style> |
Oops, something went wrong.