Skip to content

Commit

Permalink
Adds initial performance counters
Browse files Browse the repository at this point in the history
  • Loading branch information
ryannewington committed Nov 17, 2016
1 parent 47cc7c7 commit efb9c14
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Lithnet.Pan.RAProxy.Setup/Components.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
Interactive="no">
</ServiceInstall>
<ServiceControl Id="ServiceControlEvents" Name="[SERVICE_NAME]" Start="install" Stop="both" Remove="uninstall" Wait="yes"/>

<util:PerformanceCategory Id="PerformanceCounter" Name="PANRAProxy" DefaultLanguage="english">
<util:PerformanceCounter Name="Requests in queue" Type="numberOfItems32" Help="Shows the number of requests in the queue that are waiting to be sent to the firewall"/>
<util:PerformanceCounter Name="Requests received / second" Type="rateOfCountsPerSecond32" Help="Shows the number of account requests receieved per second"/>
<util:PerformanceCounter Name="Requests sent / second" Type="rateOfCountsPerSecond32" Help="Shows the number of account requests sent per second"/>
</util:PerformanceCategory>
</Component>

<Component Id="cmpb69520521cbba41ac82adecb1ef714866" Guid="*" NeverOverwrite="yes" Win64="yes">
Expand Down
35 changes: 35 additions & 0 deletions src/Lithnet.Pan.RAProxy/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ internal class Logging
public const int EventIDAccountingRequestRecieved = 4001;
public const int EventIDUserIDUpdateComplete = 4002;

public static PerformanceCounter CounterReceivedPerSecond;

public static PerformanceCounter CounterSentPerSecond;

public static PerformanceCounter CounterItemsInQueue;

public static void WriteEntry(string message, EventLogEntryType type, int eventID)
{
Trace.WriteLine(message);
Expand All @@ -42,5 +48,34 @@ public static void WriteDebugEntry(string message, EventLogEntryType type, int e
EventLog.WriteEntry(Program.EventSourceName, message, type, eventID);
}
}



static Logging()
{
Logging.CounterReceivedPerSecond = new PerformanceCounter
{
CategoryName = "PANRAProxy",
CounterName = "Requests received / second",
MachineName = ".",
ReadOnly = false
};

Logging.CounterSentPerSecond = new PerformanceCounter
{
CategoryName = "PANRAProxy",
CounterName = "Requests sent / second",
MachineName = ".",
ReadOnly = false
};

Logging.CounterItemsInQueue = new PerformanceCounter
{
CategoryName = "PANRAProxy",
CounterName = "Requests in queue",
MachineName = ".",
ReadOnly = false
};
}
}
}
6 changes: 5 additions & 1 deletion src/Lithnet.Pan.RAProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ private static void StartQueue()
{
foreach (AccountingRequest request in Program.incomingRequests.GetConsumingEnumerable(Program.cancellationToken.Token))
{
Logging.CounterItemsInQueue.Decrement();

try
{
Logging.WriteDebugEntry($"Incoming accounting request received\n{request}", EventLogEntryType.Information, Logging.EventIDAccountingRequestRecieved);
Trace.WriteLine($"Request queue lenth: {Program.incomingRequests.Count}");

Program.SendMessage(request);
}
Expand All @@ -121,6 +124,7 @@ private static void StartQueue()
internal static void AddToQueue(AccountingRequest request)
{
Program.incomingRequests.Add(request);
Logging.CounterItemsInQueue.Increment();
}

private static void SendMessage(AccountingRequest request)
Expand Down Expand Up @@ -175,9 +179,9 @@ private static void SendMessage(AccountingRequest request)

try
{
Logging.CounterSentPerSecond.Increment();
message.Send();
Logging.WriteEntry($"UserID API mapping succeeded\nUsername: {username.ValueAsString}\nIP address: {framedIP.ValueAsString}\nType: {type}", EventLogEntryType.Information, Logging.EventIDUserIDUpdateComplete);

}
catch (PanApiException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void Start(CancellationToken token)
{
var receiveResult = await listener.ReceiveAsync();
Trace.WriteLine($"Received packet from {receiveResult.RemoteEndPoint.Address}:{receiveResult.RemoteEndPoint.Port}");
Logging.CounterReceivedPerSecond.Increment();

// If this is a valid sized RADIUS packet, try to parse, otherwise silently ignore
if (receiveResult.Buffer?.Length >= 20)
Expand Down

0 comments on commit efb9c14

Please sign in to comment.