예제 #1
0
        private void Finalize(IMeasurement m, Point point)
        {
            m.AddField("elapsed", m.GetElapsed().TotalMilliseconds);
            m.AddTag("isCheckpoint", false);

            point.Fields = m.Fields;
            point.Tags   = m.Tags;
            _queue.Enqueue(point);

            if (m.Checkpoints.Any())
            {
                //NOTE: Prepare all checkpoints
                var prev  = TimeSpan.Zero;
                var index = 0;
                foreach (var checkpoint in m.Checkpoints)
                {
                    var pointFields = point.Fields.Where(x => x.Key != "value").ToDictionary(x => x.Key, x => x.Value);
                    var pointTags   = point.Tags.Where(x => x.Key != "checkpoint" && x.Key != "isCheckpoint" && x.Key != "index").ToDictionary(x => x.Key, x => x.Value);
                    pointFields.Add("value", (checkpoint.Value - prev).TotalMilliseconds);
                    pointTags.Add("isCheckpoint", true);
                    pointTags.Add("checkpoint", checkpoint.Key);
                    pointTags.Add("index", index++);

                    var check = new Point
                    {
                        Measurement = point.Measurement,
                        Fields      = pointFields,
                        Tags        = pointTags,
                        Timestamp   = point.Timestamp,
                        Precision   = point.Precision,
                    };
                    _queue.Enqueue(check);

                    prev = checkpoint.Value;
                }

                //NOTE: Prepare the end point checkpoint
                {
                    var pointFields = point.Fields.Where(x => x.Key != "value").ToDictionary(x => x.Key, x => x.Value);
                    var pointTags   = point.Tags.Where(x => x.Key != "elapsed" && x.Key != "isCheckpoint").ToDictionary(x => x.Key, x => x.Value);
                    pointFields.Add("value", (m.GetElapsed() - prev).TotalMilliseconds);
                    pointTags.Add("isCheckpoint", true);
                    pointTags.Add("checkpoint", "End");
                    pointTags.Add("index", index);

                    var check = new Point
                    {
                        Measurement = point.Measurement,
                        Fields      = pointFields,
                        Tags        = pointTags,
                        Timestamp   = point.Timestamp,
                        Precision   = point.Precision,
                    };
                    _queue.Enqueue(check);
                }
            }
        }