protected override Task OnSend(IEnumerable <Event> events) { _pump ??= _autofac.Resolve <IMessagePump>(); var eventsList = events.ToList(); foreach (var log in eventsList .Select(x => x.Lg) .Where(x => x != null)) { switch (log.Severity) { case SeverityType.Fatal: _logger.LogCritical(log.Body); break; case SeverityType.Error: _logger.LogError(log.Body); break; case SeverityType.Warning: _logger.LogWarning(log.Body); break; case SeverityType.Info: _logger.LogInformation(log.Body); break; case SeverityType.Verbose: _logger.LogDebug(log.Body); break; default: _logger.LogTrace(log.Body); break; } } _pump.OnEmbeddedEvents(eventsList); return(Task.CompletedTask); }
public void OnNewMeasure(Event metric) { var metTime = DateTimeOffset.FromUnixTimeMilliseconds(metric.Created).UtcDateTime; lock (this) { var actualIntervalStart = _dto.ActualInterval.AddMinutes(-5); var actualIntervalEnd = _dto.ActualInterval; // interval with epsilon var intervalStart = actualIntervalStart.AddMilliseconds(-IntervalEpsilon); var intervalEnd = actualIntervalEnd.AddMilliseconds(IntervalEpsilon); if ((metTime < intervalStart || metTime > intervalEnd) && (metric.Mc.Name.ToLower() != "outtimemeasure")) { // skip event // increase skip metric _monik.Measure("OutTimeMeasure", AggregationType.Accumulator, 1); var ev = NewMeasureEvent(metric.Source, metric.Instance, "OutTimeMeasure", 1, AggregationType.Accumulator); _pump.OnEmbeddedEvents(new Event[1] { ev }); var serverTime = DateTime.UtcNow; var diffInterval = metTime < intervalStart ? (metTime - actualIntervalStart).TotalMilliseconds : (metTime - actualIntervalEnd).TotalMilliseconds; var diffServer = (serverTime - metTime).TotalMilliseconds; _monik.LogicVerbose($@"[OutTime] {metric.Source}.{metric.Instance}::{metric.Mc.Name}, lag:{diffServer}, lagInterval:{diffInterval}, {metric.Created} not in [{new DateTimeOffset(actualIntervalStart).ToUnixTimeMilliseconds()},{new DateTimeOffset(actualIntervalEnd).ToUnixTimeMilliseconds()}), now:{new DateTimeOffset(serverTime).ToUnixTimeMilliseconds()}"); return; } var actualMeasure = GetMeasure(_dto.ActualID); switch (metric.Mc.Aggregation) { case AggregationType.Accumulator: if (actualMeasure.HasValue) { actualMeasure.Value += metric.Mc.Value; } else { actualMeasure.Value = metric.Mc.Value; actualMeasure.HasValue = true; } AccumWindowCalculator accWin = window as AccumWindowCalculator; if (accWin == null) { window = new AccumWindowCalculator(); } window.OnNewValue(metric.Mc.Value); break; case AggregationType.Gauge: if (actualMeasure.HasValue) { actualMeasure.Value = (actualMeasure.Value + metric.Mc.Value) / 2; } else { actualMeasure.Value = metric.Mc.Value; actualMeasure.HasValue = true; } GaugeWindowCalculator gauWin = window as GaugeWindowCalculator; if (gauWin == null) { window = new GaugeWindowCalculator(); } window.OnNewValue(metric.Mc.Value); break; default: // skip event // increase skip metric break; } }//lock }