//------------------------------------------------------------------------------ // // Method: ProcessCountMetricEvent // //------------------------------------------------------------------------------ /// <summary> /// Writes a count metric event to the database. /// </summary> /// <param name="countMetricEvent">The count metric event to write.</param> protected override void ProcessCountMetricEvent(CountMetricEventInstance countMetricEvent) { StringBuilder sqlInsertStatement = new StringBuilder(); sqlInsertStatement.Append("INSERT "); sqlInsertStatement.Append("INTO CountMetricInstances "); sqlInsertStatement.Append(" ( CmetId, "); sqlInsertStatement.Append(" CtgrId, "); sqlInsertStatement.Append(" [Timestamp] "); sqlInsertStatement.Append(" ) "); sqlInsertStatement.Append("SELECT Cmet.CmetId, "); sqlInsertStatement.Append(" Ctgr.CtgrId, "); sqlInsertStatement.Append(" '" + countMetricEvent.EventTime.ToString("yyyy-MM-dd HH:mm:ss") + "' "); sqlInsertStatement.Append("FROM CountMetrics Cmet, "); sqlInsertStatement.Append(" Categories Ctgr "); sqlInsertStatement.Append("WHERE Cmet.Name = '" + countMetricEvent.Metric.Name + "' "); sqlInsertStatement.Append(" AND Ctgr.Name = '" + metricCategoryName + "';"); dbCommand.CommandText = sqlInsertStatement.ToString(); try { dbCommand.ExecuteNonQuery(); } catch (Exception e) { exceptionHandler.Handle(new Exception("Failed to insert instance of count metric '" + countMetricEvent.Metric.Name + "'.", e)); } }
protected override void ProcessCountMetricEvent(CountMetricEventInstance countMetricEvent) { StringBuilder stringBuilder = InitializeStringBuilder(countMetricEvent.EventTime.ToLocalTime()); stringBuilder.Append(countMetricEvent.Metric.Name); streamWriter.WriteLine(stringBuilder.ToString()); streamWriter.Flush(); }
//------------------------------------------------------------------------------ // // Method: ProcessCountMetricEvent // //------------------------------------------------------------------------------ /// <summary> /// Adds the instance of the specified count metric event to the stored total. /// </summary> /// <param name="countMetricEvent">The count metric event.</param> protected override void ProcessCountMetricEvent(CountMetricEventInstance countMetricEvent) { if (countMetricTotals.ContainsKey(countMetricEvent.MetricType) == false) { countMetricTotals.Add(countMetricEvent.MetricType, new CountMetricTotalContainer(countMetricEvent.Metric)); } countMetricTotals[countMetricEvent.MetricType].Increment(); }
//------------------------------------------------------------------------------ // // Method: DequeueAndProcessCountMetricEvents // //------------------------------------------------------------------------------ /// <summary> /// Dequeues count metric events stored in the internal buffer and calls abstract method ProcessCountMetricEvent() to process them. /// </summary> private void DequeueAndProcessCountMetricEvents() { Queue <CountMetricEventInstance> tempQueue; // Lock the count metric queue and move all items to the temporary queue lock (countMetricEventQueueLock) { tempQueue = new Queue <CountMetricEventInstance>(countMetricEventQueue); countMetricEventQueue.Clear(); bufferProcessingStrategy.NotifyCountMetricEventBufferCleared(); } // Process all items in the temporary queue while (tempQueue.Count > 0) { CountMetricEventInstance currentCountMetricEvent = tempQueue.Dequeue(); ProcessCountMetricEvent(currentCountMetricEvent); } }
//------------------------------------------------------------------------------ // // Method: ProcessCountMetricEvent // //------------------------------------------------------------------------------ /// <summary> /// Processes a logged count metric event. /// </summary> /// <param name="countMetricEvent">The count metric event to process.</param> /// <remarks>Implementations of this method define how a count metric event should be processed after it has been retrieved from the internal buffer queue. The event could for example be written to a database, or to the console.</remarks> protected abstract void ProcessCountMetricEvent(CountMetricEventInstance countMetricEvent);