public long? ReportWorkingSet()
        {
            // AppPool not found -> is not started -> 0 memory in use.
            if (string.IsNullOrEmpty(this.counterName))
                return 0;

            if (this.workingSetListener == null)
            {
                try
                {
                    this.workingSetListener = new CounterListener("Process", this.counterName, "Working Set");
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (this.workingSetListener == null)
                return 0;

            try
            {
                float? value = this.workingSetListener.ReportValue();

                return value.HasValue ? (long)value.Value : default(long?);
            }
            catch (InvalidOperationException)
            {
                // counter not available.
                this.workingSetListener = null;

                return 0;
            }
        }
Exemple #2
0
        private Action CreateReportingAction(CounterListenerElement config)
        {
            CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter, _counterFactory);

            IMonitoringChannel channel;

            if (config.Sampling.HasValue)
            {
                channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value);
            }
            else
            {
                channel = this.factory.CreateChannel(config.Type, config.Target);
            }

            this.counters.Add(listener);

            return(() =>
            {
                float?value = null;
                try
                {
                    value = listener.ReportValue();
                }
                catch (InvalidOperationException ex)
                {
                    Logger.Error(ex, "Failed to report value from counter. It will retry on next interval");
                }

                if (value.HasValue)
                {
                    channel.Report(config.Key, value.Value);
                }
            });
        }
Exemple #3
0
        private Action CreateReportingAction(CounterListenerElement config)
        {
            CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter);

            IMonitoringChannel channel;

            if (config.Sampling.HasValue)
            {
                channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value);
            }
            else
            {
                channel = this.factory.CreateChannel(config.Type, config.Target);
            }

            this.counters.Add(listener);

            return(() =>
            {
                float?value = listener.ReportValue();

                if (value.HasValue)
                {
                    channel.Report(config.Key, (long)value.Value);
                }
            });
        }
        public float? ReportValue()
        {
            // AppPool not found -> is not started.
            if (string.IsNullOrEmpty(this.counterName) && !LoadCounterName())
                return null;

            if (this.counterListener == null)
            {
                try
                {
                    this.counterListener = new CounterListener(category, this.counterName, counter);
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (this.counterListener == null)
                return null;

            try
            {

                return this.counterListener.ReportValue(); ;
            }
            catch (InvalidOperationException)
            {
                // counter not available.
                this.counterListener = null;

                return null;
            }
        }
        public void LoadCounterName()
        {
            string newName = this.GetCounterName(this.appPoolName);

            if (!string.IsNullOrEmpty(newName) && this.counterName != newName)
            {
                if (this.workingSetListener != null)
                {
                    this.workingSetListener.Dispose();

                    this.workingSetListener = null;
                }

                this.counterName = newName;
            }
        }
Exemple #6
0
        public void LoadCounterName()
        {
            string newName = this.GetCounterName(this.appPoolName);

            if (!string.IsNullOrEmpty(newName) && this.counterName != newName)
            {
                if (this.workingSetListener != null)
                {
                    this.workingSetListener.Dispose();

                    this.workingSetListener = null;
                }

                this.counterName = newName;
            }
        }
        public bool LoadCounterName()
        {
            string newName = this.GetCounterName(this.appPoolName);

            if (!string.IsNullOrEmpty(newName) && this.counterName != newName)
            {
                if (this.counterListener != null)
                {
                    this.counterListener.Dispose();

                    this.counterListener = null;
                }

                this.counterName = newName;

                return(true);
            }

            return(false);
        }
        public bool LoadCounterName()
        {
            string newName = this.GetCounterName(this.appPoolName);

            if (!string.IsNullOrEmpty(newName) && this.counterName != newName)
            {
                if (this.counterListener != null)
                {
                    this.counterListener.Dispose();

                    this.counterListener = null;
                }

                this.counterName = newName;

                return true;
            }

            return false;
        }
        public float?ReportValue()
        {
            // AppPool not found -> is not started.
            if (string.IsNullOrEmpty(this.counterInstanceName) && !LoadCounterInstanceName())
            {
                return(null);
            }

            if (this.counterListener == null)
            {
                try
                {
                    this.counterListener = new CounterListener(category, this.counterInstanceName, counter, _counterFactory);
                }
                catch (InvalidOperationException ex)
                {
                    Logger.Warn(ex, "Failed to initialize counter: {0}, {1}, {2}", category, counterInstanceName, counter);
                }
            }

            if (this.counterListener == null)
            {
                return(null);
            }

            try
            {
                return(this.counterListener.ReportValue());;
            }
            catch (InvalidOperationException ex)
            {
                Logger.Warn(ex, "Failed to ReportValue from counter: {0}, {1}, {2}", category, counter, counterInstanceName);
                // counter not available.
                _counterInstanceNameCache.ReportInvalid(appPoolName, counterInstanceName);
                this.counterListener     = null;
                this.counterInstanceName = null;

                return(null);
            }
        }
Exemple #10
0
        public long?ReportWorkingSet()
        {
            // AppPool not found -> is not started -> 0 memory in use.
            if (string.IsNullOrEmpty(this.counterName))
            {
                return(0);
            }

            if (this.workingSetListener == null)
            {
                try
                {
                    this.workingSetListener = new CounterListener("Process", this.counterName, "Working Set");
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (this.workingSetListener == null)
            {
                return(0);
            }

            try
            {
                float?value = this.workingSetListener.ReportValue();

                return(value.HasValue ? (long)value.Value : default(long?));
            }
            catch (InvalidOperationException)
            {
                // counter not available.
                this.workingSetListener = null;

                return(0);
            }
        }
        public float?ReportValue()
        {
            // AppPool not found -> is not started.
            if (string.IsNullOrEmpty(this.counterName) && !LoadCounterName())
            {
                return(null);
            }

            if (this.counterListener == null)
            {
                try
                {
                    this.counterListener = new CounterListener(category, this.counterName, counter);
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (this.counterListener == null)
            {
                return(null);
            }

            try
            {
                return(this.counterListener.ReportValue());;
            }
            catch (InvalidOperationException)
            {
                // counter not available.
                this.counterListener = null;

                return(null);
            }
        }
Exemple #12
0
        private Action CreateReportingAction(CounterListenerElement config)
        {
            CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter);

            IMonitoringChannel channel;

            if (config.Sampling.HasValue)
            {
                channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value);
            }
            else
            {
                channel = this.factory.CreateChannel(config.Type, config.Target);
            }

            this.counters.Add(listener);

            return () =>
            {
                float? value = listener.ReportValue();

                if (value.HasValue)
                {
                    channel.Report(config.Key, (int)value.Value);
                }
            };
        }