Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Librato Metrics via https://github.com/tellybug/librato #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Additional usage details can be found with the -h option:
--aws-key=AWS_KEY Amazon credential key
--aws-secret-key=AWS_SECRET_KEY
Amazon credential secret key
[email protected]:APIKEYHEREDEADBEEF
Email address and API Key of Librato Metrics users account.
--nsca-host=NSCA_HOST
Hostname and port for NSCA daemon, e.g.
nsca.example.com:5667
Expand All @@ -124,7 +126,7 @@ Additional usage details can be found with the -h option:
-o OUTPUT, --output=OUTPUT
Where to send metrics (can specify multiple times).
Choices are 'graphite', 'ganglia', 'cloudwatch',
'nsca' , 'statsd', or 'stdout'.
'librato', 'nsca' , 'statsd', or 'stdout'.
--stdout-separator=STDOUT_SEPARATOR
Seperator between prefix/suffix and name for stdout.
Default is "_".
Expand Down
36 changes: 34 additions & 2 deletions bin/logster
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ cmdline.add_option('--nsca-host', action='store',
cmdline.add_option('--nsca-service-hostname', action='store',
help='<host_name> value to use in nsca passive service check. Default is \"%default\"',
default=socket.gethostname())
cmdline.add_option('--librato-user', action='store',
help='Email address and API Key of Librato Metrics users account, e.g. [email protected]:APIKEYHEREDEADBEEF')
cmdline.add_option('--state-dir', '-s', action='store', default=state_dir,
help='Where to store the logtail state file. Default location %s' % state_dir)
cmdline.add_option('--log-dir', '-l', action='store', default=log_dir,
help='Where to store the logster logfile. Default location %s' % log_dir)
cmdline.add_option('--output', '-o', action='append',
choices=('graphite', 'ganglia', 'stdout', 'cloudwatch', 'nsca', 'statsd'),
help="Where to send metrics (can specify multiple times). Choices are 'graphite', 'ganglia', 'cloudwatch', 'nsca' , 'statsd', or 'stdout'.")
choices=('graphite', 'ganglia', 'stdout', 'cloudwatch', 'librato', 'nsca', 'statsd'),
help="Where to send metrics (can specify multiple times). Choices are 'graphite', 'ganglia', 'cloudwatch', 'librato', 'nsca' , 'statsd', or 'stdout'.")
cmdline.add_option('--stdout-separator', action='store', default="_", dest="stdout_separator",
help='Seperator between prefix/suffix and name for stdout. Default is \"%default\".')
cmdline.add_option('--dry-run', '-d', action='store_true', default=False,
Expand All @@ -127,6 +129,9 @@ if 'graphite' in options.output and not options.graphite_host:
if 'cloudwatch' in options.output and not options.aws_key and not options.aws_secret_key:
cmdline.print_help()
cmdline.error("You must supply --aws-key and --aws-secret-key or Set environment variables. AWS_ACCESS_KEY_ID for --aws-key, AWS_SECRET_ACCESS_KEY_ID for --aws-secret-key")
if 'librato' in options.output and not options.librato_user:
cmdline.print_help()
cmdline.error("You must supply --librato-user when using 'librato' as an output type.")
if 'nsca' in options.output and not options.nsca_host:
cmdline.print_help()
cmdline.error("You must supply --nsca-host when using 'nsca' as an output type.")
Expand Down Expand Up @@ -173,6 +178,8 @@ def submit_stats(parser, duration, options):
submit_ganglia(metrics, options)
if 'graphite' in options.output:
submit_graphite(metrics, options)
if 'librato' in options.output:
submit_librato(metrics, options)
if 'stdout' in options.output:
submit_stdout(metrics, options)
if 'cloudwatch' in options.output:
Expand Down Expand Up @@ -308,6 +315,31 @@ def submit_statsd(metrics, addr):
print "%s %s" % (options.statsd_host, metric_string)


def submit_librato(metrics, options):
if (re.match("^\w+@[\w\.]+:\w+$", options.librato_user) == None):
raise Exception, "Invalid email:apikey found for Librato user credentials: '%s'" % options.librato_user

from librato.connection import LibratoConnection
auth = options.librato_user.split(':')
connection = LibratoConnection(auth[0], auth[1])

for metric in metrics:
if (options.metric_prefix != ""):
metric.name = options.metric_prefix + "." + metric.name

logger.debug("Submitting Librato metric: %s %s" % (metric.name, metric.value))

if (not options.dry_run):
if (metric.name[-6:] == ".count"):
counter = connection.get_or_create_counter(metric.name)
counter.add(metric.value)
else:
gauge = connection.get_or_create_gauge(metric.name)
gauge.add(metric.value)
else:
print "Librato(%s): %s %s" % (auth[0], metric.name, metric.value)


def start_locking(lockfile_name):
""" Acquire a lock via a provided lockfile filename. """
if os.path.exists(lockfile_name):
Expand Down