Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to collection of statistics #270

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
}
18 changes: 15 additions & 3 deletions 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 Expand Up @@ -375,7 +387,7 @@ public static void addUpdateToDatabase( String ipAddress, String product, String
}
catch ( Exception e )
{
Log.warn( "Unable to retrieve info", e );
Log.warn( "Unable to retrieve location info for {}", ipAddress, e );
}

pstmt.setString( 1, ipAddress );
Expand All @@ -391,7 +403,7 @@ public static void addUpdateToDatabase( String ipAddress, String product, String
}
catch ( Exception e )
{
Log.warn( "Unable to process download information for " + ipAddress, e );
Log.warn( "Unable to process download information for {} {} {} {} {} {}", ipAddress, product, version, fileType, fileName, downloadInfo, e );
}
finally
{
Expand Down
Loading