Can I enter timestamp to send data to graphite via statsd(javascript statsd)? I need to graph old data.
3 Answers
No, you can't do that with statsd, however you can achieve the same by sending your data directly to carbon which accepts tiemstamps.
Statsd just collect real time data and on a configured period sums or average each metric received on that period and send it to graphite carbon daemon with current timestamp.
Sending data to carbon daemon it's very straight forward, you just need to open a socket to carbon common port (has another port if you want to use pickle), and then print on that socket one metric per line with following values: metric_name metric_value metric_timestamp
Carbon will store that value in that timestamp, and you can use any timestamp you want as long as it's in the range configured on the storage of that metric.
There are many examples around, like this one to send with netcat
There's also a Graphite client written in C
-
Full example to send data with old timestamp. Firstly, you need to change your time and then `echo "stats.gauges.asdf.qwer.zxc 0.55 `date +%s`" | nc -q0 100.100.100.100 2003` . Read here: http://graphite.readthedocs.org/en/1.0/feeding-carbon.html – Bob Jul 06 '15 at 08:45
I wanted to use statsd but not in real time, because I process log files once an hour. So I modified the server code to accept a timestamp, and modified the client code to send one. It ended up working for me although it feels very "home grown" and I can't update to newer versions of statsd without extra work. The tricky part is that the server does some aggregation into 10-second buckets. In real time, this is pretty easy to do, but if you are going to accept a timestamp, you have to keep a lot more data around. For me, since my data can only be around an hour old, it wasn't too hard, but my solution doesn't really work for a general case.

- 723
- 3
- 9
-
did you open source this anywhere? I'm really interested in your solution, because I need to do the same – Manuel Rauber Jul 11 '13 at 13:48
-
I haven't open-sourced it. I don't mind sharing it with particular people, it's just not very general. I'm not used to contacting people on stack overflow except in the comments -- is there a way for us to exchange email addresses without just printing them here? – jfrank Jul 16 '13 at 17:05
-
-
Is there any updates on your implementation that you can share, we would like to use the same functionality for a project. – Lukie Feb 24 '14 at 18:12
-
-
@to_all_who_commented.. What's the benefit of going through `statsd` compared to sending data to graphite directly? – eugene Jan 15 '16 at 05:17
Looks like there is a way to send raw data via STATSD but it won't be aggregated:
def send(self, subname, value, timestamp=None):
'''Send the data to statsd via self.connection
:keyword subname: The subname to report the data to (appended to the
client name)
:keyword value: The raw value to send
'''
name = self._get_name(self.name, subname)
return statsd.Client._send(self, {name: '%s|r|%s' % (value, ts)})
see: http://python-statsd.readthedocs.org/en/latest/_modules/statsd/raw.html https://github.com/chuyskywalker/statsd/blob/master/README.md

- 2,530
- 2
- 28
- 27