OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ |
| 2 | LuCI - Lua Configuration Interface |
| 3 | |
| 4 | Copyright 2013 Xiangfu |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | $Id$ |
| 13 | ]]-- |
| 14 | |
| 15 | module("luci.controller.cgminer", package.seeall) |
| 16 | |
| 17 | function index() |
| 18 | entry({"admin", "status", "cgminer"}, cbi("cgminer/cgminer"), _("Cgminer Configuration")) |
| 19 | entry({"admin", "status", "cgminerstatus"}, cbi("cgminer/cgminerstatus"), _("Cgminer Status")) |
| 20 | entry({"admin", "status", "cgminerapi"}, call("action_cgminerapi"), _("Cgminer API Log")) |
| 21 | end |
| 22 | |
| 23 | function action_cgminerapi() |
| 24 | local pp = io.popen("/usr/bin/cgminer-api summary; /usr/bin/cgminer-api devs; /usr/bin/cgminer-api pools; /usr/bin/cgminer-api stats") |
| 25 | local data = pp:read("*a") |
| 26 | pp:close() |
| 27 | |
| 28 | luci.template.render("cgminerapi", {api=data}) |
| 29 | end |
| 30 | |
| 31 | function summary() |
| 32 | local data = {} |
| 33 | local summary = luci.util.execi("/usr/bin/cgminer-api -o summary | sed \"s/|/\\n/g\" ") |
| 34 | |
| 35 | if not summary then |
| 36 | return |
| 37 | end |
| 38 | |
| 39 | for line in summary do |
| 40 | local elapsed, mhsav, foundblocks, getworks, accepted, rejected, hw, utility, discarded, stale, getfailures, localwork, remotefailures, networkblocks, totalmh, wu, diffaccepted, diffrejected, diffstale, bestshare = line:match("Elapsed=(%d+),MHS av=([%d%.]+),Found Blocks=(%d+),Getworks=(%d+),Accepted=(%d+),Rejected=(%d+),Hardware Errors=(%d+),Utility=([%d%.]+),Discarded=(%d+),Stale=(%d+),Get Failures=(%d+),Local Work=(%d+),Remote Failures=(%d+),Network Blocks=(%d+),Total MH=([%d%.]+),Work Utility=([%d%.]+),Difficulty Accepted=([%d]+)%.%d+,Difficulty Rejected=([%d]+)%.%d+,Difficulty Stale=([%d]+)%.%d+,Best Share=(%d+)") |
| 41 | if elapsed then |
| 42 | local str |
| 43 | local days |
| 44 | local h |
| 45 | local m |
| 46 | local s = elapsed % 60; |
| 47 | elapsed = elapsed - s |
| 48 | elapsed = elapsed / 60 |
| 49 | if elapsed == 0 then |
| 50 | str = string.format("%ds", s) |
| 51 | else |
| 52 | m = elapsed % 60; |
| 53 | elapsed = elapsed - m |
| 54 | elapsed = elapsed / 60 |
| 55 | if elapsed == 0 then |
| 56 | str = string.format("%dm %ds", m, s); |
| 57 | else |
| 58 | h = elapsed % 24; |
| 59 | elapsed = elapsed - h |
| 60 | elapsed = elapsed / 24 |
| 61 | if elapsed == 0 then |
| 62 | str = string.format("%dh %dm %ds", h, m, s) |
| 63 | else |
| 64 | str = string.format("%dd %dh %dm %ds", elapsed, h, m, s); |
| 65 | end |
| 66 | end |
| 67 | end |
| 68 | |
| 69 | data[#data+1] = { |
| 70 | ['elapsed'] = str, |
| 71 | ['mhsav'] = mhsav, |
| 72 | ['foundblocks'] = foundblocks, |
| 73 | ['getworks'] = getworks, |
| 74 | ['accepted'] = accepted, |
| 75 | ['rejected'] = rejected, |
| 76 | ['hw'] = hw, |
| 77 | ['utility'] = utility, |
| 78 | ['discarded'] = discarded, |
| 79 | ['stale'] = stale, |
| 80 | ['getfailures'] = getfailures, |
| 81 | ['localwork'] = localwork, |
| 82 | ['remotefailures'] = remotefailures, |
| 83 | ['networkblocks'] = networkblocks, |
| 84 | ['totalmh'] = string.format("%e",totalmh), |
| 85 | ['wu'] = wu, |
| 86 | ['diffaccepted'] = diffaccepted, |
| 87 | ['diffrejected'] = diffrejected, |
| 88 | ['diffstale'] = diffstale, |
| 89 | ['bestshare'] = bestshare |
| 90 | } |
| 91 | end |
| 92 | end |
| 93 | |
| 94 | return data |
| 95 | end |
| 96 | |
| 97 | function pools() |
| 98 | local data = {} |
| 99 | local pools = luci.util.execi("/usr/bin/cgminer-api -o pools | sed \"s/|/\\n/g\" ") |
| 100 | |
| 101 | if not pools then |
| 102 | return |
| 103 | end |
| 104 | |
| 105 | for line in pools do |
| 106 | local pi, url, st, pri, lp, gw, a, r, dc, sta, gf, rf, user, lst, ds, da, dr, dsta, lsd, hs, sa, su, hg = line:match( |
| 107 | "POOL=(%d+),URL=(.*),Status=(%a+),Priority=(%d+),Long Poll=(%a+),Getworks=(%d+),Accepted=(%d+),Rejected=(%d+),Discarded=(%d+),Stale=(%d+),Get Failures=(%d+),Remote Failures=(%d+),User=(.*),Last Share Time=(%d+),Diff1 Shares=(%d+),Proxy Type=.*,Proxy=.*,Difficulty Accepted=(%d+)[%.%d]+,Difficulty Rejected=(%d+)[%.%d]+,Difficulty Stale=(%d+)[%.%d]+,Last Share Difficulty=(%d+)[%.%d]+,Has Stratum=(%a+),Stratum Active=(%a+),Stratum URL=.*,Has GBT=(%a+)") |
| 108 | if pi then |
| 109 | if lst == "0" then |
| 110 | lst_date = "Never" |
| 111 | else |
| 112 | lst_date = os.date("%c", lst) |
| 113 | end |
| 114 | data[#data+1] = { |
| 115 | ['pool'] = pi, |
| 116 | ['url'] = url, |
| 117 | ['status'] = st, |
| 118 | ['priority'] = pri, |
| 119 | ['longpoll'] = lp, |
| 120 | ['getworks'] = gw, |
| 121 | ['accepted'] = a, |
| 122 | ['rejected'] = r, |
| 123 | ['discarded'] = dc, |
| 124 | ['stale'] = sta, |
| 125 | ['getfailures'] = gf, |
| 126 | ['remotefailures'] = rf, |
| 127 | ['user'] = user, |
| 128 | ['lastsharetime'] = lst_date, |
| 129 | ['diff1shares'] = ds, |
| 130 | ['diffaccepted'] = da, |
| 131 | ['diffrejected'] = dr, |
| 132 | ['diffstale'] = dsta, |
| 133 | ['lastsharedifficulty'] = lsd, |
| 134 | ['hasstratum'] = hs, |
| 135 | ['stratumactive'] = sa, |
| 136 | ['stratumurl'] = su, |
| 137 | ['hasgbt'] = hg |
| 138 | } |
| 139 | end |
| 140 | end |
| 141 | |
| 142 | return data |
| 143 | end |
| 144 |
