Add mining dutch and start of nicehash
This commit is contained in:
parent
bc0a1db6a4
commit
00570812a2
7 changed files with 120 additions and 10 deletions
|
@ -34,6 +34,7 @@ var rootCmd = &cobra.Command{
|
|||
logrus.Panic(err)
|
||||
}
|
||||
pools.CoinMineAPIKey = config.CoinMineAPIKey
|
||||
pools.MiningDutchAPIKey = config.MiningDutchAPIKey
|
||||
daemon.Start()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/lbryio/sentinel/nicehash"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
|
||||
"github.com/lbryio/sentinel/pools"
|
||||
|
@ -15,7 +17,8 @@ var stopper = stop.New(nil)
|
|||
// Start starts the daemon that runs collecting information and watching the blockchain
|
||||
func Start() {
|
||||
//Start daemon jobs
|
||||
go pools.MonitorPools(stopper)
|
||||
go pools.Monitor(stopper)
|
||||
go nicehash.Monitor(stopper)
|
||||
|
||||
//Wait for shutdown signal, then shutdown api server. This will wait for all connections to finish.
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
|
|
1
env/env.go
vendored
1
env/env.go
vendored
|
@ -9,6 +9,7 @@ import (
|
|||
// Config holds the environment configuration used by lighthouse.
|
||||
type Config struct {
|
||||
CoinMineAPIKey string `env:"COINMINE_API_KEY"`
|
||||
MiningDutchAPIKey string `env:"MININGDUTCH_API_KEY"`
|
||||
LbrycrdURL string `env:"LBRYCRD_CONNECT" envDefault:""`
|
||||
SlackHookURL string `env:"SLACKHOOKURL"`
|
||||
SlackChannel string `env:"SLACKCHANNEL"`
|
||||
|
|
35
nicehash/nicehash.go
Normal file
35
nicehash/nicehash.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package nicehash
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// CheckPeriod time between checking on nicehash
|
||||
var CheckPeriod = 60
|
||||
var checkPeriod = time.Duration(CheckPeriod) * time.Second
|
||||
|
||||
// Monitor kicks off the monitoring of nice hash apis
|
||||
func Monitor(parent *stop.Group) {
|
||||
stopper := stop.New(parent)
|
||||
ticker := time.NewTicker(checkPeriod)
|
||||
for {
|
||||
select {
|
||||
case <-stopper.Ch():
|
||||
return
|
||||
case <-ticker.C:
|
||||
err := checkNiceHash()
|
||||
if err != nil {
|
||||
logrus.Error(errors.FullTrace(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkNiceHash() error {
|
||||
return nil
|
||||
}
|
|
@ -18,6 +18,7 @@ const url = "https://www2.coinmine.pl/lbc/index.php?page=api&action=getpoolstatu
|
|||
|
||||
// CoinMineAPIKey is the api key to use to access coinmine metrics
|
||||
var CoinMineAPIKey string
|
||||
var lastCoinMineResult *CoinMineResult
|
||||
|
||||
func monitorCoinmine(parent *stop.Group) {
|
||||
stopper := stop.New(parent)
|
||||
|
@ -29,7 +30,7 @@ func monitorCoinmine(parent *stop.Group) {
|
|||
case <-ticker.C:
|
||||
err := checkCoinMine()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Error(errors.FullTrace(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +56,7 @@ func checkCoinMine() error {
|
|||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
lastCoinMineResult = result
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
69
pools/miningdutch.go
Normal file
69
pools/miningdutch.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package pools
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// MiningDutchAPIKey api key for polling the mining dutch mining pool
|
||||
var MiningDutchAPIKey string
|
||||
var lastMiningDutchResult *MiningDutchResponse
|
||||
|
||||
var mdurl = "https://www.mining-dutch.nl/pools/lbrycredits.php?page=api&id=66009&action=getpoolhashrate&api_key="
|
||||
|
||||
func monitorMiningDutch(parent *stop.Group) {
|
||||
stopper := stop.New(parent)
|
||||
ticker := time.NewTicker(checkPeriod)
|
||||
for {
|
||||
select {
|
||||
case <-stopper.Ch():
|
||||
return
|
||||
case <-ticker.C:
|
||||
err := checkMiningDutch()
|
||||
if err != nil {
|
||||
logrus.Error(errors.FullTrace(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkMiningDutch() error {
|
||||
logrus.Debug("Checking Mining Dutch")
|
||||
apiURL := fmt.Sprintf("%s%s", mdurl, MiningDutchAPIKey)
|
||||
req, err := http.NewRequest(http.MethodGet, apiURL, bytes.NewReader(nil))
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
result := &MiningDutchResponse{}
|
||||
err = json.Unmarshal(body, result)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
lastMiningDutchResult = result
|
||||
return nil
|
||||
}
|
||||
|
||||
// MiningDutchResponse holds the data returned from the Mining Dutch API
|
||||
type MiningDutchResponse struct {
|
||||
Getpoolhashrate struct {
|
||||
Version string `json:"version"`
|
||||
Runtime float64 `json:"runtime"`
|
||||
Data float64 `json:"data"`
|
||||
} `json:"getpoolhashrate"`
|
||||
}
|
|
@ -10,10 +10,9 @@ import (
|
|||
var CheckPeriod = 60
|
||||
var checkPeriod = time.Duration(CheckPeriod) * time.Second
|
||||
|
||||
var stopper *stop.Group
|
||||
|
||||
// MonitorPools kicks off the monitors for the different pools for mining LBRY
|
||||
func MonitorPools(parent *stop.Group) {
|
||||
// Monitor kicks off the monitors for the different pools for mining LBRY
|
||||
func Monitor(parent *stop.Group) {
|
||||
stopper := stop.New(parent)
|
||||
go monitorCoinmine(stopper)
|
||||
go monitorMiningDutch(stopper)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue