From 7c30cf3caf5b35e6bac357652a36d81c67cc799f Mon Sep 17 00:00:00 2001 From: cn Date: Tue, 19 Nov 2013 14:06:55 +0100 Subject: [PATCH] Fiat lux --- README.md | 17 ++++++++++++++++ bitcoin_ | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 README.md create mode 100755 bitcoin_ diff --git a/README.md b/README.md new file mode 100644 index 0000000..becd45e --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +munin-bitcoin +============= + +Creates Munin graphs from the data at [bitcoinaverage.com tickers](https://bitcoinaverage.com/) which are extracted +via their [JSON API](https://api.bitcoinaverage.com/ticker/) providing the last price data. + +Install +------- + +Clone this repository or download the bitcoin_ file and create a +symlink as *root* in /etc/munin/plugins by using e.g.: + + cd /etc/munin/plugins; ln -s /path/to/bitcoin_ bitcoin_ + +where is a currency known to https://api.bitcoinaverage.com/ticker/ like "EUR" or "USD". + +**Don't forget to restart your munin-node deamon.** diff --git a/bitcoin_ b/bitcoin_ new file mode 100755 index 0000000..735a231 --- /dev/null +++ b/bitcoin_ @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby + +# Source: https://github.com/cmur2/munin-bitcoin + +# +# Example usage: +# Do +# ln -s /path/to/bitcoin_ bitcoin_ +# where is a currency known to https://api.bitcoinaverage.com/ticker/ +# like EUR or USD. +# +# Example config: +# [bitcoin_*] +# + +require 'rubygems' +require 'json' + +require 'open-uri' + +script = File.basename($0) +@currency = script.gsub('bitcoin_', '') +@cmd = ARGV[0] + +# open stderr +$stderr = IO.new(2, "w") + +def uri(currency) + "http://api.bitcoinaverage.com/ticker/#{currency}" # HTTPS supported +end + +def echo_price(currency, data) + case @cmd + when 'config' + puts "graph_title Bitcoin (in #{currency})" + puts "graph_args --lower-limit 0" + puts "graph_vlabel #{currency}" + puts "graph_category finance" + puts "graph_scale no" + puts "graph_info This graph shows the last price of Bitcoin from http://bitcoinaverage.com/" + %w{last ask bid total_vol 24h_avg}.each do |x| + puts "#{x}.label #{x.gsub('_', ' ').split(' ').map { |y| y.capitalize }.join(' ')}" + puts "#{x}.type GAUGE" + end + else + %w{last ask bid total_vol 24h_avg}.each do |x| + puts "#{x}.value #{data[x]}" + end + end +end + +begin + raw_data = open(uri(@currency)).read + data = JSON.parse(raw_data) + #puts data.inspect + echo_price(@currency, data) +rescue => ex + $stderr.puts "Cannot connect to bitcoinaverage.com: #{ex.to_s}" +end