StatLogger.java
6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.cache.clustering.impl.CacheServiceClientStatistics
* com.scene7.is.cache.clustering.impl.CacheServiceClientStatisticsCounter
* com.scene7.is.cache.clustering.impl.CacheServiceClientStatisticsSnapshot
* com.scene7.is.cache.server.access.CacheServerAccessBean
* com.scene7.is.cacheserver.shared.CacheServerConnection
* com.scene7.is.util.Statistics
* com.scene7.is.util.StatisticsSnapshot
* com.scene7.is.util.diskcache.Cache
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider.logging;
import com.scene7.is.cache.clustering.impl.CacheServiceClientStatistics;
import com.scene7.is.cache.clustering.impl.CacheServiceClientStatisticsCounter;
import com.scene7.is.cache.clustering.impl.CacheServiceClientStatisticsSnapshot;
import com.scene7.is.cache.server.access.CacheServerAccessBean;
import com.scene7.is.cacheserver.shared.CacheServerConnection;
import com.scene7.is.util.Statistics;
import com.scene7.is.util.StatisticsSnapshot;
import com.scene7.is.util.diskcache.Cache;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
public class StatLogger
implements Runnable {
private static final Logger LOGGER = Logger.getLogger(StatLogger.class.getName());
private static final Runtime RUNTIME = Runtime.getRuntime();
private final List<Statistics> statistics;
private final Cache cache;
private final CacheServiceClientStatistics cacheServiceStats;
private final CacheServerAccessBean cacheServerAccessBean;
public StatLogger(@NotNull List<Statistics> statistics, @NotNull Cache cache, @NotNull CacheServiceClientStatistics cacheServiceStats, @NotNull CacheServerAccessBean cacheServerAccessBean) {
this.statistics = statistics;
this.cache = cache;
this.cacheServiceStats = cacheServiceStats;
this.cacheServerAccessBean = cacheServerAccessBean;
}
@Override
public void run() {
long currentTime = System.currentTimeMillis();
LOGGER.info("Memory: size: " + RUNTIME.totalMemory() + " free: " + RUNTIME.freeMemory());
LOGGER.info("Cache: size: " + this.cache.getSize() + " count: " + this.cache.getCount());
for (Statistics statistics : this.statistics) {
this.logStatistics(currentTime, statistics);
}
this.logCacheClusterStatistics();
this.logCacheServerStatistics();
}
private void logStatistics(long currentTime, @NotNull Statistics statistics) {
StatisticsSnapshot snapshot = statistics.getSnapshot(currentTime, true);
String statusDistribution = StatLogger.formatDistribution(snapshot.getStatusCounters());
String mimeTypeDistribution = StatLogger.formatDistribution(snapshot.getMimeTypeCounters());
String cacheUseDistribution = StatLogger.formatDistribution(snapshot.getCacheUseCounters());
LOGGER.info(statistics.getName() + " statistics: ");
LOGGER.info("Bytes served: total: " + snapshot.getTotalBytesServed() + " max: " + snapshot.getMaxBytesServed());
LOGGER.info("Request count: total : " + snapshot.getTotalRequestsServed() + " overlap: " + snapshot.getMaxRequestOverlap());
LOGGER.info("Request time: total: " + snapshot.getTotalRequestTime() + " max: " + snapshot.getMaxRequestTime() + " elapsed: " + snapshot.getElapsedTime() + " idle: " + snapshot.getTotalIdleTime());
if (statusDistribution.length() > 0) {
LOGGER.info("HTTP statuses: " + statusDistribution);
}
if (mimeTypeDistribution.length() > 0) {
LOGGER.info("Mime types : " + mimeTypeDistribution);
}
if (cacheUseDistribution.length() > 0) {
LOGGER.info("Cache use: " + cacheUseDistribution);
}
}
private static <T> String formatDistribution(Map<T, Long> counters) {
StringBuilder buffer = new StringBuilder();
for (Map.Entry<T, Long> entry : counters.entrySet()) {
buffer.append(entry.getKey()).append(": ").append(entry.getValue()).append(' ');
}
return buffer.toString();
}
private void logCacheClusterStatistics() {
CacheServiceClientStatisticsSnapshot snapshot = this.cacheServiceStats.getSnapshot(true);
String queryResponseDistribution = StatLogger.formatCacheClusterDistribution(snapshot.getQueryResponse());
String fetchMissDistribution = StatLogger.formatCacheClusterDistribution(snapshot.getFetchMiss());
String fetchHitDistribution = StatLogger.formatCacheClusterDistribution(snapshot.getFetchHit());
String fetchErrorDistribution = StatLogger.formatCacheClusterDistribution(snapshot.getFetchError());
LOGGER.info("Cache Cluster Client statistics: ");
LOGGER.info("Query broadcast count: total: " + snapshot.getTotalQueryBroadcasts());
LOGGER.info("Query responses: " + queryResponseDistribution);
LOGGER.info("Fetch count: total: " + snapshot.getTotalFetches());
LOGGER.info("Fetch hits: " + fetchHitDistribution);
LOGGER.info("Fetch misses: " + fetchMissDistribution);
LOGGER.info("Fetch errors: " + fetchErrorDistribution);
LOGGER.info("Timed out count: " + snapshot.getTotalTimedOut());
}
private static String formatCacheClusterDistribution(@NotNull CacheServiceClientStatisticsCounter counter) {
StringBuilder buffer = new StringBuilder();
buffer.append("count: ").append(counter.getCount());
buffer.append(" total: ").append(counter.getTotalTime());
buffer.append(" max: ").append(counter.getMaxTime());
return buffer.toString();
}
private void logCacheServerStatistics() {
List serverConnectionList = this.cacheServerAccessBean.getCacheServerListSnapshot(true);
LOGGER.info("Cache Server statistics:");
for (CacheServerConnection serverConnection : serverConnectionList) {
StringBuilder buffer = new StringBuilder();
buffer.append("server: ").append(serverConnection.getServerUrl());
buffer.append(" connections: ").append(serverConnection.getNumConnections());
buffer.append(" cache hits: ").append(serverConnection.getCacheHits());
buffer.append(" cache misses: ").append(serverConnection.getCacheMisses());
buffer.append(" cache creates: ").append(serverConnection.getCacheCreates());
LOGGER.info(buffer.toString());
}
}
}