| | |
| | | SystemDeviceID: conf.Conf.System.DeviceId, |
| | | CurrentDeviceID: conf.Conf.CurrentDeviceID, |
| | | DeviceIDList: list, |
| | | SystemDeviceStatus: response.SystemDeviceStatusNormal, |
| | | ClusterStatus: conf.Conf.SerfClusterStatus, |
| | | ClusterNodeQuantity: conf.Conf.ClusterNodeQuantity, |
| | | SystemDeviceRunSince: conf.Conf.SystemDeviceRunSince, |
| | | } |
| | | ctx.OkWithDetailed(resp) |
| | | } |
| | |
| | | "apsClient/pkg/convertx" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/sqlitex" |
| | | "apsClient/pkg/timex" |
| | | "apsClient/utils" |
| | | "github.com/spf13/viper" |
| | | "log" |
| | | "time" |
| | | ) |
| | | |
| | | var ( |
| | |
| | | |
| | | CurrentDeviceID string //设置当前面板控制的设备 |
| | | |
| | | SerfClusterStatus string |
| | | SerfClusterStatus string //集群状态 |
| | | |
| | | ClusterNodeQuantity int //集群节点数量 |
| | | |
| | | SystemDeviceRunSince int64 //系统开始运行时间戳 |
| | | } |
| | | ) |
| | | |
| | |
| | | if Conf.PLC.StandbyTime == 0 { |
| | | Conf.PLC.StandbyTime = 300 //5分钟 |
| | | } |
| | | |
| | | uptimeStr, err := utils.Exec("uptime -s") |
| | | if err == nil { |
| | | t, err := timex.StringToTime(uptimeStr) |
| | | if err == nil { |
| | | Conf.SystemDeviceRunSince = t.Unix() |
| | | } |
| | | } else { |
| | | Conf.SystemDeviceRunSince = time.Now().Unix() |
| | | } |
| | | |
| | | SetUpTime() |
| | | |
| | | ShowConfig() |
| | | } |
| | | |
| | |
| | | log.Printf(" services : %+v", Conf.Services) |
| | | log.Println("......................................................") |
| | | } |
| | | |
| | | func SetUpTime() { |
| | | uptimeStr, err := utils.Exec("uptime -s") |
| | | if err == nil { |
| | | t, err := timex.StringToTime(uptimeStr) |
| | | if err == nil { |
| | | Conf.SystemDeviceRunSince = t.Unix() |
| | | } |
| | | } else { |
| | | Conf.SystemDeviceRunSince = time.Now().Unix() |
| | | } |
| | | } |
| | |
| | | "apsClient/nsq" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/serf" |
| | | "apsClient/service" |
| | | "fmt" |
| | | "github.com/go-co-op/gocron" |
| | |
| | | s.Every(60).Seconds().Do(SyncProductionProgress) //同步生产数据 |
| | | s.Every(30).Seconds().Do(SyncTaskStatus) //同步任务状态 |
| | | } |
| | | |
| | | s.Every(10).Seconds().Do(QueryClusterStatus) //查询集群节点数量 |
| | | |
| | | s.StartAsync() |
| | | return nil |
| | | } |
| | |
| | | logx.Errorf("send pull data msg error:%v, msg:%+v", err.Error(), msg) |
| | | } |
| | | } |
| | | |
| | | func QueryClusterStatus() { |
| | | clusterStatus, nodeQuantity := serf.QueryClusterStatusAndNodeQuantity() |
| | | conf.Conf.SerfClusterStatus = clusterStatus |
| | | conf.Conf.ClusterNodeQuantity = nodeQuantity |
| | | } |
| | |
| | | "response.DeviceListResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clusterNodeQuantity": { |
| | | "description": "集群节点数量", |
| | | "type": "integer" |
| | | }, |
| | | "clusterStatus": { |
| | | "description": "集群状态", |
| | | "type": "string" |
| | | }, |
| | | "currentDeviceID": { |
| | | "description": "当前选定的生产设备", |
| | | "type": "string" |
| | |
| | | "systemDeviceID": { |
| | | "description": "工控机设备ID", |
| | | "type": "string" |
| | | }, |
| | | "systemDeviceRunSince": { |
| | | "description": "系统运行开始时间戳", |
| | | "type": "integer" |
| | | }, |
| | | "systemDeviceStatus": { |
| | | "description": "设备状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/response.SystemDeviceStatus" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.SystemDeviceStatus": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "SystemDeviceStatusNormal": "正常", |
| | | "SystemDeviceStatusUnNormal": "异常" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "SystemDeviceStatusNormal", |
| | | "SystemDeviceStatusUnNormal" |
| | | ] |
| | | }, |
| | | "response.TaskCountdown": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "response.DeviceListResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clusterNodeQuantity": { |
| | | "description": "集群节点数量", |
| | | "type": "integer" |
| | | }, |
| | | "clusterStatus": { |
| | | "description": "集群状态", |
| | | "type": "string" |
| | | }, |
| | | "currentDeviceID": { |
| | | "description": "当前选定的生产设备", |
| | | "type": "string" |
| | |
| | | "systemDeviceID": { |
| | | "description": "工控机设备ID", |
| | | "type": "string" |
| | | }, |
| | | "systemDeviceRunSince": { |
| | | "description": "系统运行开始时间戳", |
| | | "type": "integer" |
| | | }, |
| | | "systemDeviceStatus": { |
| | | "description": "设备状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/response.SystemDeviceStatus" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.SystemDeviceStatus": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "SystemDeviceStatusNormal": "正常", |
| | | "SystemDeviceStatusUnNormal": "异常" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "SystemDeviceStatusNormal", |
| | | "SystemDeviceStatusUnNormal" |
| | | ] |
| | | }, |
| | | "response.TaskCountdown": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: object |
| | | response.DeviceListResponse: |
| | | properties: |
| | | clusterNodeQuantity: |
| | | description: 集群节点数量 |
| | | type: integer |
| | | clusterStatus: |
| | | description: 集群状态 |
| | | type: string |
| | | currentDeviceID: |
| | | description: 当前选定的生产设备 |
| | | type: string |
| | |
| | | systemDeviceID: |
| | | description: 工控机设备ID |
| | | type: string |
| | | systemDeviceRunSince: |
| | | description: 系统运行开始时间戳 |
| | | type: integer |
| | | systemDeviceStatus: |
| | | allOf: |
| | | - $ref: '#/definitions/response.SystemDeviceStatus' |
| | | description: 设备状态 |
| | | type: object |
| | | response.ListResponse: |
| | | properties: |
| | |
| | | totalNumber: |
| | | type: integer |
| | | type: object |
| | | response.SystemDeviceStatus: |
| | | enum: |
| | | - 1 |
| | | - 2 |
| | | type: integer |
| | | x-enum-comments: |
| | | SystemDeviceStatusNormal: 正常 |
| | | SystemDeviceStatusUnNormal: 异常 |
| | | x-enum-varnames: |
| | | - SystemDeviceStatusNormal |
| | | - SystemDeviceStatusUnNormal |
| | | response.TaskCountdown: |
| | | properties: |
| | | countDownHour: |
| | |
| | | Data interface{} |
| | | } |
| | | |
| | | type SystemDeviceStatus int |
| | | |
| | | const ( |
| | | SystemDeviceStatusNormal SystemDeviceStatus = 1 //正常 |
| | | SystemDeviceStatusUnNormal SystemDeviceStatus = 2 //异常 |
| | | ) |
| | | |
| | | type DeviceListResponse struct { |
| | | SystemDeviceID string `json:"systemDeviceID,omitempty"` //工控机设备ID |
| | | CurrentDeviceID string `json:"currentDeviceID,omitempty"` //当前选定的生产设备 |
| | | DeviceIDList []string `json:"deviceIDList,omitempty"` //生产设备id列表 |
| | | SystemDeviceStatus SystemDeviceStatus `json:"systemDeviceStatus"` //设备状态 |
| | | ClusterStatus string `json:"clusterStatus"` //集群状态 |
| | | ClusterNodeQuantity int `json:"clusterNodeQuantity"` //集群节点数量 |
| | | SystemDeviceRunSince int64 `json:"systemDeviceRunSince"` //系统运行开始时间戳 |
| | | } |
| | |
| | | "context" |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/mitchellh/mapstructure" |
| | | "os" |
| | | "os/signal" |
| | | "regexp" |
| | |
| | | } |
| | | |
| | | // 查询集群状态, 返回 master, slave, leave |
| | | func (ss *SyncServer) QueryClusterStat() string { |
| | | func (ss *SyncServer) QueryClusterStat() *bhomeclient.Reply { |
| | | clusterStatTopic := "/data/api-v/cluster/status" |
| | | req := bhomeclient.Request{ |
| | | Path: clusterStatTopic, |
| | |
| | | if err != nil { |
| | | fmt.Println("RequestTopic error", err.Error()) |
| | | |
| | | return "" |
| | | return reply |
| | | } |
| | | |
| | | ss.ClusterStatus = reply.Msg |
| | | |
| | | logx.Debugf("当前集群状态: %s", ss.ClusterStatus) |
| | | |
| | | return reply.Msg |
| | | return reply |
| | | } |
| | | |
| | | func (ss *SyncServer) handleDbLoggerPrint() { |
| | |
| | | |
| | | return "" |
| | | } |
| | | |
| | | type NodeInfo struct { |
| | | NodeID string `json:"node_id,omitempty"` |
| | | NodeIp string `json:"node_ip,omitempty"` |
| | | NodeName string `json:"node_name,omitempty"` |
| | | ClusterID string `json:"cluster_id"` |
| | | CreateTime string `json:"create_time"` |
| | | DeviceType string `json:"device_type"` |
| | | DriftState string `json:"drift_state"` |
| | | Online string `json:"online"` |
| | | } |
| | | |
| | | func QueryClusterStatusAndNodeQuantity() (string, int) { |
| | | reply := agent.QueryClusterStat() |
| | | if reply == nil { |
| | | return "", 0 |
| | | } |
| | | var nodes []NodeInfo |
| | | err := mapstructure.Decode(reply.Data, &nodes) |
| | | if err != nil { |
| | | logx.Errorf("mapstructure.Decode QueryClusterStat data err:%v", err) |
| | | return reply.Msg, 0 |
| | | } |
| | | return reply.Msg, len(nodes) |
| | | } |
| | |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func Exec(command string) (outputStr string, err error) { |
| | | cmd := exec.Command(command) |
| | | |
| | | // 捕获命令的输出 |
| | | output, err := cmd.Output() |
| | | if err != nil { |
| | | return "", fmt.Errorf("命令执行失败: %v", err) |
| | | } |
| | | |
| | | // 将输出转换为字符串 |
| | | outputStr = string(output) |
| | | return |
| | | } |