Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional cast of all metrics to lower case #103

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Publishing/Metrics.NET.nuspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Metrics.NET</id>
<version>0.3.3-pre</version>
<version>0.3.3</version>
<id>Metrics.NET_ntent</id>
<title>Metrics.NET</title>
<authors>iulian.margarintescu</authors>
<owners>Iulian Margarintescu</owners>
Expand Down
6 changes: 3 additions & 3 deletions Publishing/Nancy.Metrics.nuspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Nancy.Metrics</id>
<version>0.3.3-pre</version>
<version>0.3.3</version>
<id>Nancy.Metrics_ntent</id>
<title>Nancy.Metrics</title>
<authors>iulian.margarintescu</authors>
<owners>Iulian Margarintescu</owners>
Expand All @@ -15,7 +15,7 @@
<iconUrl>http://www.erata.net/Metrics.NET/metrics_32.png</iconUrl>
<tags>nancy, nancyfx, metrics, measurements, charts, timer, histogram, duration, graphite, health checks</tags>
<dependencies>
<dependency id="Metrics.NET" version="0.3.2-pre" />
<dependency id="Metrics.NET" version="0.3.3" />
<dependency id="Nancy" version="1.2.0" />
</dependencies>
</metadata>
Expand Down
6 changes: 3 additions & 3 deletions Publishing/Owin.Metrics.nuspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Owin.Metrics</id>
<version>0.3.3-pre</version>
<version>0.3.3</version>
<id>Owin.Metrics_ntent</id>
<title>Owin.Metrics</title>
<authors>Allan Hardy</authors>
<owners>Iulian Margarintescu</owners>
Expand All @@ -15,7 +15,7 @@
<iconUrl>http://www.erata.net/Metrics.NET/metrics_32.png</iconUrl>
<tags>webapi, owin, metrics, measurements, charts, timer, histogram, duration, graphite, health checks</tags>
<dependencies>
<dependency id="Metrics.NET" version="0.3.2-pre" />
<dependency id="Metrics.NET" version="0.3.3" />
</dependencies>
</metadata>
<files>
Expand Down
20 changes: 10 additions & 10 deletions Src/Metrics/Graphite/GraphiteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ namespace Metrics
{
public static class GraphiteExtensions
{
public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval)
public static MetricsReports WithGraphite(this MetricsReports reports, Uri graphiteUri, TimeSpan interval, bool keysToLowercase = false)
{
if (graphiteUri.Scheme.ToLowerInvariant() == "net.tcp")
{
return reports.WithTCPGraphite(graphiteUri.Host, graphiteUri.Port, interval);
return reports.WithTCPGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase);
}

if (graphiteUri.Scheme.ToLowerInvariant() == "net.udp")
{
return reports.WithUDPGraphite(graphiteUri.Host, graphiteUri.Port, interval);
return reports.WithUDPGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase);
}

if (graphiteUri.Scheme.ToLowerInvariant() == "net.pickled")
{
return reports.WithPickledGraphite(graphiteUri.Host, graphiteUri.Port, interval);
return reports.WithPickledGraphite(graphiteUri.Host, graphiteUri.Port, interval, keysToLowercase: keysToLowercase);
}

throw new ArgumentException("Graphite uri scheme must be either net.tcp or net.udp or net.pickled (ex: net.udp://graphite.myhost.com:2003 )", nameof(graphiteUri));
}

public static MetricsReports WithPickledGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, int batchSize = PickleGraphiteSender.DefaultPickleJarSize)
public static MetricsReports WithPickledGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, int batchSize = PickleGraphiteSender.DefaultPickleJarSize, bool keysToLowercase = false)
{
return reports.WithGraphite(new PickleGraphiteSender(host, port, batchSize), interval);
return reports.WithGraphite(new PickleGraphiteSender(host, port, batchSize, keysToLowercase), interval);
}

public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval)
public static MetricsReports WithTCPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = false)
{
return reports.WithGraphite(new TcpGraphiteSender(host, port), interval);
return reports.WithGraphite(new TcpGraphiteSender(host, port, keysToLowercase), interval);
}

public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval)
public static MetricsReports WithUDPGraphite(this MetricsReports reports, string host, int port, TimeSpan interval, bool keysToLowercase = false)
{
return reports.WithGraphite(new UdpGraphiteSender(host, port), interval);
return reports.WithGraphite(new UdpGraphiteSender(host, port, keysToLowercase), interval);
}

public static MetricsReports WithGraphite(this MetricsReports reports, GraphiteSender graphiteLink, TimeSpan interval)
Expand Down
6 changes: 5 additions & 1 deletion Src/Metrics/Graphite/PickleGraphiteSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ public sealed class PickleGraphiteSender : GraphiteSender
private readonly int port;

private readonly int pickleJarSize;
private readonly bool _keysToLowercase;

private TcpClient client;
private PickleJar jar = new PickleJar();


public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize)
public PickleGraphiteSender(string host, int port, int batchSize = DefaultPickleJarSize, bool keysToLowercase = false)
{
this.host = host;
this.port = port;
this.pickleJarSize = batchSize;
_keysToLowercase = keysToLowercase;
}

public override void Send(string name, string value, string timestamp)
{
if (_keysToLowercase)
name = name.ToLower();
this.jar.Append(name, value, timestamp);

if (jar.Size >= this.pickleJarSize)
Expand Down
7 changes: 6 additions & 1 deletion Src/Metrics/Graphite/TcpGraphiteSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public sealed class TcpGraphiteSender : GraphiteSender

private readonly string host;
private readonly int port;
private readonly bool _keysToLowercase;

private TcpClient client;

public TcpGraphiteSender(string host, int port)
public TcpGraphiteSender(string host, int port, bool keysToLowercase)
{
this.host = host;
this.port = port;
_keysToLowercase = keysToLowercase;
}

protected override void SendData(string data)
Expand All @@ -31,6 +33,9 @@ protected override void SendData(string data)
this.client = InitClient(this.host, this.port);
}

if (_keysToLowercase)
data = data.ToLower();

var bytes = Encoding.UTF8.GetBytes(data);

this.client.GetStream().Write(bytes, 0, bytes.Length);
Expand Down
7 changes: 6 additions & 1 deletion Src/Metrics/Graphite/UdpGraphiteSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public sealed class UdpGraphiteSender : GraphiteSender

private readonly string host;
private readonly int port;
private readonly bool _keysToLowercase;

private UdpClient client;

public UdpGraphiteSender(string host, int port)
public UdpGraphiteSender(string host, int port, bool keysToLowercase)
{
this.host = host;
this.port = port;
_keysToLowercase = keysToLowercase;
}

protected override void SendData(string data)
Expand All @@ -31,6 +33,9 @@ protected override void SendData(string data)
this.client = InitClient(this.host, this.port);
}

if (_keysToLowercase)
data = data.ToLower();

var bytes = Encoding.UTF8.GetBytes(data);
this.client.Send(bytes, bytes.Length);
}
Expand Down