示例#1
0
 /// <summary>
 /// Creates the performance counters.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 private void CreatePerformanceCounters(string serviceName)
 {
     try
     {
         PerformanceCounters = new PerformanceCounters(serviceName);
     }
     catch (System.Exception ex)
     {
         PerformanceCounters = new EmptyPerformanceCounters();
         this.WriteEventLog(EventLogEntryType.Error, 3221242660L,
                            string.Concat(AsyncService.HostName, ". 异常: ", ex.ToString()));
         MyTrace.Write(TraceCategory.AsyncService, TraceLevel.Error,
                       "初始化性能计数器时遭遇异常: {0} - {1}", ServiceName, ex);
     }
     // TODO: Register Counters
     //PerformanceCounterFactory.LoadCounters(PerformanceCounterLoadSetting.CreateOnly, "Platform");
     //PerformanceCounterFactory.LoadCounters(PerformanceCounterLoadSetting.CreateOnly, "Server");
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncOperationPerformanceCounters"/> class.
 /// </summary>
 /// <param name="counters">The counters.</param>
 /// <param name="operationName">Name of the operation.</param>
 /// <param name="instanceName">Name of the instance.</param>
 public AsyncOperationPerformanceCounters(PerformanceCounters counters, string operationName,
     string instanceName)
 {
     this._itemsCompleted =
         counters.InitializeCounter(string.Format(ITEMS_COMPLETED_NAME_FORMAT, operationName), instanceName);
     this._itemsCompletedThroughput =
         counters.InitializeCounter(string.Format(ITEMS_COMPLETION_THROUGHPUT_NAME_FORMAT, operationName),
                                    instanceName);
     this._itemsExecuting =
         counters.InitializeCounter(string.Format(ITEMS_EXECUTING_NAME_FORMAT, operationName), instanceName);
     this._itemsFailedWithException =
         counters.InitializeCounter(string.Format(ITEMS_FAILED_WITH_EXCEPTION_NAME_FORMAT, operationName),
                                    instanceName);
     this._itemsFailedWithRetry =
         counters.InitializeCounter(string.Format(ITEMS_FAILED_WITH_RETRY_NAME_FORMAT, operationName),
                                    instanceName);
     this._itemsOutstanding =
         counters.InitializeCounter(string.Format(ITEMS_OUTSTANDING_NAME_FORMAT, operationName), instanceName);
     this._rateFailedWithException =
         counters.InitializeCounter(string.Format(RATE_FAILED_WITH_EXCEPTION_NAME_FORMAT, operationName),
                                    instanceName);
     this._rateFailedWithRetry =
         counters.InitializeCounter(string.Format(RATE_FAILED_WITH_RETRY_NAME_FORMAT, operationName),
                                    instanceName);
     this._averageTime =
         counters.InitializeCounter(string.Format(AVERAGE_TIME_COUNTER_NAME_FORMAT, operationName),
                                    instanceName);
 }