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
85d47da0
Commit
85d47da0
authored
Mar 12, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 解析健康信息
parent
3451cc63
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
173 deletions
+143
-173
agent_msg_process.go
service/agent_msg_process.go
+90
-53
chunk_msg.go
service/end_points/chunk_msg.go
+53
-120
No files found.
service/agent_msg_process.go
View file @
85d47da0
...
@@ -11,6 +11,8 @@ import (
...
@@ -11,6 +11,8 @@ import (
)
)
var
sysNameIndex
=
make
(
map
[
int64
]
bool
)
var
sysNameIndex
=
make
(
map
[
int64
]
bool
)
var
metricsPointSlice
=
make
([]
*
client
.
Point
,
0
,
batchSize
)
var
healthPointSlice
=
make
([]
*
client
.
Point
,
0
,
batchSize
)
func
AgentMsgProcess
(
msg
string
)
{
func
AgentMsgProcess
(
msg
string
)
{
chunkMsg
:=
end_points
.
ChunkMsg
{}
chunkMsg
:=
end_points
.
ChunkMsg
{}
...
@@ -18,25 +20,37 @@ func AgentMsgProcess(msg string) {
...
@@ -18,25 +20,37 @@ func AgentMsgProcess(msg string) {
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
buildM
etricsInfluxM
sg
(
chunkMsg
)
buildMsg
(
chunkMsg
)
}
}
func
buildMetricsInfluxMsg
(
chunkMsg
end_points
.
ChunkMsg
)
{
func
buildHealthInfluxMsg
(
appName
string
,
ip
string
,
timestamp
time
.
Time
,
submitLimit
int
,
db
map
[
string
]
end_points
.
DBDetail
)
{
var
ip
=
inetAtoN
(
chunkMsg
.
Ip
)
sysNameIndex
[
ip
]
=
true
var
sysNameCount
=
len
(
sysNameIndex
)
for
_
,
p
:=
range
chunkMsg
.
EndPoints
{
tags
:=
make
(
map
[
string
]
string
,
)
tags
:=
make
(
map
[
string
]
string
,
)
tags
[
"sys_name"
]
=
chunkMsg
.
A
ppName
tags
[
"sys_name"
]
=
a
ppName
tags
[
"host"
]
=
chunkMsg
.
I
p
tags
[
"host"
]
=
i
p
fields
:=
make
(
map
[
string
]
interface
{})
fields
:=
make
(
map
[
string
]
interface
{})
var
metrics
=
p
.
Metrics
var
health
=
p
.
Health
var
status
=
health
.
Status
for
k
,
v
:=
range
db
{
if
"UP"
==
status
.
Code
{
var
fieldName
=
v
.
Details
.
Database
+
"—"
+
k
fields
[
"sever_status"
]
=
1
fields
[
fieldName
]
=
isOK
(
v
.
Status
.
Code
)
}
if
len
(
healthPointSlice
)
>=
submitLimit
{
go
batchWrite
(
healthPointSlice
)
healthPointSlice
=
make
([]
*
client
.
Point
,
0
,
batchSize
)
}
}
point
,
_
:=
client
.
NewPoint
(
"health_info"
,
tags
,
fields
,
timestamp
)
println
(
point
)
healthPointSlice
=
append
(
healthPointSlice
,
point
)
}
func
buildMetricsInfluxMsg
(
appName
string
,
ip
string
,
timestamp
time
.
Time
,
submitLimit
int
,
health
end_points
.
Health
,
metrics
end_points
.
MetricsInfo
)
{
tags
:=
make
(
map
[
string
]
string
,
)
fields
:=
make
(
map
[
string
]
interface
{})
tags
[
"sys_name"
]
=
appName
tags
[
"host"
]
=
ip
var
status
=
health
.
Status
fields
[
"sever_status"
]
=
isOK
(
status
.
Code
)
var
diskSpace
=
health
.
Details
.
DiskSpace
.
Details
var
diskSpace
=
health
.
Details
.
DiskSpace
.
Details
fields
[
"disk_tol"
]
=
diskSpace
.
Total
fields
[
"disk_tol"
]
=
diskSpace
.
Total
...
@@ -72,13 +86,29 @@ func buildMetricsInfluxMsg(chunkMsg end_points.ChunkMsg) {
...
@@ -72,13 +86,29 @@ func buildMetricsInfluxMsg(chunkMsg end_points.ChunkMsg) {
fields
[
"instance_uptime"
]
=
metrics
.
InstanceUptime
fields
[
"instance_uptime"
]
=
metrics
.
InstanceUptime
fields
[
"system_load_average"
]
=
metrics
.
SystemloadAverage
fields
[
"system_load_average"
]
=
metrics
.
SystemloadAverage
unix
:=
time
.
Unix
(
0
,
p
.
Timestamp
*
1000000
)
if
len
(
metricsPointSlice
)
>=
submitLimit
{
if
len
(
pointSlice
)
>=
sysNameCount
{
go
batchWrite
(
metricsPointSlice
)
go
batchWrite
(
pointSlice
)
metricsPointSlice
=
make
([]
*
client
.
Point
,
0
,
batchSize
)
pointSlice
=
make
([]
*
client
.
Point
,
0
,
batchSize
)
}
}
point
,
_
:=
client
.
NewPoint
(
"machine_info"
,
tags
,
fields
,
unix
)
point
,
_
:=
client
.
NewPoint
(
"machine_info"
,
tags
,
fields
,
timestamp
)
pointSlice
=
append
(
pointSlice
,
point
)
metricsPointSlice
=
append
(
metricsPointSlice
,
point
)
}
func
buildMsg
(
chunkMsg
end_points
.
ChunkMsg
)
{
var
ip
=
inetAtoN
(
chunkMsg
.
Ip
)
sysNameIndex
[
ip
]
=
true
var
sysNameCount
=
len
(
sysNameIndex
)
for
_
,
p
:=
range
chunkMsg
.
EndPoints
{
var
appName
=
chunkMsg
.
AppName
var
ip
=
chunkMsg
.
Ip
unix
:=
time
.
Unix
(
0
,
p
.
Timestamp
*
1000000
)
//metricsInfo
buildMetricsInfluxMsg
(
appName
,
ip
,
unix
,
sysNameCount
,
p
.
Health
,
p
.
Metrics
)
//health_info
buildHealthInfluxMsg
(
appName
,
ip
,
unix
,
sysNameCount
,
p
.
Health
.
Details
.
Db
.
Details
)
}
}
}
}
...
@@ -87,3 +117,10 @@ func inetAtoN(ip string) int64 {
...
@@ -87,3 +117,10 @@ func inetAtoN(ip string) int64 {
ret
.
SetBytes
(
net
.
ParseIP
(
ip
)
.
To4
())
ret
.
SetBytes
(
net
.
ParseIP
(
ip
)
.
To4
())
return
ret
.
Int64
()
return
ret
.
Int64
()
}
}
func
isOK
(
code
string
)
int
{
if
"UP"
==
code
{
return
1
}
return
0
}
service/end_points/chunk_msg.go
View file @
85d47da0
...
@@ -10,7 +10,6 @@ type EndPoint struct {
...
@@ -10,7 +10,6 @@ type EndPoint struct {
Health
Health
`json:"health"`
Health
Health
`json:"health"`
Metrics
MetricsInfo
`json:"metrics"`
Metrics
MetricsInfo
`json:"metrics"`
Timestamp
int64
`json:"timestamp"`
Timestamp
int64
`json:"timestamp"`
}
}
type
Health
struct
{
type
Health
struct
{
Status
Status
`json:"status"`
Status
Status
`json:"status"`
...
@@ -20,7 +19,21 @@ type Health struct {
...
@@ -20,7 +19,21 @@ 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
interface
{}
`json:"db"`
Db
DBInfo
`json:"db"`
}
type
DBInfo
struct
{
Details
map
[
string
]
DBDetail
`json:"details"`
Status
Status
`json:"status"`
}
type
DBDetail
struct
{
Status
Status
`json:"status"`
Details
DBDetailInfo
`json:"details"`
}
type
DBDetailInfo
struct
{
Database
string
`json:"database"`
}
}
/**
/**
...
@@ -47,10 +60,6 @@ type RedisInfo struct {
...
@@ -47,10 +60,6 @@ type RedisInfo struct {
Status
Status
`json:"status"`
Status
Status
`json:"status"`
}
}
type
Status
struct
{
type
Status
struct
{
Code
string
`json:"code"`
Code
string
`json:"code"`
Description
string
`json:"description"`
Description
string
`json:"description"`
...
@@ -82,80 +91,4 @@ type MetricsInfo struct {
...
@@ -82,80 +91,4 @@ type MetricsInfo struct {
GcParnewTime
int
`json:"gc.parnew.time"`
GcParnewTime
int
`json:"gc.parnew.time"`
GcConcurrentmarksweepCount
int
`json:"gc.concurrentmarksweep.count"`
GcConcurrentmarksweepCount
int
`json:"gc.concurrentmarksweep.count"`
GcConcurrentmarksweepTime
int
`json:"gc.concurrentmarksweep.time"`
GcConcurrentmarksweepTime
int
`json:"gc.concurrentmarksweep.time"`
//CounterStatus200AddReduceApply int `json:"counter.status.200.addReduceApply"`
//CounterStatus200OwnerList int `json:"counter.status.200.ownerList"`
//CounterStatus200ShowReport int `json:"counter.status.200.showReport"`
//GaugeResponseShowReduceApplyList int `json:"gauge.response.showReduceApplyList"`
//CounterStatus200ShowOwnerReduceApplyList int `json:"counter.status.200.showOwnerReduceApplyList"`
//GaugeResponseQueryPreciseCallRecordList int `json:"gauge.response.queryPreciseCallRecordList"`
//GaugeResponseQueryUserPhoneRemarkList int `json:"gauge.response.queryUserPhoneRemarkList"`
//CounterStatus200FindCreditReport int `json:"counter.status.200.findCreditReport"`
//GaugeResponseAddUserPhoneRemark int `json:"gauge.response.addUserPhoneRemark"`
//CounterStatus200DisperseCase int `json:"counter.status.200.disperseCase"`
//CounterStatus200QueryDispatcherParam int `json:"counter.status.200.queryDispatcherParam"`
//CounterStatus200CheckReduceApply int `json:"counter.status.200.checkReduceApply"`
//GaugeResponseQueryRepayOrderList int `json:"gauge.response.queryRepayOrderList"`
//GaugeResponseAddReduceApply int `json:"gauge.response.addReduceApply"`
//GaugeResponseOwnerList int `json:"gauge.response.ownerList"`
//GaugeResponsePhoneBook int `json:"gauge.response.phoneBook"`
//CounterStatus200ViewCaseDetail int `json:"counter.status.200.viewCaseDetail"`
//GaugeResponseUserInfo int `json:"gauge.response.userInfo"`
//GaugeResponseFindAlipayInfo int `json:"gauge.response.findAlipayInfo"`
//CounterStatus200MenuTree int `json:"counter.status.200.menuTree"`
//GaugeResponseCheckReduceApply int `json:"gauge.response.checkReduceApply"`
//CounterStatus200QueryPreciseCallRecordList int `json:"counter.status.200.queryPreciseCallRecordList"`
//CounterStatus200PhoneBook int `json:"counter.status.200.phoneBook"`
//GaugeResponseAutoAssignReceiveRelation int `json:"gauge.response.autoAssign.receiveRelation"`
//CounterStatus200SaveCall int `json:"counter.status.200.saveCall"`
//CounterStatus200QueryRepayOrderList int `json:"counter.status.200.queryRepayOrderList"`
//CounterStatus200AutoAssignReceiveRelation int `json:"counter.status.200.autoAssign.receiveRelation"`
//CounterStatus200RemoveCallRecord int `json:"counter.status.200.removeCallRecord"`
//GaugeResponseOrganizationList int `json:"gauge.response.organizationList"`
//CounterStatus200QueryCasePackPage int `json:"counter.status.200.queryCasePackPage"`
//GaugeResponseShowOwnerReduceApplyList int `json:"gauge.response.showOwnerReduceApplyList"`
//GaugeResponseHandleCollectionReduce int `json:"gauge.response.handleCollectionReduce"`
//CounterStatus200Logout int `json:"counter.status.200.logout"`
//CounterStatus200QueryCasePage int `json:"counter.status.200.queryCasePage"`
//GaugeResponseSelectList int `json:"gauge.response.selectList"`
//CounterStatus200HandleCollectionReduce int `json:"counter.status.200.handleCollectionReduce"`
//CounterStatus200FindAlipayInfo int `json:"counter.status.200.findAlipayInfo"`
//GaugeResponseFundingList int `json:"gauge.response.fundingList"`
//GaugeResponseTechHealthCheck int `json:"gauge.response.tech.health.check"`
//CounterStatus200Login int `json:"counter.status.200.login"`
//CounterStatus200HaveUnCheckedApply int `json:"counter.status.200.haveUnCheckedApply"`
//GaugeResponseSaveCall int `json:"gauge.response.saveCall"`
//GaugeResponseQueryDispatcherParam int `json:"gauge.response.queryDispatcherParam"`
//CounterStatus200OrganizationList int `json:"counter.status.200.organizationList"`
//GaugeResponseQueryOrganizationList int `json:"gauge.response.queryOrganizationList"`
//CounterStatus200ShowReduceApplyList int `json:"counter.status.200.showReduceApplyList"`
//CounterStatus200QueryDisperseParam int `json:"counter.status.200.queryDisperseParam"`
//CounterStatus200AgingList int `json:"counter.status.200.agingList"`
//CounterStatus200UserInfo int `json:"counter.status.200.userInfo"`
//GaugeResponseQueryUserPage int `json:"gauge.response.queryUserPage"`
//GaugeResponseDisperseCase int `json:"gauge.response.disperseCase"`
//CounterStatus200SelectList int `json:"counter.status.200.selectList"`
//GaugeResponsePackageStatus int `json:"gauge.response.packageStatus"`
//CounterStatus200AddUserPhoneRemark int `json:"counter.status.200.addUserPhoneRemark"`
//GaugeResponseShowReport int `json:"gauge.response.showReport"`
//GaugeResponseQueryCasePage int `json:"gauge.response.queryCasePage"`
//CounterStatus200QueryUserPhoneRemarkList int `json:"counter.status.200.queryUserPhoneRemarkList"`
//CounterStatus200TechHealthCheck int `json:"counter.status.200.tech.health.check"`
//GaugeResponseLogin int `json:"gauge.response.login"`
//CounterStatus200RoleList int `json:"counter.status.200.roleList"`
//GaugeResponseLogout int `json:"gauge.response.logout"`
//GaugeResponseAgingList int `json:"gauge.response.agingList"`
//GaugeResponseRoleList int `json:"gauge.response.roleList"`
//GaugeResponseViewCaseDetail int `json:"gauge.response.viewCaseDetail"`
//GaugeResponseMenuTree int `json:"gauge.response.menuTree"`
//CounterStatus200QueryUserPage int `json:"counter.status.200.queryUserPage"`
//GaugeResponseFindCreditReport int `json:"gauge.response.findCreditReport"`
//GaugeResponseHaveUnCheckedApply int `json:"gauge.response.haveUnCheckedApply"`
//GaugeResponseQueryDisperseParam int `json:"gauge.response.queryDisperseParam"`
//GaugeResponseQueryCasePackPage int `json:"gauge.response.queryCasePackPage"`
//CounterStatus200FundingList int `json:"counter.status.200.fundingList"`
//CounterStatus200PackageStatus int `json:"counter.status.200.packageStatus"`
//GaugeResponseRemoveCallRecord int `json:"gauge.response.removeCallRecord"`
//CounterStatus200QueryOrganizationList int `json:"counter.status.200.queryOrganizationList"`
HttpsessionsMax
int
`json:"httpsessions.max"`
HttpsessionsActive
int
`json:"httpsessions.active"`
}
}
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