CgminerApiClient
A gem that allows sending API commands to a pool of cgminer instances.
Requirements
- Ruby (~> 2.0.0, ~> 2.1.0)
- YAML
- JSON
- Socket
- Thread
- cgminer (~> 3.12.0)
GUI
Installation Options
Bundler
Add the following to your Gemfile
:
gem 'cgminer_api_client', '~> 0.2.6'
RubyGems
$ gem install cgminer_api_client
Manually
$ git clone [email protected]:jramos/cgminer_api_client.git
$ cd cgminer_api_client
$ gem build cgminer_api_client.gemspec
$ gem install cgminer_api_client-0.2.6.gem
Configuration
Copy config/miners.yml.example
to config/miners.yml
and update with the IP addresses (and optional ports and timeouts) of your cgminer instances. E.g.:
# connect to localhost on the default port (4028) with the default timeout (5 seconds)
- host: 127.0.0.1
# connect to 192.168.1.1 on a non-standard port (1234) with a custom timeout (1 second)
- host: 192.168.1.1
port: 1234
timeout: 1
Remote API Access
Your cgminer instances must be configured to allow remote API access if connecting from anywhere but localhost (127.0.0.1). See the cgminer API-README for more information.
Linux Instructions
Under Linux, you would do the following to allow access from any computer on your local network (192.168.1.x):
$ vi /etc/config/cgminer
Make the following change:
# option api_allow 'W:127.0.0.1'
option api_allow 'W:127.0.0.1,W:192.168.1.0/24'
You also need to updated the init.d script to pass the --api_allow
option:
$ vi /etc/init.d/cgminer
Make the following change:
#PARAMS="$AOPTIONS $POOL1 $POOL2 $POOL3 $_pb --api-listen --api-network"
PARAMS="$AOPTIONS $POOL1 $POOL2 $POOL3 $_pb --api-listen --api-network --api-allow $_aa"
Restart cgminer:
$ /etc/init.d/cgminer restart
Gem Usage
require 'cgminer_api_client'
# change the default timeout and port for the miners
CgminerApiClient.config do |config|
config.default_port = 4023
config.default_timeout = 3
end
pool = CgminerApiClient::MinerPool.new
# run 'devs' on each miner in the pool; returns an array of response hashes
devices = pool.devs
# run 'summary' on each miner in the pool; returns an array of response hashes
summaries = pool.summary
# run 'devs' on available miners; returns an array of response hashes
pool.available_miners.collect do |miner|
miner.devs
end
# restart the pool
pool.restart
CLI Usage
API commands can be sent to your miner pool from the command line.
$ cgminer_api_client <command> (<arguments>)
Commands & Arguments
Read-Only
The following read-only miner and pool commands are currently available:
- asc(number)
- asccount
- check(command)
- coin
- config
- devdetails
- devs
- pga(number)
- pgacount
- pools
- privileged
- notify
- stats
- summary
- usbstats
- version
Privileged
The following privileged miner and pool commands are currently available:
Asc
- ascdisable(number)
- ascenable(number)
- ascidentify(number)
- ascset(number, option, value = nil)
Pga
- pgadisable(number)
- pgaenable(number)
- pgaidentify(number)
- pgaset(number, option, value = nil)
Pool
- addpool(url, user, pass)
- disablepool(number)
- enablepool(number)
- poolpriority(*id_order)
- poolquota(number, value)
- removepool(number)
- switchpool(number)
System
- debug(setting = 'D')
- failover_only(value)
- hotplug(seconds)
- quit
- restart
- save(filename = nil)
- setconfig(name, value)
- zero(which = 'All', full_summary = false)
Any cgminer API commands not explictly defined above are implemented using method_missing
. A complete list of available API commands and options can be found in the cgminer API-README.
Contributing
- Fork it ( https://github.com/jramos/cgminer_api_client/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Donating
If you find this gem useful, please consider donating.
BTC: 18HFFqZv2KJMHPNwPes839PJd5GZc4cT3U
License
Code released under the MIT license.