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

# 修改db 的解析结构

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