Exemplo n.º 1
0
        private void InitializeServiceClient(TelemetryConfiguration configuration)
        {
            if (this.serviceClient != null)
            {
                // service client has been passed through a constructor, we don't need to do anything
                return;
            }

            Uri serviceEndpointUri;

            if (string.IsNullOrWhiteSpace(this.QuickPulseServiceEndpoint))
            {
                // endpoint is not specified in configuration, use the default one
                serviceEndpointUri = QuickPulseDefaults.ServiceEndpoint;
            }
            else
            {
                // endpoint appears to have been specified in configuration, try using it
                try
                {
                    serviceEndpointUri = new Uri(this.QuickPulseServiceEndpoint);
                }
                catch (Exception e)
                {
                    throw new ArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Error initializing QuickPulse module. QPS endpoint is not a correct URI: '{0}'",
                                  this.QuickPulseServiceEndpoint),
                              e);
                }
            }

            // create the default production implementation of the service client with the best service endpoint we could get
            string instanceName    = GetInstanceName(configuration);
            string streamId        = GetStreamId();
            string machineName     = Environment.MachineName;
            var    assemblyVersion = SdkVersionUtils.GetSdkVersion(null);
            bool   isWebApp        = PerformanceCounterUtility.IsWebAppRunningInAzure();
            int?   processorCount  = PerformanceCounterUtility.GetProcessorCount(isWebApp);

            this.serviceClient = new QuickPulseServiceClient(
                serviceEndpointUri,
                instanceName,
                streamId,
                machineName,
                assemblyVersion,
                this.timeProvider,
                isWebApp,
                processorCount ?? 0);

            QuickPulseEventSource.Log.TroubleshootingMessageEvent(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Service client initialized. Endpoint: '{0}', instance name: '{1}', assembly version: '{2}'",
                    serviceEndpointUri,
                    instanceName,
                    assemblyVersion));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NormalizedCPUPercentageGauge"/> class.
        /// </summary>
        /// <param name="name"> Name of the SumUpCountersGauge.</param>
        /// <param name="value"> Gauges to sum.</param>
        public NormalizedCPUPercentageGauge(string name, ICounterValue value) : base(name, value)
        {
            int?count = PerformanceCounterUtility.GetProcessorCount();

            if (count.HasValue)
            {
                this.processorsCount = count.Value;
                this.isInitialized   = true;
            }
        }
        /// <summary>
        ///  Initializes a new instance of the <see cref="XPlatProcessCPUPerformanceCounterNormalized" /> class.
        /// </summary>
        internal XPlatProcessCPUPerformanceCounterNormalized() : base()
        {
            int?count = PerformanceCounterUtility.GetProcessorCount();

            if (count.HasValue)
            {
                this.processorsCount = count.Value;
                this.isInitialized   = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Initializes a new instance of the <see cref="NormalizedProcessCPUPerformanceCounter" /> class.
        /// </summary>
        /// <param name="categoryName">The counter category name.</param>
        /// <param name="counterName">The counter name.</param>
        /// <param name="instanceName">The instance name.</param>
        internal NormalizedProcessCPUPerformanceCounter(string categoryName, string counterName, string instanceName)
        {
            int?count = PerformanceCounterUtility.GetProcessorCount(false);

            if (count.HasValue)
            {
                this.processorsCount = count.Value;

                this.performanceCounter = new PerformanceCounter("Process", "% Processor Time", instanceName, true);

                this.isInitialized = true;
            }
        }
        private void InitializeServiceClient(TelemetryConfiguration configuration)
        {
            if (this.ServiceClient != null)
            {
                // service client has been passed through a constructor, we don't need to do anything
                return;
            }

            Uri serviceEndpointUri;

            if (string.IsNullOrWhiteSpace(this.QuickPulseServiceEndpoint))
            {
                // endpoint is not explicitly specified, use the Endpoint from the TelemetryConfiguration (ex: https://rt.services.visualstudio.com/QuickPulseService.svc)
                serviceEndpointUri = new Uri(configuration.EndpointContainer.Live, "QuickPulseService.svc");
            }
            else
            {
                // endpoint appears to have been specified in configuration, try using it
                try
                {
                    serviceEndpointUri = new Uri(this.QuickPulseServiceEndpoint);
                }
                catch (Exception e)
                {
                    throw new ArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Error initializing QuickPulse module. QPS endpoint is not a correct URI: '{0}'",
                                  this.QuickPulseServiceEndpoint),
                              e);
                }
            }

            // create the default production implementation of the service client with the best service endpoint we could get
            string instanceName    = GetInstanceName(configuration);
            string streamId        = GetStreamId();
            var    assemblyVersion = SdkVersionUtils.GetSdkVersion(null);
            bool   isWebApp        = PerformanceCounterUtility.IsWebAppRunningInAzure();
            int?   processorCount  = PerformanceCounterUtility.GetProcessorCount();

            this.ServiceClient = new QuickPulseServiceClient(
                serviceEndpointUri,
                instanceName,
                streamId,
                ServerId,
                assemblyVersion,
                this.timeProvider,
                isWebApp,
                processorCount ?? 0);

            // TelemetryConfigurationFactory will initialize Modules after Processors. Need to update the processor with the correct service endpoint.
            foreach (var processor in this.TelemetryProcessors)
            {
                processor.ServiceEndpoint = serviceEndpointUri;
            }

            QuickPulseEventSource.Log.TroubleshootingMessageEvent(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Service client initialized. Endpoint: '{0}', instance name: '{1}', assembly version: '{2}'",
                    serviceEndpointUri,
                    instanceName,
                    assemblyVersion));
        }