/** * statsd has no notion of batch request, so counters are pushed as they are received */ public void AddCounter(DatadogCounter counter) { string[] tags = counter.Tags.ToArray(); StringBuilder sb = new StringBuilder(""); for (int i = tags.Length - 1; i >= 0; i--) { sb.Append(tags[i]); if (i > 0) { sb.Append(","); } } string metric = counter.Name; string readonlyMetricsSeenName = metric + ":" + sb.ToString(); long rawValue = counter.Value; long readonlyValue = rawValue; if (_lastSeenCounters.ContainsKey(readonlyMetricsSeenName)) { // If we've seen this counter before then calculate the difference // by subtracting the new value from the old. StatsD expects a relative // counter, not an absolute! readonlyValue = Math.Max(0, rawValue - _lastSeenCounters[readonlyMetricsSeenName]); } // Store the last value we saw so that the next addCounter call can make // the proper relative value _lastSeenCounters.Add(readonlyMetricsSeenName, rawValue); DogStatsd.Counter(metric, readonlyValue, _sampleRate, tags); }
public void SplitNameAndTags() { IDictionary <string, string> tags = new Dictionary <string, string>(); tags.Add("env", "prod"); tags.Add("version", "1.0.0"); DatadogCounter counter = new DatadogCounter( "test[tag1:value1,tag2:value2,tag3:value3]", 1L, 1234L, tags); IList <string> allTags = counter.Tags; Assert.AreEqual(5, allTags.Count); Assert.AreEqual("tag1:value1", allTags[0]); Assert.AreEqual("tag2:value2", allTags[1]); Assert.AreEqual("tag3:value3", allTags[2]); Assert.AreEqual("env:prod", allTags[3]); Assert.AreEqual("version:1.0.0", allTags[4]); }
public void AddCounter(DatadogCounter counter) { Metrics.Add(counter.Name, counter); }