zxl
2026-03-23 b924e4fe906c3e1b4e804ed9d073e09db76fc710
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<template>
  <a-skeleton active :loading="loading" :paragraph="{ rows: 17 }">
    <a-card :bordered="false">
      <a-alert type="info" :showIcon="true">
        <div slot="message">
          上次更新时间:{{ this.time }}
          <a-divider type="vertical" />
          <a @click="handleClickUpdate">立即更新</a>
        </div>
      </a-alert>
 
      <a-table
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="tableLoading"
        style="margin-top: 20px;"
      >
        <template slot="param" slot-scope="text">
          <a-tag color="green">{{ text }}</a-tag>
        </template>
 
        <template slot="value" slot-scope="text, record">
          <div v-if="text.length === 1">{{ text[0].value }}{{ record.unit }}</div>
          <template v-else>
            <div v-for="(item, index) in text" :key="index">
              {{ item.statistic }}: {{ item.value }} {{ item.statistic === 'TOTAL_TIME' ? record.unit : '' }}
            </div>
          </template>
        </template>
      </a-table>
    </a-card>
  </a-skeleton>
</template>
<script>
import moment from 'moment'
import { getAction } from '@tievd/cube-block/lib/api/manage'
 
moment.locale('zh-cn')
 
export default {
  name: 'ConnectionInfo',
 
  data() {
    return {
      time: '',
      loading: true,
      tableLoading: true,
      columns: [
        {
          title: '参数',
          width: '30%',
          dataIndex: 'param',
          scopedSlots: { customRender: 'param' }
        },
        {
          title: '描述',
          width: '40%',
          dataIndex: 'description'
          // scopedSlots: { customRender: 'text' }
        },
        {
          title: '当前值',
          width: '30%',
          dataIndex: 'value',
          scopedSlots: { customRender: 'value' }
        }
      ],
      dataSource: []
    }
  },
 
  mounted() {
    this.loadConnectionInfo()
  },
 
  methods: {
    handleClickUpdate() {
      this.loadConnectionInfo()
    },
    loadConnectionInfo() {
      this.tableLoading = true
      this.time = moment().format('YYYY年MM月DD日 HH时mm分ss秒')
      Promise.all([
        getAction('/actuator/metrics/hikaricp.connections'),
        getAction('/actuator/metrics/hikaricp.connections.acquire'),
        getAction('/actuator/metrics/hikaricp.connections.active'),
        getAction('/actuator/metrics/hikaricp.connections.creation'),
        getAction('/actuator/metrics/hikaricp.connections.idle'),
        getAction('/actuator/metrics/hikaricp.connections.max'),
        getAction('/actuator/metrics/hikaricp.connections.min'),
        getAction('/actuator/metrics/hikaricp.connections.pending'),
        getAction('/actuator/metrics/hikaricp.connections.timeout'),
        getAction('/actuator/metrics/hikaricp.connections.usage')
      ])
        .then(res => {
          let connectionInfo = []
          res.forEach((value, index) => {
            connectionInfo.push({
              id: value.name + index,
              param: value.name,
              description: value.description,
              value: value.measurements,
              unit: this.parseUnit(value.baseUnit)
            })
          })
          this.dataSource = connectionInfo
        })
        .catch(e => {
          console.error(e)
          this.$message.error('获取连接池信息失败')
        })
        .finally(() => {
          this.loading = false
          this.tableLoading = false
        })
    },
    parseUnit(unit) {
      switch (unit) {
        case 'seconds':
          unit = '秒'
          break
        default:
          unit = ''
          break
      }
      return unit
    }
  }
}
</script>
<style></style>