示例#1
0
 public static void LogActivity(CounterType counterType, string organizationName)
 {
     if (TenantMonitor.counterCategoryExist)
     {
         IntervalCounterInstanceCache.IncrementIntervalCounter(organizationName ?? "First Organization", counterType);
     }
 }
示例#2
0
        private static void UpdateCounters(object source, ElapsedEventArgs e)
        {
            ExTraceGlobals.TenantMonitoringTracer.TraceFunction(0L, "Enter UpdateCounters.");
            List <string> list = new List <string>(16);

            try
            {
                IntervalCounterInstanceCache.readerWriterLock.AcquireReaderLock(5000);
            }
            catch (TimeoutException ex)
            {
                IntervalCounterInstanceCache.LogReaderWriterLockTimeoutEvent(ex, "IntervalCounterInstanceCache.UpdateCounters.AcquireReaderLock");
                ExTraceGlobals.TenantMonitoringTracer.TraceFunction(0L, "Exit UpdateCounters.");
                return;
            }
            try
            {
                foreach (KeyValuePair <string, IntervalCounterInstance> keyValuePair in IntervalCounterInstanceCache.instanceDictionary)
                {
                    ExTraceGlobals.TenantMonitoringTracer.Information <string, DateTime, TimeSpan>(0L, "Update counter for key {0}. Last Update {1}. Current inactivityTimeout {2}", keyValuePair.Key, keyValuePair.Value.LastUpdateTime, IntervalCounterInstanceCache.inactivityTimeout);
                    if (keyValuePair.Value.LastUpdateTime + IntervalCounterInstanceCache.inactivityTimeout < DateTime.UtcNow)
                    {
                        list.Add(keyValuePair.Key);
                    }
                    keyValuePair.Value.CalculateIntervalDataAndUpdateCounters(keyValuePair.Key);
                }
            }
            finally
            {
                IntervalCounterInstanceCache.readerWriterLock.ReleaseReaderLock();
            }
            if (list.Count > 0)
            {
                try
                {
                    IntervalCounterInstanceCache.readerWriterLock.AcquireWriterLock(5000);
                }
                catch (TimeoutException ex2)
                {
                    IntervalCounterInstanceCache.LogReaderWriterLockTimeoutEvent(ex2, "IntervalCounterInstanceCache.UpdateCounters.AcquireWriterLock");
                    ExTraceGlobals.TenantMonitoringTracer.TraceFunction(0L, "Exit UpdateCounters.");
                    return;
                }
                try
                {
                    foreach (string text in list)
                    {
                        ExTraceGlobals.TenantMonitoringTracer.Information <string>(0L, "Remove entry {0} from cache.", text);
                        IntervalCounterInstanceCache.instanceDictionary.Remove(text);
                        MSExchangeTenantMonitoring.RemoveInstance(text);
                    }
                }
                finally
                {
                    IntervalCounterInstanceCache.readerWriterLock.ReleaseWriterLock();
                }
            }
            ExTraceGlobals.TenantMonitoringTracer.TraceFunction(0L, "Exit UpdateCounters.");
        }
示例#3
0
        internal static void IncrementIntervalCounter(string instanceName, CounterType counterType)
        {
            IntervalCounterInstance instance = IntervalCounterInstanceCache.GetInstance(instanceName);

            if (instance == null)
            {
                return;
            }
            instance.Increment(counterType);
        }
示例#4
0
        private static IntervalCounterInstance GetInstance(string instanceName)
        {
            try
            {
                IntervalCounterInstanceCache.readerWriterLock.AcquireReaderLock(5000);
            }
            catch (TimeoutException ex)
            {
                IntervalCounterInstanceCache.LogReaderWriterLockTimeoutEvent(ex, "IntervalCounterInstanceCache.GetInstance.AcquireReaderLock");
                return(null);
            }
            IntervalCounterInstance intervalCounterInstance;

            try
            {
                IntervalCounterInstanceCache.instanceDictionary.TryGetValue(instanceName, out intervalCounterInstance);
            }
            finally
            {
                IntervalCounterInstanceCache.readerWriterLock.ReleaseReaderLock();
            }
            if (intervalCounterInstance == null)
            {
                try
                {
                    IntervalCounterInstanceCache.readerWriterLock.AcquireWriterLock(5000);
                }
                catch (TimeoutException ex2)
                {
                    IntervalCounterInstanceCache.LogReaderWriterLockTimeoutEvent(ex2, "IntervalCounterInstanceCache.GetInstance.AcquireWriterLock");
                    return(null);
                }
                try
                {
                    if (!IntervalCounterInstanceCache.instanceDictionary.TryGetValue(instanceName, out intervalCounterInstance))
                    {
                        ExTraceGlobals.TenantMonitoringTracer.Information <string>(0L, "Create perf counter instance for {0}.", instanceName);
                        intervalCounterInstance = new IntervalCounterInstance();
                        IntervalCounterInstanceCache.instanceDictionary[instanceName] = intervalCounterInstance;
                    }
                }
                finally
                {
                    IntervalCounterInstanceCache.readerWriterLock.ReleaseWriterLock();
                }
            }
            return(intervalCounterInstance);
        }