public void HeartBeat() { //perform and process the counterreading every 'heartbeat' PerformanceMonitorRecord activeMonitorRecord = _performanceMonitorDataService.PerformanceMonitorRecords.FirstOrDefault(r => r.IsEnabled == true); string performanceCounterReading = _performanceCounterService.GetPerformanceCounterReading(activeMonitorRecord.CategoryName, activeMonitorRecord.InstanceName, activeMonitorRecord.CounterName); //calculate the the duration (in ticks) DateTime startTime = (DateTime)activeMonitorRecord.Created; TimeSpan durationCount = DateTime.Now.Subtract(startTime); //threshold check bool passedThreshold; var passedThresholdValue = 0; double countervalue = double.Parse(performanceCounterReading); passedThreshold = CheckThreshold(activeMonitorRecord.Threshold, activeMonitorRecord.ThresholdWhen, countervalue, ref passedThresholdValue); PerformanceMonitorDataRecord dataRecord = new PerformanceMonitorDataRecord() { PerformanceMonitorRecord_Id = activeMonitorRecord.Id, Count = performanceCounterReading, HeartBeat = DateTime.Now, PassedThreshold = passedThreshold, PassedThresholdValue = passedThresholdValue, Ticks = Convert.ToString(durationCount.Ticks) }; _performanceMonitorDataService.WriteDataRecord(dataRecord); }
public bool EditPost(EditPostInputModel inputModel) { string performanceCounterReading = _performanceCounterService.GetPerformanceCounterReading(inputModel.CategoryName, inputModel.InstanceName, inputModel.CounterName); if (performanceCounterReading == String.Empty) { _notifier.Error(T("Error: Not able to perform a reading on this type of counter")); return(false); } PerformanceMonitorRecord record = new PerformanceMonitorRecord() { Id = inputModel.Id, CategoryName = inputModel.CategoryName, InstanceName = inputModel.InstanceName, CounterName = inputModel.CounterName, InitialValue = performanceCounterReading, Duration = inputModel.Duration, SampleInterval = inputModel.SampleInterval, Threshold = inputModel.Threshold, ThresholdWhen = inputModel.ThresholdWhen }; var result = _performanceMonitorDataService.SetPerformanceMonitorRecord(record); if (result) { PerformanceMonitorRecord activeRecord = _performanceMonitorDataService.PerformanceMonitorRecords.FirstOrDefault(r => r.IsEnabled == true); //threshold check bool passedThreshold; var passedThresholdValue = 0; double countervalue = double.Parse(activeRecord.InitialValue); passedThreshold = _performanceMonitorService.CheckThreshold(activeRecord.Threshold, activeRecord.ThresholdWhen, countervalue, ref passedThresholdValue); PerformanceMonitorDataRecord datarecord = new PerformanceMonitorDataRecord() { PerformanceMonitorRecord_Id = activeRecord.Id, Count = activeRecord.InitialValue, HeartBeat = activeRecord.Created, PassedThreshold = passedThreshold, PassedThresholdValue = passedThresholdValue, //duration count(ticks in nanoseconds from starttime (created)) should initially be set to startvalue (zero) Ticks = "0" }; var dataResult = _performanceMonitorDataService.WriteDataRecord(datarecord); if (dataResult) { _notifier.Information(T("New counter records added succesfully")); } else { _notifier.Warning(T("New counter record added succesfully, but failed to write initial datarecord")); } } else { _notifier.Error(T("Error: Failed to add new counter")); } return(result); }