From 7cbeaab64683a0e3023b785760d228ccb3df9a7b Mon Sep 17 00:00:00 2001 From: Luke Venediger Date: Sun, 5 May 2013 22:52:24 +0200 Subject: [PATCH] Added more code documentation. Added DebuggerDisplay attributes to the client library and the timing token. --- StatsdClient/MetricType.cs | 15 ++++++++++ StatsdClient/Statsd.cs | 39 ++++++++++++++++++++++++++ StatsdClient/StatsdClientExtensions.cs | 3 ++ StatsdClient/TimingToken.cs | 7 +++++ 4 files changed, 64 insertions(+) diff --git a/StatsdClient/MetricType.cs b/StatsdClient/MetricType.cs index 3e6d489..014336d 100644 --- a/StatsdClient/MetricType.cs +++ b/StatsdClient/MetricType.cs @@ -5,11 +5,26 @@ using System.Text; namespace StatsdClient { + /// + /// A list of metric types that statsd.net supports + /// public static class MetricType { + /// + /// The number of times something happened. + /// public const string COUNT = "c"; + /// + /// The time it took for something to happen. + /// public const string TIMING = "ms"; + /// + /// The value of some measurement at this very moment. + /// public const string GAUGE = "g"; + /// + /// The number of times each event has been seen. + /// public const string SET = "s"; } } diff --git a/StatsdClient/Statsd.cs b/StatsdClient/Statsd.cs index d2e8037..4508310 100644 --- a/StatsdClient/Statsd.cs +++ b/StatsdClient/Statsd.cs @@ -6,6 +6,10 @@ using System.Text; namespace StatsdClient { + /// + /// The statsd client library. + /// + [DebuggerDisplay("{host}:{port}")] public class Statsd : IStatsd { private string _prefix; @@ -40,26 +44,53 @@ namespace StatsdClient } } + /// + /// Log a counter. + /// + /// The metric name. + /// The counter value (defaults to 1). public void LogCount(string name, int count = 1) { SendMetric(MetricType.COUNT, name, _prefix, count); } + /// + /// Log a timing / latency + /// + /// The metric name. + /// The duration, in milliseconds, for this metric. public void LogTiming(string name, int milliseconds) { SendMetric(MetricType.TIMING, name, _prefix, milliseconds); } + /// + /// Log a timing / latency + /// + /// The metric name. + /// The duration, in milliseconds, for this metric. public void LogTiming(string name, long milliseconds) { LogTiming(name, (int)milliseconds); } + /// + /// Log a gauge. + /// + /// The metric name + /// The value for this gauge public void LogGauge(string name, int value) { SendMetric(MetricType.GAUGE, name, _prefix, value); } + /// + /// Log to a set + /// + /// The metric name. + /// The value to log. + /// Logging to a set is about counting the number + /// of occurrences of each event. public void LogSet(string name, int value) { SendMetric(MetricType.SET, name, _prefix, value); @@ -78,6 +109,14 @@ namespace StatsdClient _outputChannel.Send(PrepareMetric(metricType, name, prefix, value)); } + /// + /// Prepare a metric prior to sending it off ot the Graphite server. + /// + /// + /// + /// + /// + /// The formatted metric protected virtual string PrepareMetric(string metricType, string name, string prefix, int value) { return (prefix != null ? (prefix + "." + name) : name) + ":" + value + "|" + metricType; diff --git a/StatsdClient/StatsdClientExtensions.cs b/StatsdClient/StatsdClientExtensions.cs index b33029f..72a3a06 100644 --- a/StatsdClient/StatsdClientExtensions.cs +++ b/StatsdClient/StatsdClientExtensions.cs @@ -5,6 +5,9 @@ using System.Text; namespace StatsdClient { + /// + /// A set of extensions for use with the StatsdClient library. + /// public static class StatsdClientExtensions { /// diff --git a/StatsdClient/TimingToken.cs b/StatsdClient/TimingToken.cs index a91b1db..93fd681 100644 --- a/StatsdClient/TimingToken.cs +++ b/StatsdClient/TimingToken.cs @@ -6,6 +6,10 @@ using System.Text; namespace StatsdClient { + /// + /// A class that is used to measure a latency wrapped in a using block. + /// + [DebuggerDisplay("{_name} - IsActive = {_stopwatch.IsRunning}")] public sealed class TimingToken : IDisposable { private IStatsd _client; @@ -19,6 +23,9 @@ namespace StatsdClient _name = name; } + /// + /// Stops the internal timer and logs a latency metric. + /// public void Dispose() { _stopwatch.Stop();