예제 #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 SystemResourcesMetrics(IMetricsProvider metricsProvider, Func <Task <SystemResources> > getSystemResources, string apiVersion, TimeSpan updateFrequency)
        {
            Preconditions.CheckNotNull(metricsProvider, nameof(metricsProvider));
            this.getSystemResources = Preconditions.CheckNotNull(getSystemResources, nameof(getSystemResources));
            this.apiVersion         = Preconditions.CheckNotNull(apiVersion, nameof(apiVersion));
            Preconditions.CheckArgument(updateFrequency >= MaxUpdateFrequency, $"Performance metrics cannot update faster than {MaxUpdateFrequency.Humanize()}.");
            this.updateFrequency = updateFrequency;

            this.hostUptime = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                             "host_uptime_seconds",
                                                             "How long the host has been on",
                                                             new List <string> {
                MetricsConstants.MsTelemetry
            }));

            this.iotedgedUptime = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                                 "iotedged_uptime_seconds",
                                                                 "How long iotedged has been running",
                                                                 new List <string> {
                MetricsConstants.MsTelemetry
            }));

            this.usedSpace = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                            "available_disk_space_bytes",
                                                            "Amount of space left on the disk",
                                                            new List <string> {
                "disk_name", "disk_filesystem", "disk_filetype", MetricsConstants.MsTelemetry
            }));

            this.totalSpace = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                             "total_disk_space_bytes",
                                                             "Size of the disk",
                                                             new List <string> {
                "disk_name", "disk_filesystem", "disk_filetype", MetricsConstants.MsTelemetry
            }));

            this.usedMemory = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                             "used_memory_bytes",
                                                             "Amount of RAM used by all processes",
                                                             new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.totalMemory = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                              "total_memory_bytes",
                                                              "RAM available",
                                                              new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.cpuPercentage = Preconditions.CheckNotNull(metricsProvider.CreateHistogram(
                                                                "used_cpu_percent",
                                                                "Percent of cpu used by all processes",
                                                                new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.createdPids = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                              "created_pids_total",
                                                              "The number of processes or threads the container has created",
                                                              new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.networkIn = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                            "total_network_in_bytes",
                                                            "The amount of bytes recieved from the network",
                                                            new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.networkOut = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                             "total_network_out_bytes",
                                                             "The amount of bytes sent to network",
                                                             new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.diskRead = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                           "total_disk_read_bytes",
                                                           "The amount of bytes read from the disk",
                                                           new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));

            this.diskWrite = Preconditions.CheckNotNull(metricsProvider.CreateGauge(
                                                            "total_disk_write_bytes",
                                                            "The amount of bytes written to disk",
                                                            new List <string> {
                "module", MetricsConstants.MsTelemetry
            }));
        }