From 8d34ddd0a30acf59d423bac773ac2d63aafc7044 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Mar 2020 14:58:28 +0000 Subject: Added readme, tidied some things --- Readme.textile | 23 +++++++++++++++++++++++ lib/longboat/collector.rb | 2 +- lib/longboat/jobs.rb | 4 +--- longboat | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 Readme.textile diff --git a/Readme.textile b/Readme.textile new file mode 100644 index 0000000..aa4750d --- /dev/null +++ b/Readme.textile @@ -0,0 +1,23 @@ +h1. Longboat + +Longboat is a metric collection system. Intended for Viking, but theoretically generic. + +h2. Jobs + +Longboat will pick up all jobs in the lib/jobs directory. Each job consists of: + +* a file with a snake_case name, such as @my_job.rb@ +* containing a single class with a CamelCase name matching the file name, such as @MyJob@ +* with two methods: +** @initialize@, which takes a single argument of the collector to @report!@ the metrics to +** @run@, no arguments, which triggers a job run and metric report + +@Longboat::Collector#report!@ takes as arguments: + +# The name of the metric +# The value of the metric +# Optionally, as a final hash: +#* @help@: The help string for the metric +#* @type@: The Prometheus type of the metric +#* @labels@: A hash containing the metric labels +#* @timestamp@: The timestamp when the metric was collected, defaults to the time @report!@ was called. diff --git a/lib/longboat/collector.rb b/lib/longboat/collector.rb index adb20c3..c812b05 100644 --- a/lib/longboat/collector.rb +++ b/lib/longboat/collector.rb @@ -9,7 +9,7 @@ module Longboat @metrics[name][labels] = {value: value, timestamp: timestamp} end - def metrics + def prometheus_metrics res = "" @metrics.each do |name, metric| res << "#HELP #{name} #{metric[:help]}\n" unless metric[:help].nil? diff --git a/lib/longboat/jobs.rb b/lib/longboat/jobs.rb index 155b305..c6bbb17 100644 --- a/lib/longboat/jobs.rb +++ b/lib/longboat/jobs.rb @@ -17,9 +17,7 @@ module Longboat end def collect! - @jobs.each do |job| - job.run - end + @jobs.each(&:run) end def collect_every(time = 60, async = true) diff --git a/longboat b/longboat index fb7500f..b39d399 100755 --- a/longboat +++ b/longboat @@ -11,7 +11,7 @@ jobs.load(collector) t = jobs.collect_every sleep 5 -puts collector.metrics +puts collector.prometheus_metrics t.exit #Longboat::Server.serve! -- cgit v1.2.1