Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts #27

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
568fb95
Update environment.js
ahonder Dec 9, 2020
5d53a1e
Update ember-intl.js
ahonder Dec 9, 2020
df984d1
Update application.js
ahonder Dec 9, 2020
37cd117
Update payments.hbs
ahonder Dec 9, 2020
9a4ecee
Update not-found.hbs
ahonder Dec 9, 2020
7eb392a
Update miners.hbs
ahonder Dec 9, 2020
3fda28d
Update luck.hbs
ahonder Dec 9, 2020
4f806ed
Update index.hbs
ahonder Dec 9, 2020
ece4119
Update blocks.hbs
ahonder Dec 9, 2020
703d685
Update application.hbs
ahonder Dec 9, 2020
1a3895d
Update application-error.hbs
ahonder Dec 9, 2020
26627bd
Update account.hbs
ahonder Dec 9, 2020
9a6c403
Update about.hbs
ahonder Dec 9, 2020
2b9e776
Update block.hbs
ahonder Dec 9, 2020
504e46f
Update immature.hbs
ahonder Dec 9, 2020
e8109d9
Update index.hbs
ahonder Dec 9, 2020
6e8c960
Update pending.hbs
ahonder Dec 9, 2020
b2015ef
Update index.hbs
ahonder Dec 9, 2020
c91a8fc
Update payouts.hbs
ahonder Dec 9, 2020
781024c
Update index.html
ahonder Dec 9, 2020
3adc8d2
Update and rename config.example.json to config.json
ahonder Dec 9, 2020
53db814
Create config2.json
ahonder Dec 9, 2020
95b877c
Create config4.json
ahonder Dec 9, 2020
2d2259a
Update config2.json
ahonder Dec 9, 2020
f7c1740
Create api.json
ahonder Dec 9, 2020
2e4a3cf
Create unlocker.json
ahonder Dec 9, 2020
b050e03
Create payout.json
ahonder Dec 9, 2020
392736a
Update api.json
ahonder Jul 29, 2022
d3c082f
Update server.go
ahonder Jul 29, 2022
b8d8ca4
Update redis.go
ahonder Jul 29, 2022
20e40ee
Create index.js
ahonder Jul 29, 2022
3c3ccb2
Update index.js
ahonder Jul 29, 2022
5c086a2
Update index.hbs
ahonder Jul 29, 2022
296dc5d
Update index.hbs
ahonder Jul 29, 2022
8380370
Create exchange.go
ahonder Jul 29, 2022
b90b9fb
Update unlocker.go
ahonder Jul 29, 2022
e3ab039
Update payouts.hbs
ahonder Jul 29, 2022
3f35c9a
Create rewards.hbs
ahonder Jul 29, 2022
14a57db
Update block.hbs
ahonder Jul 29, 2022
b7bbb08
Update immature.hbs
ahonder Jul 29, 2022
0524878
Update index.hbs
ahonder Jul 29, 2022
067af3f
Update pending.hbs
ahonder Jul 29, 2022
7809a1f
Update chart-diff.hbs
ahonder Jul 29, 2022
9cbebc8
Update account.hbs
ahonder Jul 29, 2022
ef10d2a
Update application.hbs
ahonder Jul 29, 2022
14e4667
Update blocks.hbs
ahonder Jul 29, 2022
6ecbe7d
Create finders.hbs
ahonder Jul 29, 2022
552519b
Update help.hbs
ahonder Jul 29, 2022
d8590ef
Update index.hbs
ahonder Jul 29, 2022
712b946
Update luck.hbs
ahonder Jul 29, 2022
585a3ad
Update miners.hbs
ahonder Jul 29, 2022
e2d05f1
Update payments.hbs
ahonder Jul 29, 2022
0695271
Update app.css
ahonder Jul 29, 2022
f0ce115
Update account.js
ahonder Jul 29, 2022
135bafb
Update application.js
ahonder Jul 29, 2022
1bebe83
Create blocks.js
ahonder Jul 29, 2022
7756dc0
Update help.js
ahonder Jul 29, 2022
6af031f
Update block.js
ahonder Jul 29, 2022
60f07ea
Update chart.js
ahonder Jul 29, 2022
bbc9286
Update account.js
ahonder Jul 29, 2022
2558018
Create finders.js
ahonder Jul 29, 2022
54593cd
Update package-lock.json
ahonder Jul 29, 2022
f870391
Update package.json
ahonder Jul 29, 2022
9601952
Delete config.json
ahonder Jul 29, 2022
cb77b5e
Delete config2.json
ahonder Jul 29, 2022
435b338
Delete config4.json
ahonder Jul 29, 2022
aeebf88
Delete payout.json
ahonder Jul 29, 2022
5a47445
Delete unlocker.json
ahonder Jul 29, 2022
ea62092
Create config.json
ahonder Jul 29, 2022
dc8b19c
Create unlocker.json
ahonder Jul 29, 2022
d305b17
Create payout.json
ahonder Jul 29, 2022
57fde37
Update main.go
ahonder Jul 29, 2022
0c32293
Update main.go
ahonder Jul 29, 2022
8bf42c9
Update main.go
ahonder Jul 29, 2022
e93be89
Update miner.go
ahonder Jul 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions config.example.json → api.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"threads": 2,
"threads": 1,
"coin": "etc",
"name": "main",
"network": "classic",

