void OnTick() { try { Queue <PointData> batch; lock (_queueLock) { if (_queue.Count == 0) { return; } batch = _queue; _queue = new Queue <PointData>(); } _parent.Emit(batch.ToArray()); } catch (Exception ex) { CollectorLog.WriteLine("Failed to emit metrics batch: {0}", ex); } finally { lock (_stateLock) { if (!_unloading) { _timer.Start(_interval); } } } }
public void Write(string measurement, IReadOnlyDictionary <string, object> fields, IReadOnlyDictionary <string, string> tags = null) { try { var point = new PointData(measurement, fields, tags, DateTime.UtcNow); Emit(new[] { point }); } catch (Exception ex) { CollectorLog.WriteLine("Failed to write point: {0}", ex); } }
public void Emit(PointData[] points) { var payload = new LineProtocolPayload(); foreach (var point in points) { payload.Add(new LineProtocolPoint(point.Measurement, point.Fields, point.Tags, point.UtcTimestamp)); } var influxResult = _client.WriteAsync(payload).Result; if (!influxResult.Success) { CollectorLog.WriteLine(influxResult.ErrorMessage); } }