Пример #1
0
        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
            });

            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");
            }
        }
Пример #2
0
        public ExceptionCounter(Dictionary <Type, string> recognizedExceptions, HashSet <Type> ignoredExceptions, IMetricsProvider metricsProvider)
        {
            this.recognizedExceptions = Preconditions.CheckNotNull(recognizedExceptions, nameof(recognizedExceptions));
            this.ignoredExceptions    = Preconditions.CheckNotNull(ignoredExceptions, nameof(ignoredExceptions));
            Preconditions.CheckNotNull(metricsProvider, nameof(metricsProvider));
            this.exceptions = Preconditions.CheckNotNull(metricsProvider.CreateCounter(
                                                             "exceptions_total",
                                                             "The number of exceptions thrown of the given type",
                                                             new List <string> {
                "exception_name"
            }));

            AppDomain.CurrentDomain.FirstChanceException += this.OnException;
        }
Пример #3
0
    public FactoryMetrics(IMetricsProvider metricsProvider)
    {
        this.commandCounters = Enum.GetValues(typeof(ModuleCommandMetric)).Cast <ModuleCommandMetric>().ToDictionary(c => c, command =>
        {
            string commandName = Enum.GetName(typeof(ModuleCommandMetric), command).ToLower();
            return(metricsProvider.CreateCounter(
                       $"module_{commandName}",
                       "Command sent to module",
                       new List <string> {
                "module_name", "module_version", MetricsConstants.MsTelemetry
            }));
        });

        this.commandTiming = metricsProvider.CreateDuration(
            $"command_latency",
            "Command sent to module",
            new List <string> {
            "command", MetricsConstants.MsTelemetry
        });
    }