• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9654

pending completion
#9654

push

travis_ci

web-flow
[IOTDB-6073] Add ClientManager metrics (#10617)

279 of 279 new or added lines in 8 files covered. (100.0%)

79121 of 165733 relevant lines covered (47.74%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.31
/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManagerMetrics.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.commons.client;
21

22
import org.apache.iotdb.commons.service.metric.enums.Metric;
23
import org.apache.iotdb.commons.service.metric.enums.Tag;
24
import org.apache.iotdb.metrics.AbstractMetricService;
25
import org.apache.iotdb.metrics.metricsets.IMetricSet;
26
import org.apache.iotdb.metrics.utils.MetricLevel;
27
import org.apache.iotdb.metrics.utils.MetricType;
28

29
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
30

31
import java.util.HashMap;
32
import java.util.Map;
33

34
public class ClientManagerMetrics implements IMetricSet {
35
  private static final String CLIENT_MANAGER_NUM_ACTIVE = "client_manager_num_active";
36
  private static final String CLIENT_MANAGER_NUM_IDLE = "client_manager_num_idle";
37
  private static final String CLIENT_MANAGER_BORROWED_COUNT = "client_manager_borrowed_count";
38
  private static final String CLIENT_MANAGER_CREATED_COUNT = "client_manager_created_count";
39
  private static final String CLIENT_MANAGER_DESTROYED_COUNT = "client_manager_destroyed_count";
40
  private static final String MEAN_ACTIVE_TIME_MILLIS = "client_manager_mean_active_time";
41
  private static final String MEAN_BORROW_WAIT_TIME_MILLIS = "client_manager_mean_borrow_wait_time";
42
  private static final String MEAN_IDLE_TIME_MILLIS = "client_manager_mean_idle_time";
43

44
  private final Map<String, GenericKeyedObjectPool<?, ?>> poolMap = new HashMap<>();
1✔
45
  private AbstractMetricService metricService;
46

47
  private static class ClientManagerMetricsHolder {
48
    private static final ClientManagerMetrics INSTANCE = new ClientManagerMetrics();
1✔
49

50
    private ClientManagerMetricsHolder() {}
51
  }
52

53
  public static ClientManagerMetrics getInstance() {
54
    return ClientManagerMetrics.ClientManagerMetricsHolder.INSTANCE;
1✔
55
  }
56

57
  private ClientManagerMetrics() {
1✔
58
    // empty constructor
59
  }
1✔
60

61
  public void registerClientManager(String poolName, GenericKeyedObjectPool<?, ?> clientPool) {
62
    synchronized (this) {
1✔
63
      if (metricService == null) {
1✔
64
        poolMap.put(poolName, clientPool);
1✔
65
      } else {
66
        if (!poolMap.containsKey(poolName)) {
×
67
          poolMap.put(poolName, clientPool);
×
68
          createMetrics(poolName);
×
69
        }
70
      }
71
    }
1✔
72
  }
1✔
73

74
  @Override
75
  public void bindTo(AbstractMetricService metricService) {
76
    this.metricService = metricService;
×
77
    synchronized (this) {
×
78
      for (String poolName : poolMap.keySet()) {
×
79
        createMetrics(poolName);
×
80
      }
×
81
    }
×
82
  }
×
83

84
  private void createMetrics(String poolName) {
85
    metricService.createAutoGauge(
×
86
        Metric.CLIENT_MANAGER.toString(),
×
87
        MetricLevel.IMPORTANT,
88
        poolMap,
89
        map -> poolMap.get(poolName).getNumActive(),
×
90
        Tag.NAME.toString(),
×
91
        CLIENT_MANAGER_NUM_ACTIVE,
92
        Tag.TYPE.toString(),
×
93
        poolName);
94
    metricService.createAutoGauge(
×
95
        Metric.CLIENT_MANAGER.toString(),
×
96
        MetricLevel.IMPORTANT,
97
        poolMap,
98
        map -> poolMap.get(poolName).getNumIdle(),
×
99
        Tag.NAME.toString(),
×
100
        CLIENT_MANAGER_NUM_IDLE,
101
        Tag.TYPE.toString(),
×
102
        poolName);
103
    metricService.createAutoGauge(
×
104
        Metric.CLIENT_MANAGER.toString(),
×
105
        MetricLevel.IMPORTANT,
106
        poolMap,
107
        map -> poolMap.get(poolName).getBorrowedCount(),
×
108
        Tag.NAME.toString(),
×
109
        CLIENT_MANAGER_BORROWED_COUNT,
110
        Tag.TYPE.toString(),
×
111
        poolName);
112
    metricService.createAutoGauge(
×
113
        Metric.CLIENT_MANAGER.toString(),
×
114
        MetricLevel.IMPORTANT,
115
        poolMap,
116
        map -> poolMap.get(poolName).getCreatedCount(),
×
117
        Tag.NAME.toString(),
×
118
        CLIENT_MANAGER_CREATED_COUNT,
119
        Tag.TYPE.toString(),
×
120
        poolName);
121
    metricService.createAutoGauge(
×
122
        Metric.CLIENT_MANAGER.toString(),
×
123
        MetricLevel.IMPORTANT,
124
        poolMap,
125
        map -> poolMap.get(poolName).getDestroyedCount(),
×
126
        Tag.NAME.toString(),
×
127
        CLIENT_MANAGER_DESTROYED_COUNT,
128
        Tag.TYPE.toString(),
×
129
        poolName);
130
    metricService.createAutoGauge(
×
131
        Metric.CLIENT_MANAGER.toString(),
×
132
        MetricLevel.IMPORTANT,
133
        poolMap,
134
        map -> poolMap.get(poolName).getMeanActiveTimeMillis(),
×
135
        Tag.NAME.toString(),
×
136
        MEAN_ACTIVE_TIME_MILLIS,
137
        Tag.TYPE.toString(),
×
138
        poolName);
139
    metricService.createAutoGauge(
×
140
        Metric.CLIENT_MANAGER.toString(),
×
141
        MetricLevel.IMPORTANT,
142
        poolMap,
143
        map -> poolMap.get(poolName).getMeanBorrowWaitTimeMillis(),
×
144
        Tag.NAME.toString(),
×
145
        MEAN_BORROW_WAIT_TIME_MILLIS,
146
        Tag.TYPE.toString(),
×
147
        poolName);
148
    metricService.createAutoGauge(
×
149
        Metric.CLIENT_MANAGER.toString(),
×
150
        MetricLevel.IMPORTANT,
151
        poolMap,
152
        map -> poolMap.get(poolName).getMeanIdleTimeMillis(),
×
153
        Tag.NAME.toString(),
×
154
        MEAN_IDLE_TIME_MILLIS,
155
        Tag.TYPE.toString(),
×
156
        poolName);
157
  }
×
158

159
  @Override
160
  public void unbindFrom(AbstractMetricService metricService) {
161
    for (String poolName : poolMap.keySet()) {
×
162
      metricService.remove(
×
163
          MetricType.GAUGE,
164
          Metric.CLIENT_MANAGER.toString(),
×
165
          Tag.NAME.toString(),
×
166
          CLIENT_MANAGER_NUM_ACTIVE,
167
          Tag.TYPE.toString(),
×
168
          poolName);
169
      metricService.remove(
×
170
          MetricType.GAUGE,
171
          Metric.CLIENT_MANAGER.toString(),
×
172
          Tag.NAME.toString(),
×
173
          CLIENT_MANAGER_NUM_IDLE,
174
          Tag.TYPE.toString(),
×
175
          poolName);
176
      metricService.remove(
×
177
          MetricType.GAUGE,
178
          Metric.CLIENT_MANAGER.toString(),
×
179
          Tag.NAME.toString(),
×
180
          CLIENT_MANAGER_BORROWED_COUNT,
181
          Tag.TYPE.toString(),
×
182
          poolName);
183
      metricService.remove(
×
184
          MetricType.GAUGE,
185
          Metric.CLIENT_MANAGER.toString(),
×
186
          Tag.NAME.toString(),
×
187
          CLIENT_MANAGER_CREATED_COUNT,
188
          Tag.TYPE.toString(),
×
189
          poolName);
190
      metricService.remove(
×
191
          MetricType.GAUGE,
192
          Metric.CLIENT_MANAGER.toString(),
×
193
          Tag.NAME.toString(),
×
194
          CLIENT_MANAGER_DESTROYED_COUNT,
195
          Tag.TYPE.toString(),
×
196
          poolName);
197
      metricService.remove(
×
198
          MetricType.GAUGE,
199
          Metric.CLIENT_MANAGER.toString(),
×
200
          Tag.NAME.toString(),
×
201
          MEAN_ACTIVE_TIME_MILLIS,
202
          Tag.TYPE.toString(),
×
203
          poolName);
204
      metricService.remove(
×
205
          MetricType.GAUGE,
206
          Metric.CLIENT_MANAGER.toString(),
×
207
          Tag.NAME.toString(),
×
208
          MEAN_BORROW_WAIT_TIME_MILLIS,
209
          Tag.TYPE.toString(),
×
210
          poolName);
211
      metricService.remove(
×
212
          MetricType.GAUGE,
213
          Metric.CLIENT_MANAGER.toString(),
×
214
          Tag.NAME.toString(),
×
215
          MEAN_IDLE_TIME_MILLIS,
216
          Tag.TYPE.toString(),
×
217
          poolName);
218
    }
×
219
    poolMap.clear();
×
220
  }
×
221
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc