Skip to content

Commit

Permalink
refactor(overview): move monitoring integration to a new module in co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
Kinplemelon committed Jul 1, 2022
1 parent 2131f35 commit 8f694c4
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export function loadChartData(time: number): Promise<Array<ChartDataItem>> {
}

//metrics integration
export function getStatsd(): Promise<StatsD> {
export function getStatsD(): Promise<StatsD> {
return http.get('/statsd')
}

export function setStatsd(body: StatsD): Promise<StatsD> {
export function setStatsD(body: StatsD): Promise<StatsD> {
return http.put('/statsd', body)
}

Expand Down
14 changes: 14 additions & 0 deletions src/i18n/MonitoringIntegration.js
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',
},
}
4 changes: 4 additions & 0 deletions src/i18n/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,8 @@ export default {
zh: '保留消息',
en: 'Retainer',
},
'monitoring-integration': {
zh: '监控集成',
en: 'Monitoring Integration',
},
}
79 changes: 48 additions & 31 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Login from '@/views/Base/Login.vue'
import store from '@/store'
import Layout from '@/views/Base/Layout.vue'
import KeepAliveChildren from '@/views/Base/KeepAliveChildren.vue'
import Overview from '@/views/Dashboard/Overview.vue'
import Nodes from '@/views/Dashboard/Nodes.vue'
import NodeDetail from '@/views/Dashboard/NodeDetail.vue'
import Metrics from '@/views/Dashboard/Metrics.vue'
import Alarm from '@/views/Alarm/Alarm.vue'
import TopicMetrics from '@/views/Diagnose/TopicMetrics.vue'
import Websocket from '@/views/Diagnose/WebSocket.vue'
import SlowSub from '@/views/Diagnose/SlowSub.vue'
import SlowSubConfig from '@/views/Diagnose/SlowSubConfig.vue'
import LogTrace from '@/views/Diagnose/LogTrace/LogTrace.vue'
import LogTraceDetail from '@/views/Diagnose/LogTrace/LogTraceDetail.vue'
import Clients from '@/views/Clients/Clients.vue'
import KeepAliveChildren from '@/views/Base/KeepAliveChildren.vue'
import Layout from '@/views/Base/Layout.vue'
import Login from '@/views/Base/Login.vue'
import ClientDetails from '@/views/Clients/ClientDetails.vue'
import Topics from '@/views/Topics/Topics.vue'
import Subscriptions from '@/views/Subscriptions/Subscriptions.vue'
import Clients from '@/views/Clients/Clients.vue'
import Advanced from '@/views/Config/Advanced/Advanced.vue'
import Mqtt from '@/views/Config/BasicConfig/Mqtt.vue'
import Session from '@/views/Config/BasicConfig/Session.vue'
import MonitoringIntegration from '@/views/Config/MonitoringIntegration.vue'
import Metrics from '@/views/Dashboard/Metrics.vue'
import NodeDetail from '@/views/Dashboard/NodeDetail.vue'
import Nodes from '@/views/Dashboard/Nodes.vue'
import Overview from '@/views/Dashboard/Overview.vue'
import LogTrace from '@/views/Diagnose/LogTrace/LogTrace.vue'
import LogTraceDetail from '@/views/Diagnose/LogTrace/LogTraceDetail.vue'
import SlowSub from '@/views/Diagnose/SlowSub.vue'
import SlowSubConfig from '@/views/Diagnose/SlowSubConfig.vue'
import TopicMetrics from '@/views/Diagnose/TopicMetrics.vue'
import Websocket from '@/views/Diagnose/WebSocket.vue'
import Subscriptions from '@/views/Subscriptions/Subscriptions.vue'
import Topics from '@/views/Topics/Topics.vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
// import Cluster from '@/views/Config/BasicConfig/Cluster.vue'
import Retainer from '@/views/Config/BasicConfig/Retainer.vue'
import Log from '@/views/Config/BasicConfig/Log.vue'
import Retainer from '@/views/Config/BasicConfig/Retainer.vue'
// import Limiter from '@/views/Config/BasicConfig/Limiter.vue'
// import Dashboard from '@/views/Config/BasicConfig/Dashboard.vue'
import Users from '@/views/General/Users.vue'
import Blacklist from '@/views/General/Blacklist.vue'
import Gateway from '@/views/Gateway/Gateway.vue'
import GatewayDetail from '@/views/Gateway/GatewayDetail.vue'
import GatewayDetailBasic from '@/views/Gateway/components/basic.vue'
import GatewayDetailListener from '@/views/Gateway/components/listeners.vue'
import GatewayDetailAuth from '@/views/Gateway/components/auth.vue'
import GatewayDetailBasic from '@/views/Gateway/components/basic.vue'
import GatewayDetailClients from '@/views/Gateway/components/clients.vue'
import GatewayDetailListener from '@/views/Gateway/components/listeners.vue'
import Gateway from '@/views/Gateway/Gateway.vue'
import GatewayCreate from '@/views/Gateway/GatewayCreate.vue'
import GatewayDetail from '@/views/Gateway/GatewayDetail.vue'
import Blacklist from '@/views/General/Blacklist.vue'
import Users from '@/views/General/Users.vue'
import BridgeCreate from '@/views/RuleEngine/Bridge/BridgeCreate.vue'
import BridgeDetail from '@/views/RuleEngine/Bridge/BridgeDetail.vue'
import Bridge from '@/views/RuleEngine/Bridge/DataBridge.vue'
import IoT from '@/views/RuleEngine/IoT/IoT.vue'
import IoTCreate from '@/views/RuleEngine/IoT/IoTCreate.vue'
import IoTDetail from '@/views/RuleEngine/IoT/IoTDetail.vue'
import Bridge from '@/views/RuleEngine/Bridge/DataBridge.vue'
import BridgeCreate from '@/views/RuleEngine/Bridge/BridgeCreate.vue'
import BridgeDetail from '@/views/RuleEngine/Bridge/BridgeDetail.vue'
// import Connector from '@/views/RuleEngine/Connector/Connector.vue'
// import ConnectorCreate from '@/views/RuleEngine/Connector/ConnectorCreate.vue'
import FlowChart from '@/views/RuleEngine/FlowChart/FlowChart.vue'
import APIKey from '@/views/APIKey/APIKey.vue'
import Plugins from '@/views/Plugins/Plugins.vue'
import PluginInstall from '@/views/Plugins/PluginInstall.vue'
import PluginDetail from '@/views/Plugins/PluginDetail.vue'
import Exhook from '@/views/Exhook/Exhook.vue'
import ExhookCreate from '@/views/Exhook/ExhookCreate.vue'
import ExhookDetail from '@/views/Exhook/ExhookDetail.vue'
import Listener from '@/views/Listener/Listener.vue'
import PluginDetail from '@/views/Plugins/PluginDetail.vue'
import PluginInstall from '@/views/Plugins/PluginInstall.vue'
import Plugins from '@/views/Plugins/Plugins.vue'
import FlowChart from '@/views/RuleEngine/FlowChart/FlowChart.vue'
import Settings from '@/views/Settings/Settings.vue'

export const routes: Array<RouteRecordRaw> = [
Expand Down Expand Up @@ -559,6 +560,22 @@ export const routes: Array<RouteRecordRaw> = [
// },
// ],
// },
// Monitoring integration
{
path: '/monitoring-integration',
component: Layout,
meta: {
hideKey: 'monitoring-integration',
authRequired: true,
},
children: [
{
path: '',
name: 'monitoring-integration',
component: MonitoringIntegration,
},
],
},
// Flow chart for IoT rule
{
path: '/flow',
Expand Down
4 changes: 4 additions & 0 deletions src/views/Base/LeftBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export default defineComponent({
title: 'log',
path: '/log',
},
{
title: 'monitoring-integration',
path: '/monitoring-integration',
},
]
menus.value = [
Expand Down
171 changes: 171 additions & 0 deletions src/views/Config/MonitoringIntegration.vue
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>
Loading

0 comments on commit 8f694c4

Please sign in to comment.