Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit cb17c7e

Browse files
committed
Export protocol name for all protocols known to .NET Core
1 parent 4db6ab2 commit cb17c7e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ Example Prometheus scrape configuration:
4040
4141
Only IPv4 packets are analyzed - IPv6 is ignored.
4242
43-
Only TCP and UDP are analyzed - other transport-level protocols are simply "unknown".
44-
4543
# How do I analyze multiple parallel packet streams?
4644
4745
You can direct multiple TZSP streams to the same analyzer, either on the same port or separate ports (using multiple `--listen-port` options). The output metrics carry a label indicating the listen port the data arrived on.

TzspPacketStreamExporter/ExporterLogic.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Net;
8+
using System.Net.Sockets;
89
using System.Text;
910
using System.Threading;
1011
using System.Threading.Tasks;
@@ -349,12 +350,10 @@ private static void ProcessTzspPacket(byte[] packet, ushort listenPort)
349350
// unknown protocol
350351
}
351352

352-
string protocolName = protocol switch
353-
{
354-
6 => "tcp",
355-
17 => "udp",
356-
_ => "unknown"
357-
};
353+
string protocolName = "unknown";
354+
355+
if (Enum.IsDefined(typeof(ProtocolType), (int)protocol))
356+
protocolName = ((ProtocolType)protocol).ToString().ToLowerInvariant();
358357

359358
BytesBase.WithLabels(sourceAddressString, sourceAddressType, destinationAddressString, destinationAddressType, protocolName, listenPort.ToString()).Inc(totalPacketLengthIncludingIpHeader);
360359
PacketsBase.WithLabels(sourceAddressString, sourceAddressType, destinationAddressString, destinationAddressType, protocolName, listenPort.ToString()).Inc();

0 commit comments

Comments
 (0)