Skip to content

Commit

Permalink
动态统计
Browse files Browse the repository at this point in the history
  • Loading branch information
adlered committed Nov 6, 2024
1 parent cb1c41c commit d49b9e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public static void register() {
Dispatcher.get("/admin/stats", adminProcessor::getStats, middlewares);
}

public static ChannelStatsManager manager = new ChannelStatsManager();
final public static ChannelStatsManager manager = new ChannelStatsManager();
public void getStats(final RequestContext context) {
JSONObject json = new JSONObject();
int c1 = ArticleListChannel.SESSIONS.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.b3log.symphony.processor.channel;

import java.text.DecimalFormat;
import java.util.concurrent.*;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -70,7 +71,10 @@ synchronized void addMessage(int messageSize) {
double getAverageBandwidth() {
long elapsedMillis = System.currentTimeMillis() - startTime.get();
if (elapsedMillis <= 0) return 0.0;
return (totalBytesSent.get() * 1000.0) / (elapsedMillis * 1024); // 转换为KB/s

double bandwidth = (totalBytesSent.get() * 1000.0) / (elapsedMillis * 1024); // 转换为KB/s
DecimalFormat df = new DecimalFormat("#.#####");
return Double.parseDouble(df.format(bandwidth));
}

long getMessageCount() {
Expand Down

0 comments on commit d49b9e8

Please sign in to comment.