Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_bitcoin.lua
blob879523a3d4ada2546e65739ab8298e17bc50cea5
1 -- Authors: Voker57 <voker57@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- Bitcoin (฿) daemon monitor
7 -- %bitcoin_speed - current speed in khash/s
8 -- %bitcoin_balance - current balance
10 -- by Voker57 <voker57@gmail.com>
11 -- Public domain
13 local defaults={
14 update_interval=30 * 1000
17 local settings=table.join(statusd.get_config("bitcoin"), defaults)
19 local bitcoin_timer
21 local function get_bitcoin_speed()
22 local hps = io.popen("bitcoind gethashespersec 2>/dev/null")
23 if not hps then
24 return "N/A"
25 end
26 local answ = hps:read("*a")
27 if not answ or answ == "" then
28 return "N/A"
29 end
30 return string.format("%0.2f", answ / 1000)
31 end
33 local function get_bitcoin_balance()
34 local bl = io.popen("bitcoind getbalance 2>/dev/null")
35 if not bl then
36 return "N/A"
37 end
38 local answ = bl:read("*a")
39 if not answ or answ == "" then
40 return "N/A"
41 end
42 return string.format("%0.2f", answ)
43 end
45 local function update_bitcoin()
46 local bitcoin_speed = get_bitcoin_speed()
47 local bitcoin_balance = get_bitcoin_balance()
48 statusd.inform("bitcoin_balance", bitcoin_balance)
49 statusd.inform("bitcoin_speed", bitcoin_speed)
50 bitcoin_timer:set(settings.update_interval, update_bitcoin)
51 end
53 -- Init
54 bitcoin_timer=statusd.create_timer()
55 update_bitcoin()