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
43a9d969
Commit
43a9d969
authored
Feb 14, 2019
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更换为UDP, 批量1000个写入一次
parent
e9abe7b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
18 deletions
+32
-18
influxdb_conf.go
service/conf/influxdb_conf.go
+3
-3
msg_process.go
service/msg_process.go
+29
-15
No files found.
service/conf/influxdb_conf.go
View file @
43a9d969
...
...
@@ -7,11 +7,11 @@ import (
func
NewClient
()
client
.
Client
{
conf
:=
client
.
HTT
PConfig
{
Addr
:
"
http://172.20.6.29:8086
"
,
conf
:=
client
.
UD
PConfig
{
Addr
:
"
172.20.6.29:8089
"
,
}
con
,
err
:=
client
.
New
HTT
PClient
(
conf
)
con
,
err
:=
client
.
New
UD
PClient
(
conf
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
service/msg_process.go
View file @
43a9d969
...
...
@@ -26,16 +26,9 @@ func MsgProcess(msg string) {
msgInfluxProcess
(
traceMsg
)
}
func
msgInfluxProcess
(
traceMsgs
[]
TraceMsg
)
{
c
:=
conf
.
NewClient
()
defer
func
()
{
_
=
c
.
Close
()
}()
var
pointSlice
=
make
([]
*
client
.
Point
,
0
,
1000
)
points
,
err
:=
client
.
NewBatchPoints
(
client
.
BatchPointsConfig
{
Database
:
"monitor"
,
})
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
func
msgInfluxProcess
(
traceMsgs
[]
TraceMsg
)
{
for
_
,
traceMsg
:=
range
traceMsgs
{
if
traceMsg
.
Kind
!=
"SERVER"
{
...
...
@@ -47,21 +40,18 @@ func msgInfluxProcess(traceMsgs []TraceMsg) {
path
=
traceMsg
.
Tags
.
HttpMethod
+
" "
+
traceMsg
.
Tags
.
HttpPath
}
//fmt.Println("搞起" ,traceMsg.TraceId)
sysName
:=
traceMsg
.
LocalEndpoint
.
ServiceName
fields
:=
make
(
map
[
string
]
interface
{})
fields
[
"duration"
]
=
traceMsg
.
Duration
/
1000
fields
[
"traceId"
]
=
traceMsg
.
TraceId
tags
:=
make
(
map
[
string
]
string
,)
tags
:=
make
(
map
[
string
]
string
,
)
tags
[
"sys_name"
]
=
sysName
tags
[
"path"
]
=
path
tags
[
"host"
]
=
traceMsg
.
LocalEndpoint
.
Ipv4
tags
[
"kind"
]
=
traceMsg
.
Kind
tags
[
"duration_tag"
]
=
strconv
.
Itoa
(
traceMsg
.
Duration
)
bytes
,
err
:=
json
.
Marshal
(
traceMsg
)
msg
:=
string
(
bytes
)
...
...
@@ -74,9 +64,14 @@ func msgInfluxProcess(traceMsgs []TraceMsg) {
unix
:=
time
.
Unix
(
0
,
traceMsg
.
Timestamp
*
1000
)
if
len
(
pointSlice
)
==
1000
{
go
batchWrite
(
pointSlice
)
pointSlice
=
make
([]
*
client
.
Point
,
0
)
}
point
,
_
:=
client
.
NewPoint
(
"trace_info"
,
tags
,
fields
,
unix
)
point
s
.
AddPoint
(
point
)
err
=
c
.
Write
(
points
)
point
Slice
=
append
(
pointSlice
,
point
)
if
err
!=
nil
{
log
.
Fatal
(
err
,
msg
)
}
...
...
@@ -84,6 +79,25 @@ func msgInfluxProcess(traceMsgs []TraceMsg) {
}
func
batchWrite
(
pointArray
[]
*
client
.
Point
)
{
c
:=
conf
.
NewClient
()
defer
func
()
{
_
=
c
.
Close
()
}()
points
,
err
:=
client
.
NewBatchPoints
(
client
.
BatchPointsConfig
{
Database
:
"monitor"
,
})
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
points
.
AddPoints
(
pointArray
)
err
=
c
.
Write
(
points
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
func
msgRedisProcess
(
traceMsg
[]
TraceMsg
)
{
conn
:=
conf
.
Pool
.
Get
()
defer
func
()
{
_
=
conn
.
Close
()
}()
...
...
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