Exemplo n.º 1
0
        public SerializedMetric Serialize <T>(
            MetricType metricType,
            string name,
            T value,
            double sampleRate = 1.0,
            string[] tags     = null)
        {
            var serializedMetric = _serializerHelper.GetOptionalSerializedMetric();

            if (serializedMetric == null)
            {
                return(null);
            }

            var builder = serializedMetric.Builder;
            var unit    = _commandToUnit[metricType];

            builder.Append(_prefix);
            builder.Append(name);
            builder.Append(':');
            builder.AppendFormat(CultureInfo.InvariantCulture, "{0}", value);
            builder.Append('|');
            builder.Append(unit);

            if (sampleRate != 1.0)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "|@{0}", sampleRate);
            }

            _serializerHelper.AppendTags(builder, tags);
            return(serializedMetric);
        }
Exemplo n.º 2
0
 public void SendMetric <T>(MetricType metricType, string name, T value, double sampleRate = 1.0, string[] tags = null)
 {
     if (_randomGenerator.ShouldSend(sampleRate))
     {
         var optionalSerializedMetric = _serializers.MetricSerializer.Serialize(metricType, name, value, sampleRate, tags);
         Send(optionalSerializedMetric, () => _optionalTelemetry?.OnMetricSent());
     }
 }
Exemplo n.º 3
0
        public void SendMetric(MetricType metricType, string name, double value, double sampleRate = 1.0, string[] tags = null)
        {
            if (metricType == MetricType.Set)
            {
                throw new ArgumentException($"{nameof(SendMetric)} does not support `MetricType.Set`.");
            }

            if (_randomGenerator.ShouldSend(sampleRate))
            {
                if (TryDequeueStats(out var stats))
                {
                    stats.Kind                = StatsKind.Metric;
                    stats.Metric.Tags         = tags;
                    stats.Metric.MetricType   = metricType;
                    stats.Metric.StatName     = name;
                    stats.Metric.SampleRate   = sampleRate;
                    stats.Metric.NumericValue = value;

                    Send(stats, () => _optionalTelemetry?.OnMetricSent());
                }
            }
        }
Exemplo n.º 4
0
 public void other_types_of_metric_are_not_supported(MetricType metricType)
 {
     Assert.Throws<NotSupportedException>(() => _statsdPublisher.Publish(new Metric(Some.String(), Some.Double(), metricType)));
 }