Commit 644c5350 authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# 修改db 的解析结构

parent c2caca2c
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"git.quantgroup.cn/DevOps/enoch/service/data"
"git.quantgroup.cn/DevOps/enoch/service/end_points"
"git.quantgroup.cn/DevOps/enoch/service/log"
"github.com/gomodule/redigo/redis"
"github.com/influxdata/influxdb/client/v2"
......@@ -20,7 +21,7 @@ var httpMethod = map[string]string{
func (BraveMessageHandler) MsgProcess(msg string) {
traceMsg := make([]TraceMsg, 3) //[]TraceMsg{}
traceMsg := make([]end_points.TraceMsg, 3) //[]TraceMsg{}
err := json.Unmarshal([]byte(msg), &traceMsg)
if err != nil {
logger.Error.Println("brave 解析msg失败:", err)
......@@ -37,7 +38,7 @@ func (BraveMessageHandler) Destroy() {
var pointSlice = make([]*client.Point, 0, batchSize)
func msgInfluxProcess(traceMsgs []TraceMsg) {
func msgInfluxProcess(traceMsgs []end_points.TraceMsg) {
for _, traceMsg := range traceMsgs {
......
......@@ -21,7 +21,7 @@ func (HealthMessageHandler) MsgProcess(msg string) {
chunkMsg := end_points.ChunkMsg{}
err := json.Unmarshal([]byte(msg), &chunkMsg)
if err != nil {
logger.Error.Println("healthMessageHandler解析json失败:",err)
logger.Error.Println("healthMessageHandler解析json失败:", err)
logger.Error.Println(msg)
}
buildMsg(chunkMsg)
......@@ -39,16 +39,26 @@ func (HealthMessageHandler) Destroy() {
}
}
func buildHealthInfluxMsg(appName string, ip string, timestamp time.Time, submitLimit int, db map[string]end_points.DBDetail) {
func buildHealthInfluxMsg(appName string, ip string, timestamp time.Time, submitLimit int, db *[]byte) {
tags := make(map[string]string, )
tags["sys_name"] = appName
tags["host"] = ip
fields := make(map[string]interface{})
for k, v := range db {
dbInfo := end_points.DBInfo{}
err := json.Unmarshal(*db, &dbInfo)
if err != nil {
dbDetails := end_points.DBDetail{}
err = json.Unmarshal(*db, &dbDetails)
if err == nil {
fields[dbDetails.Details.Database] = isOK(dbDetails.Status.Code)
}
}else {
for k, v := range dbInfo.Details {
var fieldName = v.Details.Database + "—" + k
fields[fieldName] = isOK(v.Status.Code)
}
}
if len(healthPointSlice) >= submitLimit {
go batchWrite(healthPointSlice)
healthPointSlice = make([]*client.Point, 0, batchSize)
......@@ -63,10 +73,12 @@ func buildMetricsInfluxMsg(appName string, ip string, timestamp time.Time, submi
tags["sys_name"] = appName
tags["host"] = ip
var status = health.Status
status := health.Status
fields["sever_status"] = isOK(status.Code)
var diskSpace = health.Details.DiskSpace.Details
redis := health.Details.Redis
fields["redis_status"] = isOK(redis.Status.Code)
diskSpace := health.Details.DiskSpace.Details
fields["disk_tol"] = diskSpace.Total
fields["disk_free"] = diskSpace.Free
......@@ -124,7 +136,8 @@ func buildMsg(chunkMsg end_points.ChunkMsg) {
buildMetricsInfluxMsg(appName, ip, unix, sysNameCount, p.Health, p.Metrics)
//health_info
buildHealthInfluxMsg(appName, ip, unix, sysNameCount, p.Health.Details.Db.Details)
dbByte, _ := json.Marshal(p.Health.Details.Db)
buildHealthInfluxMsg(appName, ip, unix, sysNameCount, &dbByte)
}
}
......
......@@ -19,7 +19,8 @@ type Health struct {
type Detail struct {
DiskSpace DiskInfo `json:"diskSpace"`
Redis RedisInfo `json:"redis"`
Db DBInfo `json:"db"`
Db interface{} `json:"db"`
}
type DBInfo struct {
......
package consumer
package end_points
type TraceMsg struct {
TraceId string `json:"traceId"`
......
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