Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix datagram destination to use the host/port provided to DefaultSocketProvider #1

Merged
merged 1 commit into from

4 participants

@robert-chiniquy
  • Use default constructor for DatagramSocket. Previously the host/port were passed to DatagramSocket to be used as the locally-bound address.
  • Set the destination host/port in the DatagramPacket constructor. Previously the DatagramPacket was being constructed with no destination.
  • Add import of java.net.InetAddress, remove import of java.net.InetSocketAddress.

http://docs.oracle.com/javase/6/docs/api/java/net/DatagramSocket.html#DatagramSocket()
http://docs.oracle.com/javase/6/docs/api/java/net/DatagramPacket.html#DatagramPacket(byte[], int, java.net.InetAddress, int)

@robert-chiniquy robert-chiniquy Fix datagram destination to use the host/port provided to DefaultSock…
…etProvider

- Use default constructor for DatagramSocket. Previously the host/port were
  passed to DatagramSocket to be used as the locally-bound address.
- Set the destination host/port in the DatagramPacket constructor. Previously
  the DatagramPacket was being constructed with no destination.
- Add import of java.net.InetAddress, remove import of java.net.InetSocketAddress.

http://docs.oracle.com/javase/6/docs/api/java/net/DatagramSocket.html#DatagramSocket()
http://docs.oracle.com/javase/6/docs/api/java/net/DatagramPacket.html#DatagramPacket(byte[], int, java.net.InetAddress, int)
6afa14e
@romankor

Bro , what about merging that pull request. I used your class , but without that pull request its kinda useless.

@robert-chiniquy

@Pfeffer-Kopf Until he does merge it you can always build from my fork, that's what I do.

@romankor

Hey Robert
Do you have actually a working setup with that statsD reporter. As far as I saw thats a pretty almost copy of the GraphiteReporter from Metrics. It means it sends all the gauges and timers and all the stuff that StatsD supposed to compute. I don't really understand the point in computing all the stuff twice. Am i missing something ? ( sorry for dumb questions , since i got all the setup (graphite+statsd+graphitit) ready only a week ago.

What is being send right now i think that way too much info. Probably count, percentile_90, mean will be enough

@organicveggie

Wow. I'm really sorry. I don't know how I missed the email to merge the pull request.

@organicveggie organicveggie merged commit d67b470 into organicveggie:master
@robert-chiniquy

@Pfeffer-Kopf Yep it works, but you're right, some stuff seems to be aggregated twice, and I don't see the point of that either. I assumed it was just the yammer metrics way, but now that you mention it…

@organicveggie Thanks for the merge!

@fourk

@Pfeffer-Kopf The benefit of using statsd as an intermediary is that it performs some extra aggregations for you, although admittedly most of which are useless with sane flush intervals. For example, let's say you have a Timer. Metrics will send, every flush interval, 13 [1] metrics to Statsd. For each of those 13 metrics, Statsd will compute and flush 9 [2] metrics, every statsd->graphite flush interval (a value that should be bigger than the metrics->statsd flush interval), based only on the data it received within that flush interval.

[1]: The metrics for a Timer are: 15MinuteRate, 1MinuteRate, 5MinuteRate, 75percentile, 95percentile, 98percentile, 999percentile, max, mean, meanRate, median, min, stddev

[2]: Statsd metrics: count, lower, mean, mean_90, std, sum, sum_90, upper, upper_90

Count is generally only useful for showing whether there was a problem transmitting metrics to statsd. If it is a value other than $STATSD_TO_GRAPHITE_FLUSH_INTERVAL / $METRICS_TO_STATSD_FLUSH_INTERVAL this indicates that some data points didn't end up in statsd, which is generally totally fine.

99% of the time, the only statsd metric that has value for me is mean. This probably changes if you have a larger ratio of statsd flushes per graphite flush, but with around 12 metrics->statsd flushes per statsd->graphite flush, there's not really much value provided by anything besides mean.

@romankor

This is how probably a proper statdClient should look like. https://github.com/etsy/statsd/blob/master/examples/StatsdClient.java

I dont see any point in using metrics as big and as it wide it would be. My app is running on Jersey-Guice , i have it all wrapped up with an simple MethodInterceptor around @Timed annotations , that uses that client to send out metrics. The outcome is tiny and clear , probably the only things that really bother me are mean,count,uppper_90

@organicveggie

As a side note, the data that metrics-statsd publishes is a function of codahale/metrics, not metrics-statsd. Since I generally don't care about absolute mean, I wrote different implementations on the metrics side that generated exponential weighted moving averages. You could do the same thing and only include mean, count and upper_90.

@robert-chiniquy

Interesting, thanks for the note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. @robert-chiniquy

    Fix datagram destination to use the host/port provided to DefaultSock…

    robert-chiniquy authored
    …etProvider
    
    - Use default constructor for DatagramSocket. Previously the host/port were
      passed to DatagramSocket to be used as the locally-bound address.
    - Set the destination host/port in the DatagramPacket constructor. Previously
      the DatagramPacket was being constructed with no destination.
    - Add import of java.net.InetAddress, remove import of java.net.InetSocketAddress.
    
    http://docs.oracle.com/javase/6/docs/api/java/net/DatagramSocket.html#DatagramSocket()
    http://docs.oracle.com/javase/6/docs/api/java/net/DatagramPacket.html#DatagramPacket(byte[], int, java.net.InetAddress, int)
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/main/java/com/studyblue/metrics/reporting/StatsdReporter.java
View
16 src/main/java/com/studyblue/metrics/reporting/StatsdReporter.java
@@ -25,7 +25,7 @@
import java.io.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
-import java.net.InetSocketAddress;
+import java.net.InetAddress;
import java.util.Locale;
import java.util.Map;
import java.util.SortedMap;
@@ -304,7 +304,7 @@ protected void sendData(String name, String value, StatType statType) {
statTypeStr = "ms";
break;
}
-
+
try {
if (!prefix.isEmpty()) {
writer.write(prefix);
@@ -333,19 +333,25 @@ public DefaultSocketProvider(String host, int port) {
@Override
public DatagramSocket get() throws Exception {
- return new DatagramSocket(new InetSocketAddress(this.host, this.port));
+ return new DatagramSocket();
}
-
+
@Override
public DatagramPacket newPacket(ByteArrayOutputStream out) {
byte[] dataBuffer;
+
if (out != null) {
dataBuffer = out.toByteArray();
}
else {
dataBuffer = new byte[8192];
}
- return new DatagramPacket(dataBuffer, dataBuffer.length);
+
+ try {
+ return new DatagramPacket(dataBuffer, dataBuffer.length, InetAddress.getByName(this.host), this.port);
+ } catch (Exception e) {
+ return null;
+ }
}
}
}
Something went wrong with that request. Please try again.