Skip to content

Commit c732865

Browse files
committed
Merge remote-tracking branch 'origin/4.14'
2 parents cb71774 + 578d29e commit c732865

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<cs.guava.version>28.2-jre</cs.guava.version>
135135
<cs.httpclient.version>4.5.11</cs.httpclient.version>
136136
<cs.httpcore.version>4.4.13</cs.httpcore.version>
137-
<cs.influxdb-java.version>2.17</cs.influxdb-java.version>
137+
<cs.influxdb-java.version>2.20</cs.influxdb-java.version>
138138
<cs.jackson.version>2.10.3</cs.jackson.version>
139139
<cs.jasypt.version>1.9.3</cs.jasypt.version>
140140
<cs.java-ipv6.version>0.17</cs.java-ipv6.version>

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,21 +1336,25 @@ abstract class AbstractStatsCollector extends ManagedContextRunnable {
13361336
protected void sendMetricsToInfluxdb(Map<Object, Object> metrics) {
13371337
InfluxDB influxDbConnection = createInfluxDbConnection();
13381338

1339-
Pong response = influxDbConnection.ping();
1340-
if (response.getVersion().equalsIgnoreCase("unknown")) {
1341-
throw new CloudRuntimeException(String.format("Cannot ping influxdb host %s:%s.", externalStatsHost, externalStatsPort));
1342-
}
1339+
try {
1340+
Pong response = influxDbConnection.ping();
1341+
if (response.getVersion().equalsIgnoreCase("unknown")) {
1342+
throw new CloudRuntimeException(String.format("Cannot ping influxdb host %s:%s.", externalStatsHost, externalStatsPort));
1343+
}
13431344

1344-
Collection<Object> metricsObjects = metrics.values();
1345-
List<Point> points = new ArrayList<>();
1345+
Collection<Object> metricsObjects = metrics.values();
1346+
List<Point> points = new ArrayList<>();
13461347

1347-
s_logger.debug(String.format("Sending stats to %s host %s:%s", externalStatsType, externalStatsHost, externalStatsPort));
1348+
s_logger.debug(String.format("Sending stats to %s host %s:%s", externalStatsType, externalStatsHost, externalStatsPort));
13481349

1349-
for (Object metricsObject : metricsObjects) {
1350-
Point vmPoint = creteInfluxDbPoint(metricsObject);
1351-
points.add(vmPoint);
1350+
for (Object metricsObject : metricsObjects) {
1351+
Point vmPoint = creteInfluxDbPoint(metricsObject);
1352+
points.add(vmPoint);
1353+
}
1354+
writeBatches(influxDbConnection, databaseName, points);
1355+
} finally {
1356+
influxDbConnection.close();
13521357
}
1353-
writeBatches(influxDbConnection, databaseName, points);
13541358
}
13551359

13561360
/**
@@ -1523,7 +1527,9 @@ protected InfluxDB createInfluxDbConnection() {
15231527
*/
15241528
protected void writeBatches(InfluxDB influxDbConnection, String dbName, List<Point> points) {
15251529
BatchPoints batchPoints = BatchPoints.database(dbName).build();
1526-
influxDbConnection.enableBatch(BatchOptions.DEFAULTS);
1530+
if(!influxDbConnection.isBatchEnabled()){
1531+
influxDbConnection.enableBatch(BatchOptions.DEFAULTS);
1532+
}
15271533

15281534
for (Point point : points) {
15291535
batchPoints.point(point);

0 commit comments

Comments
 (0)