Skip to content

Commit f39b02a

Browse files
Use long instead of int in DB statistics for Queries and Uptime. (#7125)
Co-authored-by: Wei Zhou <weizhou@apache.org>
1 parent e8c1b55 commit f39b02a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,8 @@ public DbMetricsResponse listDbMetrics() {
807807
private void getQueryHistory(DbMetricsResponse response) {
808808
Map<String, Object> dbStats = ApiDBUtils.getDbStatistics();
809809
if (dbStats != null) {
810-
response.setQueries((Integer)dbStats.get(DbStatsCollection.queries));
811-
response.setUptime((Integer)dbStats.get(DbStatsCollection.uptime));
810+
response.setQueries((Long)dbStats.get(DbStatsCollection.queries));
811+
response.setUptime((Long)dbStats.get(DbStatsCollection.uptime));
812812
}
813813

814814
List<Double> loadHistory = (List<Double>) dbStats.get(DbStatsCollection.loadAvarages);

plugins/metrics/src/main/java/org/apache/cloudstack/response/DbMetricsResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DbMetricsResponse extends BaseResponse {
4343

4444
@SerializedName(MetricConstants.UPTIME)
4545
@Param(description = "the uptime of the DB in seconds")
46-
private int uptime;
46+
private long uptime;
4747

4848
@SerializedName(MetricConstants.TLS_VERSIONS)
4949
@Param(description = "the tls versions currently in use (accepted) by the DB")
@@ -59,7 +59,7 @@ public class DbMetricsResponse extends BaseResponse {
5959

6060
@SerializedName(MetricConstants.QUERIES)
6161
@Param(description = "the number of queries performed on the DB")
62-
private int queries;
62+
private long queries;
6363

6464
@SerializedName(MetricConstants.DATABASE_LOAD_AVERAGES)
6565
@Param(description = "the last measured load averages on the DB")
@@ -77,7 +77,7 @@ public void setConnections(int connections) {
7777
this.connections = connections;
7878
}
7979

80-
public void setUptime(int uptime) {
80+
public void setUptime(long uptime) {
8181
this.uptime = uptime;
8282
}
8383

@@ -93,7 +93,7 @@ public void setVersionComment(String versionComment) {
9393
this.versionComment = versionComment;
9494
}
9595

96-
public void setQueries(int queries) {
96+
public void setQueries(long queries) {
9797
this.queries = queries;
9898
}
9999

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,11 @@ protected void runInContext() {
714714
LOGGER.debug(String.format("%s is running...", this.getClass().getSimpleName()));
715715

716716
try {
717-
int lastUptime = (dbStats.containsKey(uptime) ? (Integer) dbStats.get(uptime) : 0);
718-
int lastQueries = (dbStats.containsKey(queries) ? (Integer) dbStats.get(queries) : 0);
717+
long lastUptime = (dbStats.containsKey(uptime) ? (Long) dbStats.get(uptime) : 0);
718+
long lastQueries = (dbStats.containsKey(queries) ? (Long) dbStats.get(queries) : 0);
719719
getDynamicDataFromDB();
720-
int interval = (Integer) dbStats.get(uptime) - lastUptime;
721-
int activity = (Integer) dbStats.get(queries) - lastQueries;
720+
long interval = (Long) dbStats.get(uptime) - lastUptime;
721+
long activity = (Long) dbStats.get(queries) - lastQueries;
722722
loadHistory.add(0, Double.valueOf(activity / interval));
723723
int maxsize = DATABASE_SERVER_LOAD_HISTORY_RETENTION_NUMBER.value();
724724
while (loadHistory.size() > maxsize) {
@@ -736,8 +736,8 @@ protected void runInContext() {
736736
private void getDynamicDataFromDB() {
737737
Map<String, String> stats = DbUtil.getDbInfo("STATUS", queries, uptime);
738738
dbStats.put(collectionTime, new Date());
739-
dbStats.put(queries, (Integer.valueOf(stats.get(queries))));
740-
dbStats.put(uptime, (Integer.valueOf(stats.get(uptime))));
739+
dbStats.put(queries, (Long.valueOf(stats.get(queries))));
740+
dbStats.put(uptime, (Long.valueOf(stats.get(uptime))));
741741
}
742742

743743

0 commit comments

Comments
 (0)