Skip to content

Commit

Permalink
Use code gen logging (#380)
Browse files Browse the repository at this point in the history
* Move calc to helper

* Improve logs

* Update version

* Improve status codes

* Cosmetic

* Debug level

* Disable publish metrics during high load

* Remove test
  • Loading branch information
luiscantero authored Jul 30, 2024
1 parent 88ca0e8 commit 1d036d1
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 147 deletions.
27 changes: 24 additions & 3 deletions src/Helpers/MetricsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace OpcPlc;

using Microsoft.Extensions.Logging;
using Opc.Ua;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
Expand Down Expand Up @@ -151,18 +153,37 @@ public static void AddMonitoredItemCount(int delta = 1)
/// <summary>
/// Add a published count.
/// </summary>
public static void AddPublishedCount(string sessionId, string subscriptionId, int dataPoints, int events)
public static void AddPublishedCount(string sessionId, string subscriptionId, NotificationMessage notificationMessage, ILogger logger)
{
if (!IsEnabled)
{
return;
}

if (dataPoints > 0)
int events = 0;
int dataChanges = 0;
int diagnostics = 0;
notificationMessage.NotificationData.ForEach(x => {
if (x.Body is DataChangeNotification changeNotification)
{
dataChanges += changeNotification.MonitoredItems.Count;
diagnostics += changeNotification.DiagnosticInfos.Count;
}
else if (x.Body is EventNotificationList eventNotification)
{
events += eventNotification.Events.Count;
}
else
{
logger.LogDebug("Unknown notification type: {NotificationType}", x.Body.GetType().Name);
}
});

if (dataChanges > 0)
{
var dataPointsDimensions = MergeWithBaseDimensions(
new KeyValuePair<string, object>("type", "data_point"));
_publishedCountWithType.Add(dataPoints, dataPointsDimensions);
_publishedCountWithType.Add(dataChanges, dataPointsDimensions);
}

if (events > 0)
Expand Down
Loading

0 comments on commit 1d036d1

Please sign in to comment.