public static ICounterPayload GenerateCounterPayload( bool isIncrementingCounter, string counterName, double counterValue, int displayRateTimeScaleSeconds = 0, string displayName = "", string displayUnits = "") { if (isIncrementingCounter) { Dictionary <string, object> payloadFields = new Dictionary <string, object>() { { "Name", counterName }, { "Increment", counterValue }, { "DisplayName", displayName }, { "DisplayRateTimeScale", displayRateTimeScaleSeconds == 0 ? "" : TimeSpan.FromSeconds(displayRateTimeScaleSeconds).ToString() }, { "DisplayUnits", displayUnits }, }; ICounterPayload payload = new IncrementingCounterPayload(payloadFields, 1); return(payload); } else { Dictionary <string, object> payloadFields = new Dictionary <string, object>() { { "Name", counterName }, { "Mean", counterValue }, { "DisplayName", displayName }, { "DisplayUnits", displayUnits }, }; ICounterPayload payload = new CounterPayload(payloadFields); return(payload); } }
internal override void WritePayload(float intervalSec) { lock (MyLock) // Lock the counter { IncrementingCounterPayload payload = new IncrementingCounterPayload(); payload.Name = _name; payload.IntervalSec = intervalSec; payload.DisplayName = DisplayName ?? ""; payload.DisplayRateTimeScale = (DisplayRateTimeScale == TimeSpan.Zero) ? "" : DisplayRateTimeScale.ToString("c"); payload.MetaData = GetMetaDataString(); payload.Increment = _increment - _prevIncrement; _prevIncrement = _increment; _eventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new IncrementingEventCounterPayloadType(payload)); } }
internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (MyLock) // Lock the counter { IncrementingCounterPayload payload = new IncrementingCounterPayload(); payload.Name = Name; payload.IntervalSec = intervalSec; payload.DisplayName = DisplayName ?? ""; payload.DisplayRateTimeScale = (DisplayRateTimeScale == TimeSpan.Zero) ? "" : DisplayRateTimeScale.ToString("c"); payload.Series = $"Interval={pollingIntervalMillisec}"; // TODO: This may need to change when we support multi-session payload.CounterType = "Sum"; payload.Metadata = GetMetadataString(); payload.Increment = _increment - _prevIncrement; _prevIncrement = _increment; EventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new IncrementingEventCounterPayloadType(payload)); } }
public IncrementingPollingCounterPayloadType(IncrementingCounterPayload payload) { Payload = payload; }