Example #1
0
        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);
                    }
                }
            }
        }
Example #2
0
 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);
     }
 }
Example #3
0
        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);
            }
        }