コード例 #1
0
        public static ResourceLoadPerfCounterWrapper Get(ResourceKey resource, WorkloadClassification classification)
        {
            ResourceLoadPerfCounterWrapper resourceLoadPerfCounterWrapper = null;
            Tuple <ResourceKey, WorkloadClassification> key = new Tuple <ResourceKey, WorkloadClassification>(resource, classification);

            lock (ResourceLoadPerfCounterWrapper.staticLock)
            {
                if (ResourceLoadPerfCounterWrapper.instances.TryGetValue(key, out resourceLoadPerfCounterWrapper))
                {
                    resourceLoadPerfCounterWrapper.lastUpdateUtc = DateTime.UtcNow;
                }
            }
            if (resourceLoadPerfCounterWrapper == null)
            {
                if (ResourceHealthMonitorManager.Active)
                {
                    string text = string.Concat(new object[]
                    {
                        ResourceLoadPerfCounterWrapper.GetDefaultInstanceName(),
                        "_",
                        resource,
                        "_",
                        classification
                    });
                    try
                    {
                        MSExchangeResourceLoadInstance instance = MSExchangeResourceLoad.GetInstance(text);
                        resourceLoadPerfCounterWrapper = new ResourceLoadPerfCounterWrapper(instance);
                    }
                    catch (Exception ex)
                    {
                        Globals.LogEvent(DirectoryEventLogConstants.Tuple_InitializeResourceHealthPerformanceCountersFailed, string.Empty, new object[]
                        {
                            ResourceLoadPerfCounterWrapper.GetDefaultInstanceName(),
                            ex.ToString()
                        });
                        ExTraceGlobals.ClientThrottlingTracer.TraceError <string, string, string>(0L, "[ResourceLoadPerfCounterWrapper::Get] Perf counter initialization failed for key instance: {0} with exception type: {1}, Messsage: {2}", text, ex.GetType().FullName, ex.Message);
                    }
                }
                if (resourceLoadPerfCounterWrapper == null)
                {
                    resourceLoadPerfCounterWrapper = new ResourceLoadPerfCounterWrapper(null);
                }
                lock (ResourceLoadPerfCounterWrapper.staticLock)
                {
                    ResourceLoadPerfCounterWrapper resourceLoadPerfCounterWrapper2;
                    if (!ResourceLoadPerfCounterWrapper.instances.TryGetValue(key, out resourceLoadPerfCounterWrapper2))
                    {
                        ResourceLoadPerfCounterWrapper.instances.Add(key, resourceLoadPerfCounterWrapper);
                    }
                    else
                    {
                        resourceLoadPerfCounterWrapper = resourceLoadPerfCounterWrapper2;
                    }
                }
            }
            return(resourceLoadPerfCounterWrapper);
        }
コード例 #2
0
 private static void CleanupStaleCounters(object state)
 {
     Tuple <ResourceKey, WorkloadClassification>[] array = null;
     lock (ResourceLoadPerfCounterWrapper.staticLock)
     {
         array = new Tuple <ResourceKey, WorkloadClassification> [ResourceLoadPerfCounterWrapper.instances.Keys.Count];
         ResourceLoadPerfCounterWrapper.instances.Keys.CopyTo(array, 0);
     }
     foreach (Tuple <ResourceKey, WorkloadClassification> key in array)
     {
         lock (ResourceLoadPerfCounterWrapper.staticLock)
         {
             ResourceLoadPerfCounterWrapper resourceLoadPerfCounterWrapper = null;
             if (ResourceLoadPerfCounterWrapper.instances.TryGetValue(key, out resourceLoadPerfCounterWrapper) && DateTime.UtcNow - resourceLoadPerfCounterWrapper.lastUpdateUtc > ResourceLoadPerfCounterWrapper.CleanupWindow)
             {
                 if (resourceLoadPerfCounterWrapper.perfCounters != null)
                 {
                     resourceLoadPerfCounterWrapper.perfCounters.Remove();
                 }
                 ResourceLoadPerfCounterWrapper.instances.Remove(key);
             }
         }
     }
 }
