feed graphite/carbon like in the example
@@ -18,22 +18,26 @@ class Command(BaseCommand):
parser.add_argument('--graphite', type=str, help=_('graphite address'), default=None)
parser.add_argument('--graphite-port', type=int, default=2003, help=_('graphite port (default 2003)'))
- def _output_graphite(self, s, prefix, result, timestamp):
+ def _output_graphite(self, lines, prefix, result, timestamp):
for name, value in result.items():
if isinstance(value, dict):
- self._output_graphite(s, prefix+name+'.', value, timestamp)
+ self._output_graphite(lines, prefix+name+'.', value, timestamp)
continue
- s.sendall(('%s%s %s %s\n' % (prefix, name, value, timestamp)).encode())
+ lines.append('%s%s %s %s\n' % (prefix, name, value, timestamp))
def handle(self, *args, **options):
data = json.load(options['statsfile'])
end_time = int(dateutil.parser.parse(data['end_date']).timestamp())
result = convert_stats(data)
if options['graphite']:
+ lines = []
+ self._output_graphite(lines, 'c3nav.%s.' % settings.INSTANCE_NAME, result, end_time)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((options['graphite'], options['graphite_port']))
- self._output_graphite(s, 'c3nav.%s.' % settings.INSTANCE_NAME, result, end_time)
+ message = '\n'.join(lines) + '\n' # all lines must end in a newline
+ print(message)
+ sock.sendall(message)
finally:
s.close()
else:
