mirror of
https://github.com/corda/corda.git
synced 2025-04-15 06:56:59 +00:00
ENT-2500: Improve formatting when no traffic flown through Bridge. (#1447)
Without this change the following output can be observed: ``` ... Traffic breakdown: Successful connections in: Successful connections out: Failed connections in: Failed connections out: Accepted packets in: Accepted packets out: Dropped packets in: Dropped packets out: ```
This commit is contained in:
parent
f94aedec25
commit
95de18b1ca
@ -11,6 +11,7 @@ import net.corda.nodeapi.internal.protonwrapper.messages.ApplicationMessage
|
||||
import net.corda.nodeapi.internal.protonwrapper.messages.ReceivedMessage
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.net.InetSocketAddress
|
||||
import java.text.DecimalFormat
|
||||
import java.text.NumberFormat
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
@ -35,6 +36,14 @@ class LoggingFirewallAuditService(val conf: FirewallConfiguration,
|
||||
val leftPad = "\t".repeat(tabsCount)
|
||||
return entries.joinToString(separator = "\n") { entry -> leftPad + entry.key.toString() + " -> " + nf.format(entry.value.get())}
|
||||
}
|
||||
|
||||
private fun <K> Map<K, AtomicLong>.whenNonEmptyPrint(block: Map<K, AtomicLong>.() -> String): String {
|
||||
return if(this.isEmpty()) {
|
||||
""
|
||||
} else {
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val loggingIntervalSec = conf.auditServiceConfiguration.loggingIntervalSec
|
||||
@ -151,7 +160,8 @@ class LoggingFirewallAuditService(val conf: FirewallConfiguration,
|
||||
|
||||
val operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean()
|
||||
val loadAverage = operatingSystemMXBean.systemLoadAverage
|
||||
val loadAverageStr = if(loadAverage < 0) "N/A" else "${loadAverage * 100}%"
|
||||
val df = DecimalFormat("#.##")
|
||||
val loadAverageStr = if(loadAverage < 0) "N/A" else "${df.format(loadAverage * 100)}%"
|
||||
|
||||
val runtime = Runtime.getRuntime()
|
||||
val freeMemory = runtime.freeMemory().toMB()
|
||||
@ -184,15 +194,15 @@ class LoggingFirewallAuditService(val conf: FirewallConfiguration,
|
||||
"${nf.format(dirStatsOut.accepted.mapValues { it.value.second }.sumValues())}(outgoing)\n" +
|
||||
"\tPackets dropped count: ${nf.format(dirStatsIn.droppedPacketsCount.sumValues())}(inbound), ${nf.format(dirStatsOut.droppedPacketsCount.sumValues())}(outgoing)"
|
||||
|
||||
val breakDownTrafficStr = "Traffic breakdown:\n" +
|
||||
"\tSuccessful connections in:\n${dirStatsIn.successfulConnectionCount.prettyPrint(2, nf)}\n" +
|
||||
"\tSuccessful connections out:\n${dirStatsOut.successfulConnectionCount.prettyPrint(2, nf)}\n" +
|
||||
"\tFailed connections in:\n${dirStatsIn.failedConnectionCount.prettyPrint(2, nf)}\n" +
|
||||
"\tFailed connections out:\n${dirStatsOut.failedConnectionCount.prettyPrint(2, nf)}\n" +
|
||||
"\tAccepted packets in:\n${inAcceptedPackets.prettyPrint(2, nf)}\n" +
|
||||
"\tAccepted packets out:\n${outAcceptedPackets.prettyPrint(2, nf)}\n" +
|
||||
"\tDropped packets in:\n${dirStatsIn.droppedPacketsCount.prettyPrint(2, nf)}\n" +
|
||||
"\tDropped packets out:\n${dirStatsOut.droppedPacketsCount.prettyPrint(2, nf)}"
|
||||
val breakDownTrafficStr = "Traffic breakdown:\n" +
|
||||
dirStatsIn.successfulConnectionCount.whenNonEmptyPrint { "\tSuccessful connections in:\n${prettyPrint(2, nf)}\n" } +
|
||||
dirStatsOut.successfulConnectionCount.whenNonEmptyPrint { "\tSuccessful connections out:\n${prettyPrint(2, nf)}\n" } +
|
||||
dirStatsIn.failedConnectionCount.whenNonEmptyPrint { "\tFailed connections in:\n${prettyPrint(2, nf)}\n" } +
|
||||
dirStatsOut.failedConnectionCount.whenNonEmptyPrint { "\tFailed connections out:\n${prettyPrint(2, nf)}\n" } +
|
||||
inAcceptedPackets.whenNonEmptyPrint { "\tAccepted packets in:\n${prettyPrint(2, nf)}\n" } +
|
||||
outAcceptedPackets.whenNonEmptyPrint { "\tAccepted packets out:\n${prettyPrint(2, nf)}\n" } +
|
||||
dirStatsIn.droppedPacketsCount.whenNonEmptyPrint { "\tDropped packets in:\n${prettyPrint(2, nf)}\n" } +
|
||||
dirStatsOut.droppedPacketsCount.whenNonEmptyPrint { "\tDropped packets out:\n${prettyPrint(2, nf)}" }
|
||||
|
||||
return durationStr + "\n" + runtimeStr + "\n" + trafficTotalsStr + "\n" + breakDownTrafficStr
|
||||
}
|
||||
|
@ -84,19 +84,23 @@ class LoggingFirewallAuditServiceTest {
|
||||
instance.packetAcceptedEvent(it.createMessage(direction), direction)
|
||||
}
|
||||
|
||||
val statsStr = instance.prepareStatsAndReset()
|
||||
assertThat(statsStr, containsSubstring("Successful connection count: 13(inbound), 27(outgoing)"))
|
||||
assertThat(statsStr, containsSubstring("Failed connection count: 2(inbound), 5(outgoing)"))
|
||||
assertThat(statsStr, containsSubstring("Packets accepted count: 3,000(inbound), 6,000(outgoing)"))
|
||||
assertThat(statsStr, containsSubstring("Bytes transmitted: 60,000(inbound), 120,000(outgoing)"))
|
||||
assertThat(statsStr, containsSubstring("Packets dropped count: 6(inbound), 14(outgoing)"))
|
||||
assertThat(statsStr, containsSubstring("Failed connections out:"))
|
||||
assertThat(statsStr, containsSubstring("Server5:10001 -> 1"))
|
||||
with(instance.prepareStatsAndReset()) {
|
||||
assertThat(this, containsSubstring("Successful connection count: 13(inbound), 27(outgoing)"))
|
||||
assertThat(this, containsSubstring("Failed connection count: 2(inbound), 5(outgoing)"))
|
||||
assertThat(this, containsSubstring("Packets accepted count: 3,000(inbound), 6,000(outgoing)"))
|
||||
assertThat(this, containsSubstring("Bytes transmitted: 60,000(inbound), 120,000(outgoing)"))
|
||||
assertThat(this, containsSubstring("Packets dropped count: 6(inbound), 14(outgoing)"))
|
||||
assertThat(this, containsSubstring("Failed connections out:"))
|
||||
assertThat(this, containsSubstring("Server5:10001 -> 1"))
|
||||
}
|
||||
|
||||
// Ensure reset stats
|
||||
val statsStr2 = instance.prepareStatsAndReset()
|
||||
assertThat(statsStr2, containsSubstring("Successful connection count: 0"))
|
||||
assertThat(statsStr2, containsSubstring("Packets dropped count: 0(inbound), 0(outgoing)"))
|
||||
with(instance.prepareStatsAndReset()) {
|
||||
assertThat(this, containsSubstring("Successful connection count: 0"))
|
||||
assertThat(this, containsSubstring("Packets dropped count: 0(inbound), 0(outgoing)"))
|
||||
assertThat(this, containsSubstring("Failed connections out:").not())
|
||||
assertThat(this, containsSubstring("Accepted packets out:").not())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user