/// <summary>
        /// Fetch diagnostic data.
        /// </summary>
        public static DiagnosticInfoMethodResponseModel GetDiagnosticInfo()
        {
            DiagnosticInfoMethodResponseModel diagnosticInfo = new DiagnosticInfoMethodResponseModel();

            try
            {
                diagnosticInfo.PublisherStartTime                  = PublisherStartTime;
                diagnosticInfo.NumberOfOpcSessionsConfigured       = NumberOfOpcSessionsConfigured;
                diagnosticInfo.NumberOfOpcSessionsConnected        = NumberOfOpcSessionsConnected;
                diagnosticInfo.NumberOfOpcSubscriptionsConfigured  = NumberOfOpcSubscriptionsConfigured;
                diagnosticInfo.NumberOfOpcSubscriptionsConnected   = NumberOfOpcSubscriptionsConnected;
                diagnosticInfo.NumberOfOpcMonitoredItemsConfigured = NumberOfOpcMonitoredItemsConfigured;
                diagnosticInfo.NumberOfOpcMonitoredItemsMonitored  = NumberOfOpcMonitoredItemsMonitored;
                diagnosticInfo.NumberOfOpcMonitoredItemsToRemove   = NumberOfOpcMonitoredItemsToRemove;
                diagnosticInfo.MonitoredItemsQueueCapacity         = MonitoredItemsQueueCapacity;
                diagnosticInfo.MonitoredItemsQueueCount            = MonitoredItemsQueueCount;
                diagnosticInfo.EnqueueCount               = EnqueueCount;
                diagnosticInfo.EnqueueFailureCount        = EnqueueFailureCount;
                diagnosticInfo.NumberOfEvents             = NumberOfEvents;
                diagnosticInfo.SentMessages               = SentMessages;
                diagnosticInfo.SentLastTime               = SentLastTime;
                diagnosticInfo.SentBytes                  = SentBytes;
                diagnosticInfo.FailedMessages             = FailedMessages;
                diagnosticInfo.TooLargeCount              = TooLargeCount;
                diagnosticInfo.MissedSendIntervalCount    = MissedSendIntervalCount;
                diagnosticInfo.WorkingSetMB               = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                diagnosticInfo.DefaultSendIntervalSeconds = DefaultSendIntervalSeconds;
                diagnosticInfo.HubMessageSize             = HubMessageSize;
                diagnosticInfo.HubProtocol                = HubProtocol;
            }
            catch
            {
            }
            return(diagnosticInfo);
        }
        /// <summary>
        /// Kicks of the task to show diagnostic information each 30 seconds.
        /// </summary>
        public async Task ShowDiagnosticsInfoAsync(CancellationToken ct)
        {
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    await Task.Delay(DiagnosticsInterval * 1000, ct).ConfigureAwait(false);

                    // only show diag after startup is completed
                    if (!StartupCompleted)
                    {
                        continue;
                    }

                    DiagnosticInfoMethodResponseModel diagnosticInfo = GetDiagnosticInfo();
                    Logger.Information("==========================================================================");
                    Logger.Information($"OpcPublisher status @ {System.DateTime.UtcNow} (started @ {diagnosticInfo.PublisherStartTime})");
                    Logger.Information("---------------------------------");
                    Logger.Information($"OPC sessions (configured/connected): {diagnosticInfo.NumberOfOpcSessionsConfigured}/{diagnosticInfo.NumberOfOpcSessionsConnected}");
                    Logger.Information($"OPC subscriptions (configured/connected): {diagnosticInfo.NumberOfOpcSubscriptionsConfigured}/{diagnosticInfo.NumberOfOpcSubscriptionsConnected}");
                    Logger.Information($"OPC monitored items (configured/monitored/to remove): {diagnosticInfo.NumberOfOpcMonitoredItemsConfigured}/{diagnosticInfo.NumberOfOpcMonitoredItemsMonitored}/{diagnosticInfo.NumberOfOpcMonitoredItemsToRemove}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"monitored items queue bounded capacity: {diagnosticInfo.MonitoredItemsQueueCapacity}");
                    Logger.Information($"monitored items queue current items: {diagnosticInfo.MonitoredItemsQueueCount}");
                    Logger.Information($"monitored item notifications enqueued: {diagnosticInfo.EnqueueCount}");
                    Logger.Information($"monitored item notifications enqueue failure: {diagnosticInfo.EnqueueFailureCount}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"messages sent to IoTHub: {diagnosticInfo.SentMessages}");
                    Logger.Information($"last successful msg sent @: {diagnosticInfo.SentLastTime}");
                    Logger.Information($"bytes sent to IoTHub: {diagnosticInfo.SentBytes}");
                    Logger.Information($"avg msg size: {diagnosticInfo.SentBytes / (diagnosticInfo.SentMessages == 0 ? 1 : diagnosticInfo.SentMessages)}");
                    Logger.Information($"msg send failures: {diagnosticInfo.FailedMessages}");
                    Logger.Information($"messages too large to sent to IoTHub: {diagnosticInfo.TooLargeCount}");
                    Logger.Information($"times we missed send interval: {diagnosticInfo.MissedSendIntervalCount}");
                    Logger.Information($"number of events: {diagnosticInfo.NumberOfEvents}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"current working set in MB: {diagnosticInfo.WorkingSetMB}");
                    Logger.Information($"--si setting: {diagnosticInfo.DefaultSendIntervalSeconds}");
                    Logger.Information($"--ms setting: {diagnosticInfo.HubMessageSize}");
                    Logger.Information($"--ih setting: {diagnosticInfo.HubProtocol}");
                    Logger.Information("==========================================================================");
                }
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
                catch
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
                {
                }
            }
        }
        /// <summary>
        /// Kicks of the task to show diagnostic information each 30 seconds.
        /// </summary>
        public static async Task ShowDiagnosticsInfoAsync(CancellationToken ct)
        {
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    await Task.Delay((int)DiagnosticsInterval * 1000, ct);

                    DiagnosticInfoMethodResponseModel diagnosticInfo = GetDiagnosticInfo();
                    Logger.Information("==========================================================================");
                    Logger.Information($"OpcPublisher status @ {System.DateTime.UtcNow} (started @ {diagnosticInfo.PublisherStartTime})");
                    Logger.Information("---------------------------------");
                    Logger.Information($"OPC sessions: {diagnosticInfo.NumberOfOpcSessions}");
                    Logger.Information($"connected OPC sessions: {diagnosticInfo.NumberOfConnectedOpcSessions}");
                    Logger.Information($"connected OPC subscriptions: {diagnosticInfo.NumberOfConnectedOpcSubscriptions}");
                    Logger.Information($"OPC monitored items: {diagnosticInfo.NumberOfMonitoredItems}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"monitored items queue bounded capacity: {diagnosticInfo.MonitoredItemsQueueCapacity}");
                    Logger.Information($"monitored items queue current items: {diagnosticInfo.MonitoredItemsQueueCount}");
                    Logger.Information($"monitored item notifications enqueued: {diagnosticInfo.EnqueueCount}");
                    Logger.Information($"monitored item notifications enqueue failure: {diagnosticInfo.EnqueueFailureCount}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"messages sent to IoTHub: {diagnosticInfo.SentMessages}");
                    Logger.Information($"last successful msg sent @: {diagnosticInfo.SentLastTime}");
                    Logger.Information($"bytes sent to IoTHub: {diagnosticInfo.SentBytes}");
                    Logger.Information($"avg msg size: {diagnosticInfo.SentBytes / (diagnosticInfo.SentMessages == 0 ? 1 : diagnosticInfo.SentMessages)}");
                    Logger.Information($"msg send failures: {diagnosticInfo.FailedMessages}");
                    Logger.Information($"messages too large to sent to IoTHub: {diagnosticInfo.TooLargeCount}");
                    Logger.Information($"times we missed send interval: {diagnosticInfo.MissedSendIntervalCount}");
                    Logger.Information($"number of events: {diagnosticInfo.NumberOfEvents}");
                    Logger.Information("---------------------------------");
                    Logger.Information($"current working set in MB: {diagnosticInfo.WorkingSetMB}");
                    Logger.Information($"--si setting: {diagnosticInfo.DefaultSendIntervalSeconds}");
                    Logger.Information($"--ms setting: {diagnosticInfo.HubMessageSize}");
                    Logger.Information($"--ih setting: {diagnosticInfo.HubProtocol}");
                    Logger.Information("==========================================================================");
                }
                catch
                {
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Fetch diagnostic data.
        /// </summary>
        public DiagnosticInfoMethodResponseModel GetDiagnosticInfo()
        {
            DiagnosticInfoMethodResponseModel diagnosticInfo = new DiagnosticInfoMethodResponseModel();

            try
            {
                diagnosticInfo.PublisherStartTime                            = PublisherStartTime;
                diagnosticInfo.NumberOfOpcSessionsConfigured                 = NodeConfiguration.NumberOfOpcSessionsConfigured;
                diagnosticInfo.NumberOfOpcSessionsConnected                  = NodeConfiguration.NumberOfOpcSessionsConnected;
                diagnosticInfo.NumberOfOpcSubscriptionsConfigured            = NodeConfiguration.NumberOfOpcSubscriptionsConfigured;
                diagnosticInfo.NumberOfOpcSubscriptionsConnected             = NodeConfiguration.NumberOfOpcSubscriptionsConnected;
                diagnosticInfo.NumberOfOpcDataChangeMonitoredItemsConfigured = NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured;
                diagnosticInfo.NumberOfOpcDataChangeMonitoredItemsMonitored  = NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsMonitored;
                diagnosticInfo.NumberOfOpcDataChangeMonitoredItemsToRemove   = NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsToRemove;
                diagnosticInfo.NumberOfOpcEventMonitoredItemsConfigured      = NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured;
                diagnosticInfo.NumberOfOpcEventMonitoredItemsMonitored       = NodeConfiguration.NumberOfOpcEventMonitoredItemsMonitored;
                diagnosticInfo.NumberOfOpcEventMonitoredItemsToRemove        = NodeConfiguration.NumberOfOpcEventMonitoredItemsToRemove;
                diagnosticInfo.MonitoredItemsQueueCapacity                   = MonitoredItemsQueueCapacity;
                diagnosticInfo.MonitoredPropertiesQueueCapacity              = MonitoredPropertiesQueueCapacity;
                diagnosticInfo.MonitoredSettingsQueueCapacity                = MonitoredSettingsQueueCapacity;
                diagnosticInfo.MonitoredItemsQueueCount                      = _hub.MonitoredItemsQueueCount;
                diagnosticInfo.MonitoredPropertiesQueueCount                 = MonitoredPropertiesQueueCount;
                diagnosticInfo.MonitoredSettingsQueueCount                   = MonitoredSettingsQueueCount;
                diagnosticInfo.EnqueueCount             = EnqueueCount;
                diagnosticInfo.EnqueueFailureCount      = EnqueueFailureCount;
                diagnosticInfo.NumberOfDataChangeEvents = NumberOfDataChangeEvents;
                diagnosticInfo.NumberOfEvents           = NumberOfEvents;
                diagnosticInfo.SentMessages             = SentMessages;
                diagnosticInfo.SentProperties           = SentProperties;
                diagnosticInfo.SentSettings             = SentSettings;
                diagnosticInfo.SentIoTCEvents           = SentIoTcEvents;
                diagnosticInfo.SentLastTime             = SentLastTime;
                diagnosticInfo.SentBytes                  = SentBytes;
                diagnosticInfo.FailedMessages             = FailedMessages;
                diagnosticInfo.TooLargeCount              = TooLargeCount;
                diagnosticInfo.MissedSendIntervalCount    = MissedSendIntervalCount;
                diagnosticInfo.WorkingSetMB               = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                diagnosticInfo.DefaultSendIntervalSeconds = SendIntervalSecondsDefault;
                diagnosticInfo.HubMessageSize             = HubMessageSizeDefault;
                diagnosticInfo.HubProtocol                = HubProtocol;
            }
            catch
            {
                // startup might be not completed yet
            }
            return(diagnosticInfo);
        }
        /// <summary>
        /// Fetch diagnostic data.
        /// </summary>
        public DiagnosticInfoMethodResponseModel GetDiagnosticInfo()
        {
            DiagnosticInfoMethodResponseModel diagnosticInfo = new DiagnosticInfoMethodResponseModel();

            try
            {
                diagnosticInfo.PublisherStartTime                  = PublisherStartTime;
                diagnosticInfo.NumberOfOpcSessionsConfigured       = NodeConfiguration.NumberOfOpcSessionsConfigured;
                diagnosticInfo.NumberOfOpcSessionsConnected        = NodeConfiguration.NumberOfOpcSessionsConnected;
                diagnosticInfo.NumberOfOpcSubscriptionsConfigured  = NodeConfiguration.NumberOfOpcSubscriptionsConfigured;
                diagnosticInfo.NumberOfOpcSubscriptionsConnected   = NodeConfiguration.NumberOfOpcSubscriptionsConnected;
                diagnosticInfo.NumberOfOpcMonitoredItemsConfigured = NodeConfiguration.NumberOfOpcMonitoredItemsConfigured;
                diagnosticInfo.NumberOfOpcMonitoredItemsMonitored  = NodeConfiguration.NumberOfOpcMonitoredItemsMonitored;
                diagnosticInfo.NumberOfOpcMonitoredItemsToRemove   = NodeConfiguration.NumberOfOpcMonitoredItemsToRemove;
                diagnosticInfo.MonitoredItemsQueueCapacity         = MonitoredItemsQueueCapacity;
                diagnosticInfo.MonitoredItemsQueueCount            = MonitoredItemsQueueCount;
                diagnosticInfo.EnqueueCount               = EnqueueCount;
                diagnosticInfo.EnqueueFailureCount        = EnqueueFailureCount;
                diagnosticInfo.NumberOfEvents             = NumberOfEvents;
                diagnosticInfo.SentMessages               = SentMessages;
                diagnosticInfo.SentLastTime               = SentLastTime;
                diagnosticInfo.SentBytes                  = SentBytes;
                diagnosticInfo.FailedMessages             = FailedMessages;
                diagnosticInfo.TooLargeCount              = TooLargeCount;
                diagnosticInfo.MissedSendIntervalCount    = MissedSendIntervalCount;
                diagnosticInfo.WorkingSetMB               = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                diagnosticInfo.DefaultSendIntervalSeconds = DefaultSendIntervalSeconds;
                diagnosticInfo.HubMessageSize             = HubMessageSize;
                diagnosticInfo.HubProtocol                = HubProtocol;
            }
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
            catch
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
            {
                // startup might be not completed yet
            }
            return(diagnosticInfo);
        }
Beispiel #6
0
        /// <summary>
        /// Fetch diagnostic data.
        /// </summary>
        public DiagnosticInfoMethodResponseModel GetDiagnosticInfo()
        {
            DiagnosticInfoMethodResponseModel diagnosticInfo = new DiagnosticInfoMethodResponseModel();

            try
            {
                diagnosticInfo.PublisherStartTime                  = PublisherStartTime;
                diagnosticInfo.NumberOfOpcSessionsConfigured       = NodeConfiguration.NumberOfOpcSessionsConfigured;
                diagnosticInfo.NumberOfOpcSessionsConnected        = NodeConfiguration.NumberOfOpcSessionsConnected;
                diagnosticInfo.NumberOfOpcSubscriptionsConfigured  = NodeConfiguration.NumberOfOpcSubscriptionsConfigured;
                diagnosticInfo.NumberOfOpcSubscriptionsConnected   = NodeConfiguration.NumberOfOpcSubscriptionsConnected;
                diagnosticInfo.NumberOfOpcMonitoredItemsConfigured = NodeConfiguration.NumberOfOpcMonitoredItemsConfigured;
                diagnosticInfo.NumberOfOpcMonitoredItemsMonitored  = NodeConfiguration.NumberOfOpcMonitoredItemsMonitored;
                diagnosticInfo.NumberOfOpcMonitoredItemsToRemove   = NodeConfiguration.NumberOfOpcMonitoredItemsToRemove;
                diagnosticInfo.MonitoredItemsQueueCapacity         = MonitoredItemsQueueCapacity;
                diagnosticInfo.MonitoredItemsQueueCount            = MonitoredItemsQueueCount;
                diagnosticInfo.EnqueueCount               = EnqueueCount;
                diagnosticInfo.EnqueueFailureCount        = EnqueueFailureCount;
                diagnosticInfo.NumberOfEvents             = NumberOfEvents;
                diagnosticInfo.SentMessages               = SentMessages;
                diagnosticInfo.SentLastTime               = SentLastTime;
                diagnosticInfo.SentBytes                  = SentBytes;
                diagnosticInfo.FailedMessages             = FailedMessages;
                diagnosticInfo.TooLargeCount              = TooLargeCount;
                diagnosticInfo.MissedSendIntervalCount    = MissedSendIntervalCount;
                diagnosticInfo.WorkingSetMB               = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                diagnosticInfo.DefaultSendIntervalSeconds = DefaultSendIntervalSeconds;
                diagnosticInfo.HubMessageSize             = HubMessageSize;
                diagnosticInfo.HubProtocol                = HubProtocol;
            }
            catch (Exception ex)
            {
                // startup might be not completed yet
                Logger.Error(ex, "Collecting diagnostics information causing error {diagnosticInfo}", diagnosticInfo);
            }
            return(diagnosticInfo);
        }