コード例 #3
0
        // Token: 0x060075F6 RID: 30198 RVA: 0x00184160 File Offset: 0x00182360
        public virtual ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null)
        {
            if (!this.Settings.Enabled)
            {
                return(ResourceLoad.Zero);
            }
            int metricValue = this.GetMetricValue(optionalData);

            if (metricValue < 0)
            {
                return(ResourceLoad.Unknown);
            }
            ResourceMetricPolicy resourceMetricPolicy = new ResourceMetricPolicy(this.MetricType, classification, this.Settings);
            ResourceLoad         resourceLoad         = resourceMetricPolicy.InterpretMetricValue(metricValue);

            if (!raw)
            {
                CacheableResourceHealthMonitor.LoadInfo loadInfo = this.loadInfo[classification];
                if (this.UpdateIsNeeded(loadInfo, resourceLoad))
                {
                    try
                    {
                        if (Monitor.TryEnter(this.instanceLock) && this.UpdateIsNeeded(loadInfo, resourceLoad))
                        {
                            switch (resourceLoad.State)
                            {
                            case ResourceLoadState.Unknown:
                                loadInfo.Load = resourceLoad;
                                break;

                            case ResourceLoadState.Underloaded:
                            case ResourceLoadState.Full:
                                if (loadInfo.Load < ResourceLoad.Full)
                                {
                                    loadInfo.Load = resourceLoad;
                                }
                                else if (this.LastUpdateUtc > loadInfo.UpdateUtc)
                                {
                                    if (loadInfo.Load == ResourceLoad.Full)
                                    {
                                        loadInfo.Load = resourceLoad;
                                    }
                                    else if (loadInfo.Load == ResourceLoad.Critical)
                                    {
                                        loadInfo.Load = new ResourceLoad(resourceMetricPolicy.MaxOverloaded.LoadRatio, new int?(metricValue), null);
                                    }
                                    else if (resourceLoad.State == ResourceLoadState.Underloaded)
                                    {
                                        double num = (resourceMetricPolicy.MaxOverloaded - ResourceLoad.Full) / (double)CacheableResourceHealthMonitor.numberOfAdjustmentSteps;
                                        if (loadInfo.Load - ResourceLoad.Full > num)
                                        {
                                            loadInfo.Load -= num;
                                        }
                                        else
                                        {
                                            loadInfo.Load = new ResourceLoad(ResourceLoad.Full.LoadRatio, new int?(metricValue), null);
                                        }
                                    }
                                }
                                break;

                            case ResourceLoadState.Overloaded:
                                if (loadInfo.Load < resourceLoad)
                                {
                                    loadInfo.Load = resourceLoad;
                                }
                                else if (this.LastUpdateUtc > loadInfo.UpdateUtc)
                                {
                                    double delta = (resourceMetricPolicy.MaxOverloaded - ResourceLoad.Full) / (double)CacheableResourceHealthMonitor.numberOfAdjustmentSteps;
                                    if (loadInfo.Load + delta <= resourceMetricPolicy.MaxOverloaded)
                                    {
                                        loadInfo.Load += delta;
                                    }
                                    else
                                    {
                                        loadInfo.Load = new ResourceLoad(ResourceLoad.Critical.LoadRatio, new int?(metricValue), null);
                                    }
                                }
                                break;

                            case ResourceLoadState.Critical:
                                loadInfo.Load = resourceLoad;
                                break;
                            }
                        }
                    }
                    finally
                    {
                        if (Monitor.IsEntered(this.instanceLock))
                        {
                            Monitor.Exit(this.instanceLock);
                        }
                    }
                }
                resourceLoad = loadInfo.Load;
            }
            object resourceLoadlInfo = this.GetResourceLoadlInfo(resourceLoad);

            if (resourceLoadlInfo != null)
            {
                resourceLoad = new ResourceLoad(resourceLoad.LoadRatio, resourceLoad.Metric, resourceLoadlInfo);
            }
            ResourceLoadPerfCounterWrapper.Get(this.resourceKey, classification).Update(metricValue, resourceLoad);
            lock (this.lastEntries)
            {
                SystemWorkloadManagerLogEntry value = null;
                this.lastEntries.TryGetValue(classification, out value);
                SystemWorkloadManagerBlackBox.RecordMonitorUpdate(ref value, this.resourceKey, classification, resourceLoad);
                this.lastEntries[classification] = value;
            }
            ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceMetricType, ResourceLoad>((long)this.GetHashCode(), "[ResourceLoadMonitor.GetResourceLoad] MetricType={0}, Current Load={1}.", this.MetricType, resourceLoad);
            return(resourceLoad);
        }