Skip to content

Commit

Permalink
Update readme and test nuget (#382)
Browse files Browse the repository at this point in the history
* Add otlpublishmetrics

* Update test nuget

* Cosmetic

* Refactor
  • Loading branch information
luiscantero authored Aug 1, 2024
1 parent c340a5d commit ef2454e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ Options:
the protocol for exporting OTLP information.
(allowed values: grpc, protobuf).
Default: grpc
--otlpub, --otlpublishmetrics=VALUE
how to handle metrics for publish requests.
(allowed values: disable=Always disabled, enable=
Always enabled, auto=Auto-disable when sessions >
40 or monitored items > 500).
Default: auto
--lr, --ldsreginterval=VALUE
the LDS(-ME) registration interval in ms. If 0,
then the registration is disabled.
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/OpcUaAppConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<ApplicationConfiguration> ConfigureAsync()
}
}

_logger.LogInformation("Alternate base addresses (for server binding and certificate DNSNames and IPAddresses extensions): {alternateBaseAddresses}", alternateBaseAddresses);
_logger.LogInformation("Alternate base addresses (for server binding and certificate DNSNames and IPAddresses extensions): {AlternateBaseAddresses}", alternateBaseAddresses);

string applicationUri = $"urn:{_config.ProgramName}:{_config.OpcUa.HostnameLabel}{(string.IsNullOrEmpty(_config.OpcUa.ServerPath)
? string.Empty
Expand Down
47 changes: 26 additions & 21 deletions src/PlcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,7 @@ public override ResponseHeader Publish(

if (PublishMetricsEnabled)
{
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
{
LogUnknownNotification(x.Body.GetType().Name);
}
});

MetricsHelper.AddPublishedCount(context.SessionId.ToString(), subscriptionId.ToString(), dataChanges, events);
AddPublishMetrics(notificationMessage, context.SessionId.ToString(), subscriptionId.ToString());
}

LogSuccessWithSessionIdAndSubscriptionId(
Expand Down Expand Up @@ -594,6 +574,31 @@ protected override void OnServerStopping()
base.OnServerStopping();
}

private void AddPublishMetrics(NotificationMessage notificationMessage, string sessionId, string subscriptionId)
{
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
{
LogUnknownNotification(x.Body.GetType().Name);
}
});

MetricsHelper.AddPublishedCount(sessionId, subscriptionId, dataChanges, events);
}

[LoggerMessage(
Level = LogLevel.Information,
Message = "\n\t# Open sessions: {Sessions}\n" +
Expand Down
2 changes: 1 addition & 1 deletion tests/opc-plc-tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
</ItemGroup>

Expand Down

0 comments on commit ef2454e

Please sign in to comment.