public void Send(InfluxPoint point) { using (var writer = new StringWriter()) { point.Format(writer, _tags); _udp.Send(writer.ToString()); } }
public void KeepDelivering(CancellationToken token) { var list = new List <InfluxPoint>(_batchSize); while (!token.IsCancellationRequested) { try { list.Clear(); InfluxPoint point; while (_queue.TryDequeue(out point) && (list.Count < list.Capacity)) { list.Add(point); } if (list.Count == 0) { // nothing to send. Sleep token.WaitHandle.WaitOne(200); continue; } using (var writer = new StringWriter()) { for (int i = 0; i < list.Count; i++) { if (i > 0) { writer.Write('\n'); } list[i].Format(writer, _tags); } _udp.Send(writer.ToString()); } } catch (Exception ex) { Interlocked.Increment(ref _failed); DiagnosticsLog.WriteLine("Failed to send metrics: {0}", ex); } } }