Skip to content

Commit

Permalink
Extend statistic functions.
Browse files Browse the repository at this point in the history
Enable to collect statistics without writing to the associated logger.
Deprecate active statistic logger, call dump externally enables to sync
several statistics in order to report them together.
Add net-socket statistic for dropped udp messages (unix only).

Signed-off-by: Achim Kraus <[email protected]>
  • Loading branch information
Achim Kraus committed Dec 17, 2021
1 parent 47c65a6 commit 389ebd3
Show file tree
Hide file tree
Showing 12 changed files with 1,130 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

/**
* Health implementation using counter and logging for result.
*
* @since 2.1
*/
public class HealthStatisticLogger extends CounterStatisticManager implements MessageInterceptor {
Expand Down Expand Up @@ -89,8 +90,11 @@ public HealthStatisticLogger(String tag, boolean udp) {
* @param executor executor executor to schedule active logging.
* @throws NullPointerException if executor is {@code null}
* @since 3.0 (added unit)
* @deprecated use {@link HealthStatisticLogger#HealthStatisticLogger(String, boolean)}
* instead and call {@link #dump()} externally.
*/
public HealthStatisticLogger(String tag, boolean udp, long interval, TimeUnit unit, ScheduledExecutorService executor) {
public HealthStatisticLogger(String tag, boolean udp, long interval, TimeUnit unit,
ScheduledExecutorService executor) {
super(tag, interval, unit, executor);
this.udp = udp;
init();
Expand All @@ -99,59 +103,69 @@ public HealthStatisticLogger(String tag, boolean udp, long interval, TimeUnit un
private void init() {
add("send-", sentRequests);
add("send-", sentResponses);
add("send-", sentAcknowledges);
add("send-", sentRejects);
add("send-", resentRequests);
add("send-", resentResponses);
if (udp) {
add("send-", sentAcknowledges);
add("send-", sentRejects);
add("send-", resentRequests);
add("send-", resentResponses);
}
add("send-", sendErrors);

add("recv-", receivedRequests);
add("recv-", receivedResponses);
add("recv-", receivedAcknowledges);
add("recv-", receivedRejects);
add("recv-", duplicateRequests);
add("recv-", duplicateResponses);
if (udp) {
add("recv-", receivedAcknowledges);
add("recv-", receivedRejects);
add("recv-", duplicateRequests);
add("recv-", duplicateResponses);
add("recv-", offloadedMessages);
}
add("recv-", ignoredMessages);
}

@Override
public boolean isEnabled() {
return LOGGER.isDebugEnabled();
return LOGGER.isInfoEnabled();
}

@Override
public void dump() {
try {
if (receivedRequests.isUsed() || sentRequests.isUsed() || sendErrors.isUsed()) {
String eol = StringUtil.lineSeparator();
String head = " " + tag;
StringBuilder log = new StringBuilder();
log.append(tag).append("endpoint statistic:").append(eol);
log.append(tag).append("send statistic:").append(eol);
log.append(head).append(sentRequests).append(eol);
log.append(head).append(sentResponses).append(eol);
if (udp) {
log.append(head).append(sentAcknowledges).append(eol);
log.append(head).append(sentRejects).append(eol);
log.append(head).append(resentRequests).append(eol);
log.append(head).append(resentResponses).append(eol);
}
log.append(head).append(sendErrors).append(eol);
log.append(tag).append("receive statistic:").append(eol);
log.append(head).append(receivedRequests).append(eol);
log.append(head).append(receivedResponses).append(eol);
if (udp) {
log.append(head).append(receivedAcknowledges).append(eol);
log.append(head).append(receivedRejects).append(eol);
log.append(head).append(duplicateRequests).append(eol);
log.append(head).append(duplicateResponses).append(eol);
log.append(head).append(offloadedMessages).append(eol);
if (isEnabled()) {
if (LOGGER.isDebugEnabled()) {
if (receivedRequests.isUsed() || sentRequests.isUsed() || sendErrors.isUsed()) {
String eol = StringUtil.lineSeparator();
String head = " " + tag;
StringBuilder log = new StringBuilder();
log.append(tag).append("endpoint statistic:").append(eol);
log.append(tag).append("send statistic:").append(eol);
log.append(head).append(sentRequests).append(eol);
log.append(head).append(sentResponses).append(eol);
if (udp) {
log.append(head).append(sentAcknowledges).append(eol);
log.append(head).append(sentRejects).append(eol);
log.append(head).append(resentRequests).append(eol);
log.append(head).append(resentResponses).append(eol);
}
log.append(head).append(sendErrors).append(eol);
log.append(tag).append("receive statistic:").append(eol);
log.append(head).append(receivedRequests).append(eol);
log.append(head).append(receivedResponses).append(eol);
if (udp) {
log.append(head).append(receivedAcknowledges).append(eol);
log.append(head).append(receivedRejects).append(eol);
log.append(head).append(duplicateRequests).append(eol);
log.append(head).append(duplicateResponses).append(eol);
log.append(head).append(offloadedMessages).append(eol);
}
log.append(head).append(ignoredMessages).append(eol);
long sent = getSentCounters();
long processed = getProcessedCounters();
log.append(tag).append("sent ").append(sent).append(", received ").append(processed);
LOGGER.debug("{}", log);
}
}
log.append(head).append(ignoredMessages).append(eol);
long sent = getSentCounters();
long processed = getProcessedCounters();
log.append(tag).append("sent ").append(sent).append(", received ").append(processed);
LOGGER.debug("{}", log);
transferCounter();
}
} catch (Throwable e) {
LOGGER.error("{}", tag, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.TimeUnit;

import org.eclipse.californium.core.coap.Response;
import org.eclipse.californium.core.network.interceptors.HealthStatisticLogger;
import org.eclipse.californium.elements.util.CounterStatisticManager;
import org.eclipse.californium.elements.util.SimpleCounterStatistic;
import org.eclipse.californium.elements.util.StringUtil;
Expand All @@ -40,6 +41,19 @@ public class CongestionStatisticLogger extends CounterStatisticManager {
private final SimpleCounterStatistic dequeueRequests = new SimpleCounterStatistic("dequeue-requests", align);
private final SimpleCounterStatistic receivedResponses = new SimpleCounterStatistic("recv-responses", align);

/**
* Create passive congestion logger.
*
* {@link #dump()} must be called externally.
*
* @param tag logging tag
* @since 3.1
*/
public CongestionStatisticLogger(String tag) {
super(tag);
init();
}

/**
* Create active congestion logger.
*
Expand All @@ -51,6 +65,8 @@ public class CongestionStatisticLogger extends CounterStatisticManager {
* @param unit time unit of interval
* @throws NullPointerException if executor is {@code null}
* @since 3.0 (added unit)
* @deprecated use {@link HealthStatisticLogger#HealthStatisticLogger(String, boolean)}
* instead and call {@link #dump()} externally.
*/
public CongestionStatisticLogger(String tag, int interval, TimeUnit unit, ScheduledExecutorService executor) {
super(tag, interval, unit, executor);
Expand All @@ -65,22 +81,27 @@ private void init() {

@Override
public boolean isEnabled() {
return LOGGER.isDebugEnabled();
return LOGGER.isInfoEnabled();
}

@Override
public void dump() {
try {
if (receivedResponses.isUsed() || sentRequests.isUsed() || queueRequests.isUsed()) {
String eol = StringUtil.lineSeparator();
String head = " " + tag;
StringBuilder log = new StringBuilder();
log.append(tag).append("congestion statistic:").append(eol);
log.append(head).append(sentRequests).append(eol);
log.append(head).append(queueRequests).append(eol);
log.append(head).append(dequeueRequests).append(eol);
log.append(head).append(receivedResponses).append(eol);
LOGGER.debug("{}", log);
if (isEnabled()) {
if (LOGGER.isDebugEnabled()) {
if (receivedResponses.isUsed() || sentRequests.isUsed() || queueRequests.isUsed()) {
String eol = StringUtil.lineSeparator();
String head = " " + tag;
StringBuilder log = new StringBuilder();
log.append(tag).append("congestion statistic:").append(eol);
log.append(head).append(sentRequests).append(eol);
log.append(head).append(queueRequests).append(eol);
log.append(head).append(dequeueRequests).append(eol);
log.append(head).append(receivedResponses).append(eol);
LOGGER.debug("{}", log);
}
}
transferCounter();
}
} catch (Throwable e) {
LOGGER.error("{}", tag, e);
Expand Down
Loading

0 comments on commit 389ebd3

Please sign in to comment.