Ejemplo n.º 1
0
        public MetricSnapshotHostedMetricsJsonWriter(
            Stream stream,
            TimeSpan flushInterval,
            Func <IHostedMetricsPointTextWriter> metricPointTextWriter = null)
        {
            _stream        = stream ?? throw new ArgumentNullException(nameof(stream));
            _flushInterval = flushInterval;
            _points        = new HostedMetricsPoints();

            _metricPointTextWriter = metricPointTextWriter != null?metricPointTextWriter() : HostedMetricsFormatterConstants.GraphiteDefaults.MetricPointTextWriter();
        }
Ejemplo n.º 2
0
        public MetricSnapshotHostedMetricsJsonWriter(
            TextWriter textWriter,
            Func <IHostedMetricsPointTextWriter> metricPointTextWriter = null,
            GeneratedMetricNameMapping dataKeys = null)
        {
            _textWriter = textWriter ?? throw new ArgumentNullException(nameof(textWriter));
            _points     = new HostedMetricsPoints();

            _metricPointTextWriter = metricPointTextWriter != null?metricPointTextWriter() : HostedMetricsFormatterConstants.GraphiteDefaults.MetricPointTextWriter();

            MetricNameMapping = dataKeys ?? new GeneratedMetricNameMapping();
        }
        public HostedMetricsPoint(
            string context,
            string measurement,
            IReadOnlyDictionary <string, object> fields,
            MetricTags tags,
            IHostedMetricsPointTextWriter pointTextWriter,
            TimeSpan flushInterval,
            DateTime?utcTimestamp = null)
        {
            _pointTextWriter = pointTextWriter ?? throw new ArgumentNullException(nameof(pointTextWriter));

            FlushInterval = flushInterval;

            if (string.IsNullOrEmpty(measurement))
            {
                throw new ArgumentException("A measurement must be specified", nameof(measurement));
            }

            if (fields == null || fields.Count == 0)
            {
                throw new ArgumentException("At least one field must be specified", nameof(fields));
            }

            if (fields.Any(f => string.IsNullOrEmpty(f.Key)))
            {
                throw new ArgumentException("Fields must have non-empty names", nameof(fields));
            }

            if (utcTimestamp != null && utcTimestamp.Value.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException("Timestamps must be specified as UTC", nameof(utcTimestamp));
            }

            Context      = context;
            Measurement  = measurement;
            Fields       = fields;
            Tags         = tags;
            UtcTimestamp = utcTimestamp ?? DateTime.UtcNow;
        }