Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
enoch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
enoch
Commits
644c5350
Commit
644c5350
authored
May 22, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 修改db 的解析结构
parent
c2caca2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
17 deletions
+32
-17
brave_message_handler.go
service/consumer/brave_message_handler.go
+3
-2
health_message_handler.go
service/consumer/health_message_handler.go
+23
-10
chunk_msg.go
service/end_points/chunk_msg.go
+5
-4
trace_msg.go
service/end_points/trace_msg.go
+1
-1
No files found.
service/consumer/brave_message_handler.go
View file @
644c5350
...
@@ -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
{
...
...
service/consumer/health_message_handler.go
View file @
644c5350
...
@@ -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
)
}
}
}
}
...
...
service/end_points/chunk_msg.go
View file @
644c5350
...
@@ -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"`
}
}
/**
/**
硬盘信息
硬盘信息
...
...
service/
consumer
/trace_msg.go
→
service/
end_points
/trace_msg.go
View file @
644c5350
package
consumer
package
end_points
type
TraceMsg
struct
{
type
TraceMsg
struct
{
TraceId
string
`json:"traceId"`
TraceId
string
`json:"traceId"`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment