Added more code documentation. Added DebuggerDisplay attributes to the client library and the timing token.
This commit is contained in:
@@ -5,11 +5,26 @@ using System.Text;
|
||||
|
||||
namespace StatsdClient
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of metric types that statsd.net supports
|
||||
/// </summary>
|
||||
public static class MetricType
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of times something happened.
|
||||
/// </summary>
|
||||
public const string COUNT = "c";
|
||||
/// <summary>
|
||||
/// The time it took for something to happen.
|
||||
/// </summary>
|
||||
public const string TIMING = "ms";
|
||||
/// <summary>
|
||||
/// The value of some measurement at this very moment.
|
||||
/// </summary>
|
||||
public const string GAUGE = "g";
|
||||
/// <summary>
|
||||
/// The number of times each event has been seen.
|
||||
/// </summary>
|
||||
public const string SET = "s";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ using System.Text;
|
||||
|
||||
namespace StatsdClient
|
||||
{
|
||||
/// <summary>
|
||||
/// The statsd client library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{host}:{port}")]
|
||||
public class Statsd : IStatsd
|
||||
{
|
||||
private string _prefix;
|
||||
@@ -40,26 +44,53 @@ namespace StatsdClient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a counter.
|
||||
/// </summary>
|
||||
/// <param name="name">The metric name.</param>
|
||||
/// <param name="count">The counter value (defaults to 1).</param>
|
||||
public void LogCount(string name, int count = 1)
|
||||
{
|
||||
SendMetric(MetricType.COUNT, name, _prefix, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a timing / latency
|
||||
/// </summary>
|
||||
/// <param name="name">The metric name.</param>
|
||||
/// <param name="milliseconds">The duration, in milliseconds, for this metric.</param>
|
||||
public void LogTiming(string name, int milliseconds)
|
||||
{
|
||||
SendMetric(MetricType.TIMING, name, _prefix, milliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a timing / latency
|
||||
/// </summary>
|
||||
/// <param name="name">The metric name.</param>
|
||||
/// <param name="milliseconds">The duration, in milliseconds, for this metric.</param>
|
||||
public void LogTiming(string name, long milliseconds)
|
||||
{
|
||||
LogTiming(name, (int)milliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a gauge.
|
||||
/// </summary>
|
||||
/// <param name="name">The metric name</param>
|
||||
/// <param name="value">The value for this gauge</param>
|
||||
public void LogGauge(string name, int value)
|
||||
{
|
||||
SendMetric(MetricType.GAUGE, name, _prefix, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log to a set
|
||||
/// </summary>
|
||||
/// <param name="name">The metric name.</param>
|
||||
/// <param name="value">The value to log.</param>
|
||||
/// <remarks>Logging to a set is about counting the number
|
||||
/// of occurrences of each event.</remarks>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepare a metric prior to sending it off ot the Graphite server.
|
||||
/// </summary>
|
||||
/// <param name="metricType"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="prefix"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>The formatted metric</returns>
|
||||
protected virtual string PrepareMetric(string metricType, string name, string prefix, int value)
|
||||
{
|
||||
return (prefix != null ? (prefix + "." + name) : name) + ":" + value + "|" + metricType;
|
||||
|
||||
@@ -5,6 +5,9 @@ using System.Text;
|
||||
|
||||
namespace StatsdClient
|
||||
{
|
||||
/// <summary>
|
||||
/// A set of extensions for use with the StatsdClient library.
|
||||
/// </summary>
|
||||
public static class StatsdClientExtensions
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -6,6 +6,10 @@ using System.Text;
|
||||
|
||||
namespace StatsdClient
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that is used to measure a latency wrapped in a using block.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{_name} - IsActive = {_stopwatch.IsRunning}")]
|
||||
public sealed class TimingToken : IDisposable
|
||||
{
|
||||
private IStatsd _client;
|
||||
@@ -19,6 +23,9 @@ namespace StatsdClient
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the internal timer and logs a latency metric.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
|
||||
Reference in New Issue
Block a user