Skip to content

Commit

Permalink
Add logging to collection of statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
guusdk committed Sep 19, 2024
1 parent 231d3f1 commit 471c13c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/main/java/org/jivesoftware/site/DiscourseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
Expand Down Expand Up @@ -105,7 +107,7 @@ private synchronized static void collectTotals() {
try {
collectorThread.join();
}
catch (Exception e) { Log.debug( "An exception occurred that can probably be ignored.", e); }
catch (Exception e) { Log.info( "An exception occurred while collecting Discourse stats.", e); }
}
}

Expand All @@ -117,6 +119,9 @@ public DownloadStatsRunnable(Map<Integer, Long> counts) {
}

public void run() {
Log.info("Retrieving Discourse statistics...");

Instant start = Instant.now();
final Map<Integer, Long> results = new HashMap<>();
final Long a = doSimpleQuery(3, 7);
if (a != null) {
Expand All @@ -126,10 +131,14 @@ public void run() {
if (b != null) {
results.put(4, b);
}
Log.debug("Queried all Discourse stats in {}", Duration.between(start, Instant.now()));

// Replace all values in the object used by the website in one go.
counts.clear();
counts.putAll(results);

Log.debug("Retrieved Discourse statistics:");
results.forEach((key, value) -> Log.debug("- {} : {}", key, value));
}
}
}
14 changes: 13 additions & 1 deletion src/main/java/org/jivesoftware/site/DownloadStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Types;
import java.time.Duration;
import java.time.Instant;
import java.util.Hashtable;
import java.util.Map;

Expand Down Expand Up @@ -176,7 +178,7 @@ private synchronized static void collectTotals() {
try {
collectorThread.join();
}
catch (Exception e) { Log.debug( "An exception occurred that can probably be ignored.", e); }
catch (Exception e) { Log.info( "An exception occurred while collecting download stats.", e); }
}
}

Expand All @@ -188,6 +190,8 @@ public DownloadStatsRunnable(Map<String, Long> counts) {
}

public void run() {
Log.info("Retrieving downloads statistics...");

final DbConnectionManager connectionManager = DbConnectionManager.getInstance();
Connection con = null;
PreparedStatement pstmt = null;
Expand All @@ -197,6 +201,8 @@ public void run() {
long total = 0L;
try {
con = connectionManager.getConnection();

Instant start = Instant.now();
pstmt = con.prepareStatement(COUNT_TOTAL_DOWNLOADS_BY_TYPE);
rs = pstmt.executeQuery();

Expand Down Expand Up @@ -243,18 +249,24 @@ public void run() {

rs.close();
pstmt.close();
Log.debug("Queried all download stats in {}", Duration.between(start, Instant.now()));

start = Instant.now();
pstmt = con.prepareStatement(COUNT_TOTAL_DOWNLOADS_LAST_7_DAYS);
rs = pstmt.executeQuery();
long lastDays = 0L;
if (rs.next()) {
lastDays = rs.getLong(1);
}
results.put(TOTAL7DAYS, lastDays);
Log.debug("Queried last 7 days download stats in {}", Duration.between(start, Instant.now()));

// Replace all values in the object used by the website in one go.
counts.clear();
counts.putAll(results);

Log.debug("Retrieved downloads statistics:");
results.forEach((key, value) -> Log.debug("- {} : {}", key, value));
} catch (Exception e) {
Log.warn("Error counting downloads.", e);
}
Expand Down

0 comments on commit 471c13c

Please sign in to comment.