"proxy": {
"enabled": true,
"enabled": false,
"listen": "0.0.0.0:8888",
"limitHeadersSize": 1024,
"limitBodySize": 256,
"behindReverseProxy": false,
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
"difficulty": 2000000000,
"difficulty": 8000000000,
"hashrateExpiration": "3h",

"healthCheck": true,
Expand Down Expand Up @@ -57,7 +57,15 @@
"hashrateLargeWindow": "3h",
"luckWindow": [64, 128, 256],
"payments": 30,
"blocks": 50
"blocks": 50,
"poolCharts":"*/20 * * * *",
"poolChartsNum":74,
"minerCharts":"*/20 * * * *",
"minerChartsNum":74,
"netCharts":"*/20 * * * *",
"netChartsNum":74,
"shareCharts":"*/20 * * * *",
"shareChartsNum":74
},

"upstreamCheckInterval": "5s",
Expand All @@ -84,7 +92,7 @@
"unlocker": {
"enabled": false,
"poolFee": 1.0,
"poolFeeAddress": "",
"poolFeeAddress": "0x841Dc834eC4c8925b37d4eFaDCCeFca25582BD8a",
"depth": 120,
"immatureDepth": 20,
"keepTxFees": false,
Expand All @@ -95,15 +103,15 @@

"payouts": {
"enabled": false,
"requirePeers": 25,
"interval": "120m",
"requirePeers": 5,
"interval": "1430m",
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"address": "0x0",
"address": "0xa0102b3390ad022160d0a37e87191c76483ef669",
"gas": "21000",
"gasPrice": "50000000000",
"autoGas": true,
"threshold": 500000000,
"threshold": 100000000,
"bgsave": false
},

Expand Down
158 changes: 158 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"encoding/json"
"fmt"
"log"
"net/http"
"sort"
Expand All @@ -11,6 +12,7 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/robfig/cron"

"github.com/etclabscore/open-etc-pool/storage"
"github.com/etclabscore/open-etc-pool/util"
Expand All @@ -19,6 +21,14 @@ import (
type ApiConfig struct {
Enabled bool `json:"enabled"`
Listen string `json:"listen"`
PoolCharts string `json:"poolCharts"`
PoolChartsNum int64 `json:"poolChartsNum"`
NetCharts string `json:"netCharts"`
NetChartsNum int64 `json:"netChartsNum"`
MinerChartsNum int64 `json:"minerChartsNum"`
MinerCharts string `json:"minerCharts"`
ShareCharts string `json:"shareCharts"`
ShareChartsNum int64 `json:"shareChartsNum"`
StatsCollectInterval string `json:"statsCollectInterval"`
HashrateWindow string `json:"hashrateWindow"`
HashrateLargeWindow string `json:"hashrateLargeWindow"`
Expand Down Expand Up @@ -96,13 +106,127 @@ func (s *ApiServer) Start() {
}
}()

go func() {
c := cron.New()

poolCharts := s.config.PoolCharts
log.Printf("Pool charts config is :%v", poolCharts)
c.AddFunc(poolCharts, func() {
s.collectPoolCharts()
})

netCharts := s.config.NetCharts
log.Printf("Net charts config is :%v", netCharts)
c.AddFunc(netCharts, func() {
s.collectnetCharts()
})

minerCharts := s.config.MinerCharts
log.Printf("Miner charts config is :%v", minerCharts)
c.AddFunc(minerCharts, func() {

miners, err := s.backend.GetAllMinerAccount()
if err != nil {
log.Println("Get all miners account error: ", err)
}
for _, login := range miners {
miner, _ := s.backend.CollectWorkersStats(s.hashrateWindow, s.hashrateLargeWindow, login)
s.collectMinerCharts(login, miner["currentHashrate"].(int64), miner["hashrate"].(int64), miner["workersOnline"].(int64))
}
})
///test share chart
shareCharts := s.config.ShareCharts
log.Printf("Share charts config is :%v", shareCharts)
c.AddFunc(shareCharts, func() {
miners, err := s.backend.GetAllMinerAccount()
if err != nil {
log.Println("Get all miners account error: ", err)
}
for _, login := range miners {
miner, _ := s.backend.CollectWorkersStats(s.hashrateWindow, s.hashrateLargeWindow, login)
s.collectshareCharts(login, miner["workersOnline"].(int64))
}

})

c.Start()
}()

if !s.config.PurgeOnly {
s.listen()
}
}

func (s *ApiServer) collectPoolCharts() {
ts := util.MakeTimestamp() / 1000
now := time.Now()
year, month, day := now.Date()
hour, min, _ := now.Clock()
t2 := fmt.Sprintf("%d-%02d-%02d %02d_%02d", year, month, day, hour, min)
stats := s.getStats()
hash := fmt.Sprint(stats["hashrate"])
log.Println("Pool Hash is ", ts, t2, hash)
err := s.backend.WritePoolCharts(ts, t2, hash)
if err != nil {
log.Printf("Failed to fetch pool charts from backend: %v", err)
return
}
}

func (s *ApiServer) collectnetCharts() {
ts := util.MakeTimestamp() / 1000
now := time.Now()
year, month, day := now.Date()
hour, min, _ := now.Clock()
t2 := fmt.Sprintf("%d-%02d-%02d %02d_%02d", year, month, day, hour, min)
//stats := s.getStats()
//diff := fmt.Sprint(stats["difficulty"])
nodes, erro := s.backend.GetNodeStates()
if erro != nil {
log.Printf("Failed to fetch Diff charts from backend: %v", erro)
return
}
diff := fmt.Sprint(nodes[0]["difficulty"])
log.Println("Difficulty Hash is ", ts, t2, diff)
err := s.backend.WriteDiffCharts(ts, t2, diff)
if err != nil {
log.Printf("Failed to fetch Diff charts from backend: %v", err)
return
}
}

func (s *ApiServer) collectMinerCharts(login string, hash int64, largeHash int64, workerOnline int64) {
ts := util.MakeTimestamp() / 1000
now := time.Now()
year, month, day := now.Date()
hour, min, _ := now.Clock()
t2 := fmt.Sprintf("%d-%02d-%02d %02d_%02d", year, month, day, hour, min)

log.Println("Miner "+login+" Hash is", ts, t2, hash, largeHash)
err := s.backend.WriteMinerCharts(ts, t2, login, hash, largeHash, workerOnline)
if err != nil {
log.Printf("Failed to fetch miner %v charts from backend: %v", login, err)
}
}

func (s *ApiServer) collectshareCharts(login string, workerOnline int64) {
ts := util.MakeTimestamp() / 1000
now := time.Now()
year, month, day := now.Date()
hour, min, _ := now.Clock()
t2 := fmt.Sprintf("%d-%02d-%02d %02d_%02d", year, month, day, hour, min)

log.Println("Share chart is created", ts, t2)

err := s.backend.WriteShareCharts(ts, t2, login, 0, 0, workerOnline)
if err != nil {
log.Printf("Failed to fetch miner %v charts from backend: %v", login, err)
}
}

func (s *ApiServer) listen() {
r := mux.NewRouter()
r.HandleFunc("/api/finders", s.FindersIndex)
r.HandleFunc("/api/stats", s.StatsIndex)
r.HandleFunc("/api/miners", s.MinersIndex)
r.HandleFunc("/api/blocks", s.BlocksIndex)
Expand Down Expand Up @@ -141,15 +265,37 @@ func (s *ApiServer) collectStats() {
}
if len(s.config.LuckWindow) > 0 {
stats["luck"], err = s.backend.CollectLuckStats(s.config.LuckWindow)
stats["luckCharts"], err = s.backend.CollectLuckCharts(s.config.LuckWindow[0])
if err != nil {
log.Printf("Failed to fetch luck stats from backend: %v", err)
return
}
}
stats["netCharts"], err = s.backend.GetNetCharts(s.config.NetChartsNum)
stats["poolCharts"], err = s.backend.GetPoolCharts(s.config.PoolChartsNum)
s.stats.Store(stats)
log.Printf("Stats collection finished %s", time.Since(start))
}

func (s *ApiServer) FindersIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Cache-Control", "no-cache")
w.WriteHeader(http.StatusOK)

reply := make(map[string]interface{})
stats := s.getStats()
if stats != nil {
reply["now"] = util.MakeTimestamp()
reply["finders"] = stats["finders"]
}

err := json.NewEncoder(w).Encode(reply)
if err != nil {
log.Println("Error serializing API response: ", err)
}
}

