Class AssetRuntimeHealthReporter
- Namespace
- Azure.Iot.Operations.Services.AssetAndDeviceRegistry
- Assembly
- Azure.Iot.Operations.Services.dll
A class for smartly sending runtime health events for a specific asset to the Azure Device Registry service
public class AssetRuntimeHealthReporter : IAsyncDisposable
- Inheritance
-
AssetRuntimeHealthReporter
- Implements
- Inherited Members
Remarks
This class has two main features that differentiate it from just directly calling the runtime health update APIs like ReportDatasetRuntimeHealthAsync(string, string, string, List<DatasetsRuntimeHealthEvent>, TimeSpan?, CancellationToken):
- De-duplication of dataset/stream/event/management action runtime healths. This allows you to write your connector code such that it repeatedly calls an API like ReportDatasetHealthStatusAsync(List<DatasetsRuntimeHealthEvent>, TimeSpan?, CancellationToken) even if the runtime health has not changed as this client will cache the last sent runtime health and check if the new runtime health actually needs to be forwarded to the service.
- Periodic reporting of the last known runtime healths of the datasets/streams/events/management actions with updated timestamps. Connectors are advised to periodically send these updates to ensure that the Azure Device Registry service has an up-to-date picture of the runtime health of each dataset/stream/event/management action and this class handles that for you. Additionally, the periodic updates can be paused for specific datasets/streams/events/management actions when their runtime health becomes unknown. This background reporting will send the runtime health for all non-paused datasets/streams/events/management actions at once and the period that it does this can be changed with SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan, CancellationToken).
Constructors
AssetRuntimeHealthReporter(IAzureDeviceRegistryClient, string, string, string, TimeSpan?)
Create a new runtime health reporter for a given asset
public AssetRuntimeHealthReporter(IAzureDeviceRegistryClient azureDeviceRegistryClient, string deviceName, string inboundEndpointName, string assetName, TimeSpan? reportingPeriod = null)
Parameters
azureDeviceRegistryClientIAzureDeviceRegistryClientThe Azure Device Registry client used to send these runtime health events.
deviceNamestringThe name of the device.
inboundEndpointNamestringThe name of the inbound endpoint
assetNamestringThe name of the asset.
reportingPeriodTimeSpan?The interval at which to send background reports.
Remarks
Background reporting does not start until the first runtime health of a dataset/stream/event/management action is set by calling a method like ReportDatasetHealthStatusAsync(string, RuntimeHealth, TimeSpan?, CancellationToken).
Methods
CancelHealthStatusReportingAsync(CancellationToken)
Stop all background reporting.
public Task CancelHealthStatusReportingAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Generally, this method should only be called if the asset this client reports for is no longer available.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public virtual ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
DisposeAsync(bool)
public virtual ValueTask DisposeAsync(bool disposing)
Parameters
disposingbool
Returns
PauseReportingDatasetAsync(string, CancellationToken)
Pause background reporting until a new health status is set for this dataset
public Task PauseReportingDatasetAsync(string datasetName, CancellationToken cancellationToken = default)
Parameters
datasetNamestringThe dataset to pause health status reporting for.
cancellationTokenCancellationToken
Returns
Remarks
This is used to signal that the last known health status may no longer be applicable. This does not affect background reporting of other datasets/streams/events/management actions that were already active.
PauseReportingEventAsync(string, string, CancellationToken)
Pause background reporting until a new health status is set for this event
public Task PauseReportingEventAsync(string eventGroupName, string eventName, CancellationToken cancellationToken = default)
Parameters
eventGroupNamestringThe event group whose event should pause reporting.
eventNamestringThe event within the given event group that should pause reporting
cancellationTokenCancellationToken
Returns
Remarks
This is used to signal that the last known health status may no longer be applicable.
PauseReportingManagementActionAsync(string, string, CancellationToken)
Pause background reporting until a new health status is set for this event
public Task PauseReportingManagementActionAsync(string managementGroupName, string managementActionName, CancellationToken cancellationToken = default)
Parameters
managementGroupNamestringThe management group whose action should pause reporting.
managementActionNamestringThe action within the given management group that should pause reporting
cancellationTokenCancellationToken
Returns
Remarks
This is used to signal that the last known health status may no longer be applicable. This does not affect background reporting of other datasets/streams/events/management actions that were already active.
PauseReportingStreamAsync(string, CancellationToken)
Pause background reporting until a new health status is set for this stream
public Task PauseReportingStreamAsync(string streamName, CancellationToken cancellationToken = default)
Parameters
streamNamestringThe stream to pause health status reporting for.
cancellationTokenCancellationToken
Returns
Remarks
This is used to signal that the last known health status may no longer be applicable. This does not affect background reporting of other datasets/streams/events/management actions that were already active.
ReportDatasetHealthStatusAsync(List<DatasetsRuntimeHealthEvent>, TimeSpan?, CancellationToken)
Report a batch of runtime healths of datasets if any of them are worth reporting.
public Task ReportDatasetHealthStatusAsync(List<DatasetsRuntimeHealthEvent> datasetRuntimeHealths, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
datasetRuntimeHealthsList<DatasetsRuntimeHealthEvent>The batch of dataset runtime healths.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for any of these datasets, or it was paused, then background reporting will start/resume. This method will only send the runtime healths in this batch that are not functionally identical to their previously reported runtime health (identical other than timestamp). If none of these runtime healths are worth reporting, then no telemetry will be sent.
ReportDatasetHealthStatusAsync(string, RuntimeHealth, TimeSpan?, CancellationToken)
Report the runtime health of a single dataset if it is worth reporting.
public Task ReportDatasetHealthStatusAsync(string datasetName, RuntimeHealth datasetRuntimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
datasetNamestringThe name of the dataset
datasetRuntimeHealthRuntimeHealthThe runtime health of that dataset
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for this dataset, or it was paused, then background reporting will start/resume. If this runtime health is functionally identical to the previously reported runtime health (identical other than timestamp), then no telemetry will be sent to the Azure Device Registry service.
ReportEventHealthStatusAsync(List<EventsRuntimeHealthEvent>, TimeSpan?, CancellationToken)
Report a batch of runtime healths of events if any of them are worth reporting.
public Task ReportEventHealthStatusAsync(List<EventsRuntimeHealthEvent> eventRuntimeHealths, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
eventRuntimeHealthsList<EventsRuntimeHealthEvent>The batch of event runtime healths.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for any of these events, or it was paused, then background reporting will start/resume. This method will only send the runtime healths in this batch that are not functionally identical to their previously reported runtime health (identical other than timestamp). If none of these runtime healths are worth reporting, then no telemetry will be sent.
ReportEventHealthStatusAsync(string, string, RuntimeHealth, TimeSpan?, CancellationToken)
Report the runtime health of a single event if it is worth reporting.
public Task ReportEventHealthStatusAsync(string eventGroupName, string eventName, RuntimeHealth eventRuntimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
eventGroupNamestringThe name of the event group that the event belongs to
eventNamestringThe name of the event
eventRuntimeHealthRuntimeHealthThe runtime health of that event
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for this event, or it was paused, then background reporting will start/resume. If this runtime health is functionally identical to the previously reported runtime health (identical other than timestamp), then no telemetry will be sent to the Azure Device Registry service.
ReportManagementActionHealthStatusAsync(List<ManagementActionsRuntimeHealthEvent>, TimeSpan?, CancellationToken)
Report a batch of runtime healths of management actions if any of them are worth reporting.
public Task ReportManagementActionHealthStatusAsync(List<ManagementActionsRuntimeHealthEvent> managementActionRuntimeHealths, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
managementActionRuntimeHealthsList<ManagementActionsRuntimeHealthEvent>The batch of management action runtime healths.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for any of these management actions, or it was paused, then background reporting will start/resume. This method will only send the runtime healths in this batch that are not functionally identical to their previously reported runtime health (identical other than timestamp). If none of these runtime healths are worth reporting, then no telemetry will be sent.
ReportManagementActionHealthStatusAsync(string, string, RuntimeHealth, TimeSpan?, CancellationToken)
Report the runtime health of a single management action if it is worth reporting.
public Task ReportManagementActionHealthStatusAsync(string managementGroupName, string managementActionName, RuntimeHealth managementActionRuntimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
managementGroupNamestringThe name of the management group that the management action belongs to
managementActionNamestringThe name of the event
managementActionRuntimeHealthRuntimeHealthThe runtime health of that management action
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for this management action, or it was paused, then background reporting will start/resume. If this runtime health is functionally identical to the previously reported runtime health (identical other than timestamp), then no telemetry will be sent to the Azure Device Registry service.
ReportStreamHealthStatusAsync(List<StreamsRuntimeHealthEvent>, TimeSpan?, CancellationToken)
Report a batch of runtime healths of streams if any of them are worth reporting.
public Task ReportStreamHealthStatusAsync(List<StreamsRuntimeHealthEvent> streamRuntimeHealths, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
streamRuntimeHealthsList<StreamsRuntimeHealthEvent>The batch of stream runtime healths.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for any of these streams, or it was paused, then background reporting will start/resume. This method will only send the runtime healths in this batch that are not functionally identical to their previously reported runtime health (identical other than timestamp). If none of these runtime healths are worth reporting, then no telemetry will be sent.
ReportStreamHealthStatusAsync(string, RuntimeHealth, TimeSpan?, CancellationToken)
Report the runtime health of a single stream if it is worth reporting.
public Task ReportStreamHealthStatusAsync(string streamName, RuntimeHealth streamRuntimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
streamNamestringThe name of the stream
streamRuntimeHealthRuntimeHealthThe runtime health of that stream
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry (if any telemetry is sent).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
If background reporting has not started for this stream, or it was paused, then background reporting will start/resume. If this runtime health is functionally identical to the previously reported runtime health (identical other than timestamp), then no telemetry will be sent to the Azure Device Registry service.
SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan, CancellationToken)
Change the interval at which this client will send background reports of the latest cached asset runtime healths
public Task SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan reportingInterval, CancellationToken cancellationToken = default)
Parameters
reportingIntervalTimeSpanThe new reporting interval
cancellationTokenCancellationTokenCancellation token
Returns
Remarks
If background reporting is currently in progress, it will be cancelled and restarted with this new interval. If background reporting is not currently in progress, calling this method will not start it.