Commit f8a4a973 authored by szh's avatar szh

统计信息更新 增加历史表和info信息具体到字段

parent fc1eb543
......@@ -29,7 +29,7 @@ func init() {
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
func main() {
go app.CornClean(time.NewTicker(time.Hour*24))
go app.CornDayJob(time.NewTicker(time.Hour*24))
go app.CornData(time.NewTicker(time.Minute*5))
gin.SetMode(setting.ServerSetting.RunMode)
routersInit := routers.InitRouter()
......
......@@ -29,7 +29,7 @@ func init() {
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
func main() {
go app.CornClean(time.NewTicker(time.Hour*24))
go app.CornDayJob(time.NewTicker(time.Hour*24))
go app.CornData(time.NewTicker(time.Minute*5))
gin.SetMode(setting.ServerSetting.RunMode)
routersInit := routers.InitRouter()
......
package models
import "chain33-pai/pkg/util"
type RaspDevHistory struct {
//Model
Id int64 `json:"id" gorm:"PRIMARY_KEY"`
Addr string `json:"addr"`
Info string `json:"info"`
Addtime string `json:"addtime"`
}
const MonthDevHistoryTable = `
DROP TABLE IF EXISTS '?_rasp_miner_stat';
CREATE TABLE '?_rasp_dev_history' (
'id' bigint(20) NOT NULL AUTO_INCREMENT,
'addr' varchar(20) NOT NULL,
'info' text,
'addtime' varchar(32) DEFAULT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COMMENT='上传历史'`
//
func CreateMonthDevHistoryTable() error {
date := util.GetMonthDate()
return db.Raw(MonthDevHistoryTable,date,date).Error
}
func AddDevHistory(rasp *RaspDevHistory) error {
return db.Create(rasp).Error
}
package models
import (
"chain33-pai/service/pai_service"
"encoding/json"
"time"
"strings"
)
type RaspDevList struct {
Id int64 `json:"id"`
Addr string `json:"addr"`
PaiVersion string `json:"pai_version"`
UpdateTime int64 `json:"update_time"`
Height int64 `json:"height"`
BtyVersion string `json:"bty_version"`
ExtIp string `json:"ext_ip"`
Error string `json:"error"`
WalletStatus int32 `json:"wallet_status"`
NodeStatus int32 `json:"node_status"`
PaiStatus int32 `json:"pai_status"`
UserName string `json:"user_name"`
Email string `json:"email"`
Phone string `json:"phone"`
}
func convertDevList(params map[string]string) RaspDevList {
var pai pai_service.Pai
var rasp RaspDevList
rasp.Addr = params["addr"]
rasp.PaiVersion = params["version"]
err := json.Unmarshal([]byte(params["info"]),&pai)
if err != nil {
rasp.Error = err.Error()
return rasp
}
rasp.UpdateTime = time.Now().Unix()
if pai.Err == "" {
rasp.NodeStatus = 1
rasp.Height = pai.LastHeight
if !pai.WalletStatus.IsTicketLock {
rasp.WalletStatus = 2
} else if !pai.WalletStatus.IsWalletLock && pai.WalletStatus.IsTicketLock {
rasp.WalletStatus = 1
} else if pai.WalletStatus.IsTicketLock && pai.WalletStatus.IsWalletLock {
rasp.WalletStatus = 3
}
laddr := strings.Split(pai.NetInfo.Externaladdr,":")
if len(laddr) == 2 {
rasp.ExtIp = laddr[0]
} else {
rasp.ExtIp = pai.NetInfo.Externaladdr
}
rasp.BtyVersion = pai.BtyVersion.App
}
return rasp
}
func UpdateDevList(params map[string]string) error {
var dev RaspDevList
rasp := convertDevList(params)
err := db.Where(RaspDevList{Addr: rasp.Addr}).Assign(rasp).FirstOrCreate(&dev).Error
if err != nil {
return err
}
return nil
}
......@@ -137,12 +137,13 @@ func CleanUpNossh(){
models.DeleteCompleteFeedbackNossh()
}
func CornClean(ticker *time.Ticker){
func CornDayJob(ticker *time.Ticker){
for{
select {
case <-ticker.C:
CleanUp()
CleanUpNossh()
CreateMonthTable()
}
}
}
......@@ -171,4 +172,8 @@ func UploadMinerData() bool {
return false
}
}
func CreateMonthTable() error {
return models.CreateMonthDevHistoryTable()
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import (
"chain33-pai/pkg/setting"
"net"
"errors"
"time"
)
// Setup Initialize the util
......@@ -37,4 +38,8 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
err = errors.New("ERR_NO_LOCAL_IP_FOUND")
return
}
\ No newline at end of file
}
func GetMonthDate() string {
return time.Now().Format("2006-1")
}
......@@ -269,11 +269,26 @@ func GetUploadInfo(c *gin.Context){
appG.Response(http.StatusOK, e.INVALID_PARAMS, nil)
return
}
date := time.Now().Format("2006-01-02 15:04:05")
t := time.Now()
date := t.Format("2006-01-02 15:04:05")
KP["date"] = date
history := &models.RaspDevHistory{
Addr:KP["addr"],
Info:KP["info"],
Addtime:date,
}
err = models.AddDevHistory(history)
if err != nil {
appG.Response(http.StatusOK, e.ERROR, nil)
return
}
err = models.UpdateDevList(KP)
if err != nil {
appG.Response(http.StatusOK, e.ERROR, nil)
return
}
err = models.UpdateDevVersion(KP)
if err != nil {
appG.Response(http.StatusOK, e.ERROR, nil)
return
}
......
......@@ -17,16 +17,19 @@ var (
pai_serial string
)
type Pai struct {
Hardware string `json:"hardware"`
Revision string `json:"revision"`
Serial string `json:"serial"`
//PeerList *types.PeerList
LocalLastHeight int64 `json:"local_last_height"`
LastHeight int64 `json:"last_height"`
IsNtpSync bool `json:"is_ntp_sync"`
WalletStatus *types.WalletStatus `json:"wallet_status"`
NetInfo *types.NodeNetInfo `json:"net_info"`
BtyVersion *types.VersionInfo `json:"bty_version"`
Err string `json:"err"`
Arch string `json:"arch"`
}
type MinedInfo struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment