1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Interface for sending data to Graphite."""
7 from __future__ import print_function
11 from chromite.lib import cros_build_lib
13 CARBON_SERVER = 'chromeos-stats.corp.google.com'
16 def SendToCarbon(lines, dryrun=False, process_queue=20):
17 """Send data to the statsd/graphite server.
19 Example of a line "autotest.scheduler.running_agents_5m 300"
20 5m is the frequency we are sampling (It is not required but it adds clarity
24 lines: A list of lines of the format "category value"
25 dryrun: Print out what you would send but do not send anything.
27 process_queue: How many lines to send to the statsd server at a
30 sock = socket.socket()
33 sock.connect((CARBON_SERVER, CARBON_PORT))
35 cros_build_lib.Error('Failed to connect to Carbon.')
38 slices = [lines[i:i+process_queue]
39 for i in range(0, len(lines), process_queue)]
41 data = '\n'.join(lines) + '\n'
43 cros_build_lib.Info('Not sending to Graphite via Carbon:\n%s', data)
45 cros_build_lib.Debug('Sending to Graphite via Carbon:\n%s', data)