func (s *ApiServer) StatsIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Header().Set("Access-Control-Allow-Origin", "*")
Expand All @@ -167,11 +313,15 @@ func (s *ApiServer) StatsIndex(w http.ResponseWriter, r *http.Request) {
if stats != nil {
reply["now"] = util.MakeTimestamp()
reply["stats"] = stats["stats"]
reply["poolCharts"] = stats["poolCharts"]
reply["hashrate"] = stats["hashrate"]
reply["minersTotal"] = stats["minersTotal"]
reply["maturedTotal"] = stats["maturedTotal"]
reply["immatureTotal"] = stats["immatureTotal"]
reply["candidatesTotal"] = stats["candidatesTotal"]
reply["exchangedata"] = stats["exchangedata"]
reply["netCharts"] = stats["netCharts"]
reply["workersTotal"] = stats["workersTotal"]
}

err = json.NewEncoder(w).Encode(reply)
Expand Down Expand Up @@ -217,6 +367,7 @@ func (s *ApiServer) BlocksIndex(w http.ResponseWriter, r *http.Request) {
reply["candidates"] = stats["candidates"]
reply["candidatesTotal"] = stats["candidatesTotal"]
reply["luck"] = stats["luck"]
reply["luckCharts"] = stats["luckCharts"]
}

err := json.NewEncoder(w).Encode(reply)
Expand All @@ -236,6 +387,7 @@ func (s *ApiServer) PaymentsIndex(w http.ResponseWriter, r *http.Request) {
if stats != nil {
reply["payments"] = stats["payments"]
reply["paymentsTotal"] = stats["paymentsTotal"]
reply["exchangedata"] = stats["exchangedata"]
}

err := json.NewEncoder(w).Encode(reply)
Expand All @@ -253,6 +405,8 @@ func (s *ApiServer) AccountIndex(w http.ResponseWriter, r *http.Request) {
s.minersMu.Lock()
defer s.minersMu.Unlock()

generalstats := s.getStats()

reply, ok := s.miners[login]
now := util.MakeTimestamp()
cacheIntv := int64(s.statsIntv / time.Millisecond)
Expand Down Expand Up @@ -285,6 +439,10 @@ func (s *ApiServer) AccountIndex(w http.ResponseWriter, r *http.Request) {
stats[key] = value
}
stats["pageSize"] = s.config.Payments
stats["exchangedata"] = generalstats["exchangedata"]
stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login)
stats["shareCharts"], err = s.backend.GetShareCharts(s.config.ShareChartsNum, login)
stats["paymentCharts"], err = s.backend.GetPaymentCharts(login)
reply = &Entry{stats: stats, updatedAt: now}
s.miners[login] = reply
}
Expand Down
Loading