protected virtual K ExecuteFunction <K>(HealthTrackType type, string methodName, Func <K> function, params object[] parameters) { using (var scope = HealthReporter.BeginTrack(type, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName))) { return(base.ExecuteFunction <K>(methodName, function, parameters)); } }
protected virtual void ExecuteMethod(HealthTrackType type, string methodName, Action action, params object[] parameters) { using (var scope = HealthReporter.BeginTrack(type, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName))) { base.ExecuteMethod(methodName, action, parameters); } }
public HealthTrackScope(HealthTrackType trackType, string trackName, int count = 1) { this.Count = count; this.TrackType = trackType; this.TrackName = trackName; this.Stopwatch = Stopwatch.StartNew(); }
/// <summary> /// Tracks metrics to graphite /// </summary> /// <param name="type">The operation transform to apply</param> /// <param name="trackName">The name to track</param> /// <param name="milliseconds">Ignored if each or none</param> /// <param name="count">Ignored if each or none</param> public virtual void UpdateMetric(HealthTrackType type, string trackName, long milliseconds, int count) { try { if (type == HealthTrackType.None) { return; } if (type == HealthTrackType.Count || type == HealthTrackType.CountAndDurationAverage) { string key = trackName + ".count"; if (!this.Metrics.ContainsKey(key)) { this.Metrics[key] = 0; } this.Metrics[key] += count; } // must run after count to include current if (type == HealthTrackType.DurationAverage || type == HealthTrackType.CountAndDurationAverage) { double minutesSinceLastReset = (DateTime.UtcNow - this.LastReset).TotalMinutes; if (minutesSinceLastReset > 0) // jic, no zero divide [shouldnt happen] { string key = trackName + ".durationavg"; string totalKey = trackName + ".total"; string countkey = trackName + ".count"; decimal countSinceLast = 0; decimal totalSinceLast = 0; this.Metrics.TryGetValue(countkey, out countSinceLast); this.Interim.TryGetValue(totalKey, out totalSinceLast); countSinceLast++; totalSinceLast += milliseconds; this.Interim[totalKey] = totalSinceLast; this.Metrics[key] = (totalSinceLast / countSinceLast); } } if (type == HealthTrackType.Each) { string prefix = string.Format("{0}.", GetHostName()); this.Logs.Add(prefix + string.Format(HealthReporter.EACH_FORMAT, trackName, DateTime.UtcNow.ToUnixSecondsUTC().ToString("###0"))); } } catch (Exception ex) { base.IFoundation.LogError(ex, "UpdateMetric"); } }
/// <summary> /// Tracks metrics to graphite /// </summary> /// <param name="type">The operation transform to apply</param> /// <param name="trackName">The name to track</param> /// <param name="milliseconds">Ignored if each or none</param> /// <param name="count">Ignored if each or none</param> public virtual void UpdateMetric(HealthTrackType type, string trackName, long milliseconds, int count) { try { if (type == HealthTrackType.None) { return; } lock (SyncLock) { this.Generator.UpdateMetric(type, trackName, milliseconds, count); } } catch (Exception ex) { base.IFoundation.LogError(ex, "UpdateMetric"); } }
public static IDisposable BeginTrack(HealthTrackType type, string trackName, int count = 1) { return(new HealthTrackScope(type, trackName, count)); }