AuditLogDemo.EventSources.ApiEventCounterSource.OnEventCommand C# (CSharp) Method

OnEventCommand() protected method

protected OnEventCommand ( EventCommandEventArgs command ) : void
command EventCommandEventArgs
return void
        protected override void OnEventCommand(EventCommandEventArgs command)
        {
            if (command.Command == EventCommand.Enable)
            {
                //请求响应耗时
                _requestCounter = new EventCounter("request-time", this)
                {
                    DisplayName = "Request Processing Time",
                    DisplayUnits = "ms"
                };

                //内存占用
                _workingSetCounter = new PollingCounter("working-set", this, () => (double)(Environment.WorkingSet / 1_000_000))
                {
                    DisplayName = "Working Set",
                    DisplayUnits = "MB"
                };

                //总请求量
                _totalRequestsCounter = new PollingCounter("total-requests", this, () => Volatile.Read(ref _totalRequests))
                {
                    DisplayName = "Total Requests",
                    DisplayUnits = "次"
                };

                //单位时间请求速率
                _incrementingPollingCounter = new IncrementingPollingCounter("Request Rate", this, () =>
                {
                    return Volatile.Read(ref _totalRequests);
                })
                {
                    DisplayName = "Request Rate",
                    DisplayUnits = "次/s",
                    //时间间隔1s
                    DisplayRateTimeScale = new TimeSpan(0, 0, 1)
                };

                var monitorContentionCounter = new IncrementingPollingCounter("monitor-lock-contention-count", this, () => Monitor.LockContentionCount)
                {
                    DisplayName = "Monitor Lock Contention Count",
                    DisplayRateTimeScale = TimeSpan.FromSeconds(1)
                };
            }
        }