public DeploymentMetrics(IMetricsProvider metricsProvider, string storageFolder, ISystemTime time = null) { this.systemTime = time ?? SystemTime.Instance; this.availabilities = new List <Availability>(); this.edgeAgent = new Lazy <Availability>(() => new Availability(Constants.EdgeAgentModuleName, this.CalculateEdgeAgentDowntime(), this.systemTime)); Preconditions.CheckNotNull(metricsProvider, nameof(metricsProvider)); this.running = metricsProvider.CreateGauge( "total_time_running_correctly_seconds", "The amount of time the module was specified in the deployment and was in the running state", new List <string> { "module_name", MetricsConstants.MsTelemetry }); this.expectedRunning = metricsProvider.CreateGauge( "total_time_expected_running_seconds", "The amount of time the module was specified in the deployment", new List <string> { "module_name", MetricsConstants.MsTelemetry }); this.unsuccessfulSyncs = metricsProvider.CreateCounter( "unsuccessful_iothub_syncs", "The amount of times edgeAgent failed to sync with iotHub", new List <string> { MetricsConstants.MsTelemetry }); this.totalSyncs = metricsProvider.CreateCounter( "iothub_syncs", "The amount of times edgeAgent attempted to sync with iotHub, both successful and unsuccessful", new List <string> { MetricsConstants.MsTelemetry }); this.deploymentTime = metricsProvider.CreateHistogram( "deployment_time_seconds", "The amount of time it took to complete a new deployment", new List <string> { MetricsConstants.MsTelemetry }); this.manifestIntegrityFlag = metricsProvider.CreateGauge( "manifest_integrity_flag", "The value is 1 if manifest integrity is present or 0 if not present, tags indicate which integrity components are present", new List <string> { "signing_with_ca_enabled", "signing_with_integrity_enabled", MetricsConstants.MsTelemetry }); this.twinSignatureChecks = metricsProvider.CreateCounter( "twin_signature_check_count", "The number of twin signature checks, both successful and unsuccessful", new List <string> { "result", "algorithm", MetricsConstants.MsTelemetry }); this.twinSignatureTime = metricsProvider.CreateTimer( "twin_signature_check_seconds", "The amount of time it took to verify twin signature", new List <string> { MetricsConstants.MsTelemetry }); string storageDirectory = Path.Combine(Preconditions.CheckNonWhiteSpace(storageFolder, nameof(storageFolder)), "availability"); try { Directory.CreateDirectory(storageDirectory); this.checkpointFile = Path.Combine(storageDirectory, "avaliability.checkpoint"); this.updateCheckpointFile = new PeriodicTask(this.UpdateCheckpointFile, this.checkpointFrequency, this.checkpointFrequency, this.log, "Checkpoint Availability", false); } catch (Exception ex) { this.log.LogError(ex, "Could not create checkpoint directory"); } }