send data from java client

Asked by Peter Kenens

Hi,

We want to collect measurements from our java application via graphite. However, we are not successful in showing the graphs that represent our data. When we connect via the webinterface, we do see our components appear in the left tree, but the graphs are empty. This is maybe because we are unsure on how to send in the data from a java client.

In java, System.currentTimeMillis() (see http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#currentTimeMillis()) returns the time in milliseconds since jan 1, 1970. Therefor, we divide this time by 1000 to get the seconds since jan 1, 1970 as explained in a previous question.

The routine we use looks like

Socket s = new Socket(graphiteServer, 2003);
PrintStream ps = new PrintStream(s.getOutputStream());
String m = "servers.MyMachine.foo 10 " + (int) (System.currentTimeMillis() / 1000);
ps.println(m);
s.close();

but we do not see the corresponding graph.

Thanks,
Peter

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
Peter Kenens
Solved:
Last query:
Last reply:
Revision history for this message
chrismd (chrismd) said :
#1

That's odd. Maybe construct your PrintStream with autoFlush=true? Or do ps.flush() after the println? Might be a non-issue, I don't know for sure.

If that doesn't work then what I would do is look at the carbon logs. Look at $GRAPHITE/carbon/log/*.log and see what (if anything) happens when your client sends a data point. Under normal circumstances you should see the agent log saying 'accepted connection from ...', the cache log shouldn't matter as long as it doesn't have exceptions, the persister log should say 'update_many: ../storage/whisper/servers/MyMachine/foo.wsp 1 data points took XYZ seconds' or something like that.

Let me know what you find.

Revision history for this message
Peter Kenens (peter-kenens) said :
#2

Thanks for the quick reply... In the meantime, I managed to visualize the data.

We did not find any exceptions in the logs, but we do see incoming connections. When looking at the raw data
http://<server>/render?target=servers.XXX.YYY&yMin=0&yMax=20&width=600&height=600&until=10:00&rawData=true

we always saw None values.

When we used the python example client, we did see values instead of None.

I found that some of our naming schemes (which are automatically generated based on system configuration) contained spaces and this was probably to main reason why the data did not came through... I removed these now. Are there also other chars that are not allowed in the data that can be send in?

As a result of sending in such invalid entries, we could even add nonsense to the tree in the graphite browser...unreadable entries. I can send you a screenshot if you want.

I think that it would be an improvement to have better exception handling around (invalid) entries that are received.

Another improvement could be to allow quotes around the naming scheme to allow spaces in parts of the naming scheme, e.g.
"servers.My Component" 10 1234567890\n