btcpool礦池原始碼分析(9)-statshttpd模組解析
# btcpool礦池-statshttpd模組解析
## 核心機制總結
* 監聽並接收SHARE_LOG,按Worker、user、pool統計acceptCount_、acceptShareSec_、rejectShareMin_
* 同時統計totalWorkerCount_和totalUserCount_
* 延時超過1小時的SHARE_LOG將被忽略
* 每15s寫入資料庫(可由flush_db_interval指定),每30分鐘清理過期Worker
* 如果Worker超過1小時未提交share,將被置為過期狀態
* 計算每個Worker的accept1m_、accept5m_、accept15m_、reject15m_、accept1h_、reject1h_
* 以及acceptCount_、lastShareIP_、lastShareTime_
* DROP並CREATE資料表mining_workers_tmp,Worker統計資料批量寫入mining_workers_tmp
* mining_workers_tmp資料寫入資料表mining_workers
* 監聽並接收COMMON_EVENTS,獲取workerName和minerAgent,更新資料表mining_workers
* 啟動Httpd服務,開放ServerStatus和WorkerStatus
## statshttpd命令使用
```shell
statshttpd -c statshttpd.cfg -l log_dir
#-c指定statshttpd配置檔案
#-l指定日誌目錄
```
## statshttpd.cfg配置檔案
```shell
#指定kafka叢集
kafka = {
brokers = "1.1.1.1:9092,2.2.2.2:9092,3.3.3.3:9092";
};
statshttpd = {
#指定IP和埠
ip = "0.0.0.0";
port = 8080;
#間隔15s將workers data入庫
flush_db_interval = 15;
#最近一次寫庫時間
file_last_flush_time = "/work/xxx/statshttpd_lastflushtime.txt";
};
#指定資料庫配置
pooldb = {
host = "";
port = 3306;
username = "dbusername";
password = "dbpassword";
dbname = "";
};
```
## mining_workers/mining_workers_tmp資料表結構
```c++
CREATE TABLE `mining_workers_tmp` (
`worker_id` bigint(20) NOT NULL,
`puid` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
`worker_name` varchar(20) DEFAULT NULL,
`accept_1m` bigint(20) NOT NULL DEFAULT '0',
`accept_5m` bigint(20) NOT NULL DEFAULT '0',
`accept_15m` bigint(20) NOT NULL DEFAULT '0',
`reject_15m` bigint(20) NOT NULL DEFAULT '0',
`accept_1h` bigint(20) NOT NULL DEFAULT '0',
`reject_1h` bigint(20) NOT NULL DEFAULT '0',
`accept_count` int(11) NOT NULL DEFAULT '0',
`last_share_ip` char(16) NOT NULL DEFAULT '0.0.0.0',
`last_share_time` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01',
`miner_agent` varchar(30) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
UNIQUE KEY `puid_worker_id` (`puid`,`worker_id`),
KEY `puid_group_id` (`puid`,`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mining_workers` (
`worker_id` bigint(20) NOT NULL,
`puid` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
`worker_name` varchar(20) DEFAULT NULL,
`accept_1m` bigint(20) NOT NULL DEFAULT '0',
`accept_5m` bigint(20) NOT NULL DEFAULT '0',
`accept_15m` bigint(20) NOT NULL DEFAULT '0',
`reject_15m` bigint(20) NOT NULL DEFAULT '0',
`accept_1h` bigint(20) NOT NULL DEFAULT '0',
`reject_1h` bigint(20) NOT NULL DEFAULT '0',
`accept_count` int(11) NOT NULL DEFAULT '0',
`last_share_ip` char(16) NOT NULL DEFAULT '0.0.0.0',
`last_share_time` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01',
`miner_agent` varchar(30) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
UNIQUE KEY `puid_worker_id` (`puid`,`worker_id`),
KEY `puid_group_id` (`puid`,`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```
mining_workers_tmp資料寫入資料表mining_workers
```c++
const string mergeSQL = "INSERT INTO `mining_workers` "
" SELECT * FROM `mining_workers_tmp` "
" ON DUPLICATE KEY "
" UPDATE "
" `mining_workers`.`accept_1m` =`mining_workers_tmp`.`accept_1m`, "
" `mining_workers`.`accept_5m` =`mining_workers_tmp`.`accept_5m`, "
" `mining_workers`.`accept_15m` =`mining_workers_tmp`.`accept_15m`, "
" `mining_workers`.`reject_15m` =`mining_workers_tmp`.`reject_15m`, "
" `mining_workers`.`accept_1h` =`mining_workers_tmp`.`accept_1h`, "
" `mining_workers`.`reject_1h` =`mining_workers_tmp`.`reject_1h`, "
" `mining_workers`.`accept_count` =`mining_workers_tmp`.`accept_count`,"
" `mining_workers`.`last_share_ip` =`mining_workers_tmp`.`last_share_ip`,"
" `mining_workers`.`last_share_time`=`mining_workers_tmp`.`last_share_time`,"
" `mining_workers`.`updated_at` =`mining_workers_tmp`.`updated_at` ";
```
## statshttpd流程圖
網址:http://www.qukuailianxueyuan.io/
欲領取造幣技術與全套虛擬機器資料
區塊鏈技術交流QQ群:756146052 備註:CSDN
尹成學院微信:備註:CSDN
網址:http://www.qukuailianxueyuan.io/
欲領取造幣技術與全套虛擬機器資料
區塊鏈技術交流QQ群:756146052 備註:CSDN
尹成學院微信:備註:CSDN
相關文章
- btcpool礦池原始碼分析(3)-BlockMaker模組解析TCP原始碼BloC
- btcpool礦池原始碼分析(4)-GbtMaker模組解析TCP原始碼
- btcpool礦池原始碼分析(5)-JobMaker模組解析TCP原始碼
- btcpool礦池原始碼分析(6)-nmcauxmaker模組解析TCP原始碼UX
- btcpool礦池原始碼分析(6)-PoolWatcher模組解析TCP原始碼
- btcpool礦池原始碼分析(7)-sharelogger模組解析TCP原始碼
- btcpool礦池原始碼分析(10)-StratumServer模組解析TCP原始碼Server
- btcpool礦池原始碼分析(8)-slparserTCP原始碼
- btcpool礦池原始碼分析(1)環境搭建TCP原始碼
- btcpool礦池原始碼分析(2)-核心機制總結及優化思考TCP原始碼優化
- open-ethereum-pool以太坊礦池原始碼分析(3)payouts模組原始碼
- open-ethereum-pool以太坊礦池原始碼分析(4)-policy模組原始碼
- open-ethereum-pool以太坊礦池原始碼分析(5)proxy模組原始碼
- open-ethereum-pool以太坊礦池原始碼分析(6)-redis模組原始碼Redis
- open-ethereum-pool以太坊礦池原始碼分析(7)unlocker模組原始碼
- Django(49)drf解析模組原始碼分析Django原始碼
- (一) Mybatis原始碼分析-解析器模組MyBatis原始碼
- Swoole 原始碼分析——記憶體模組之記憶體池原始碼記憶體
- go-ethereum原始碼解析-miner挖礦部分原始碼分析CPU挖礦Go原始碼
- webpack核心模組tapable原始碼解析Web原始碼
- open-ethereum-pool以太坊礦池原始碼分析(2)API分析原始碼API
- python2 traceback模組原始碼解析Python原始碼
- QT Widgets模組原始碼解析與技巧QT原始碼
- SOFARegistry 原始碼|資料同步模組解析原始碼
- mybaits原始碼分析--binding模組(五)AI原始碼
- open-ethereum-pool以太坊礦池原始碼分析(1)-main入口分析原始碼AI
- QT Widgets模組原始碼解析與實踐QT原始碼
- 從原始碼分析Node的Cluster模組原始碼
- Swoole 原始碼分析——Reactor 模組之 ReactorEpoll原始碼React
- Swoole 原始碼分析——Client模組之Send原始碼client
- Swoole 原始碼分析——Client模組之Connect原始碼client
- Swoole 原始碼分析——Client模組之Recv原始碼client
- JavaScript 模組化及 SeaJs 原始碼分析JavaScriptJS原始碼
- mybaits原始碼分析--快取模組(六)AI原始碼快取
- mybaits原始碼分析--日誌模組(四)AI原始碼
- Django(51)drf渲染模組原始碼分析Django原始碼
- 以太坊原始碼分析(42)miner挖礦部分原始碼分析CPU挖礦原始碼
- Swoole 原始碼分析——Server 模組之 OpenSSL (下)原始碼Server