Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gostatsd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
gostatsd
Commits
1d3ac345
Commit
1d3ac345
authored
10 years ago
by
Kamil Kisiel
Browse files
Options
Downloads
Plain Diff
Merge pull request #2 from RangelReale/protocol-fix
* Allows lines not ending in \n, as it is not required by the protocol
parents
e770009a
802c36d5
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
statsd/aggregator.go
+8
-0
8 additions, 0 deletions
statsd/aggregator.go
statsd/receiver.go
+18
-10
18 additions, 10 deletions
statsd/receiver.go
with
26 additions
and
10 deletions
statsd/aggregator.go
+
8
−
0
View file @
1d3ac345
...
...
@@ -21,6 +21,14 @@ type MetricSender interface {
SendMetrics
(
MetricMap
)
error
}
// The MetricSenderFunc type is an adapter to allow the use of ordinary functions as metric senders
type
MetricSenderFunc
func
(
MetricMap
)
error
// SendMetrics calls f(m)
func
(
f
MetricSenderFunc
)
SendMetrics
(
m
MetricMap
)
error
{
return
f
(
m
)
}
// MetricAggregator is an object that aggregates statsd metrics.
// The function NewMetricAggregator should be used to create the objects.
//
...
...
This diff is collapsed.
Click to expand it.
statsd/receiver.go
+
18
−
10
View file @
1d3ac345
...
...
@@ -69,25 +69,33 @@ func (r *MetricReceiver) Receive(c net.PacketConn) error {
func
(
srv
*
MetricReceiver
)
handleMessage
(
addr
net
.
Addr
,
msg
[]
byte
)
{
buf
:=
bytes
.
NewBuffer
(
msg
)
for
{
line
,
err
:=
buf
.
ReadBytes
(
'\n'
)
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
log
.
Printf
(
"error reading message from %s: %s"
,
addr
,
err
)
line
,
readerr
:=
buf
.
ReadBytes
(
'\n'
)
// protocol does not require line to end in \n, if EOF use received line if valid
if
readerr
!=
nil
&&
readerr
!=
io
.
EOF
{
log
.
Printf
(
"error reading message from %s: %s"
,
addr
,
readerr
)
return
}
else
if
readerr
!=
io
.
EOF
{
// remove newline, only if not EOF
if
len
(
line
)
>
0
{
line
=
line
[
:
len
(
line
)
-
1
]
}
}
lineLength
:=
len
(
line
)
// Only process lines with more than one character
if
l
ineLength
>
1
{
metric
,
err
:=
parseLine
(
line
[
:
lineLength
-
1
]
)
if
l
en
(
line
)
>
1
{
metric
,
err
:=
parseLine
(
line
)
if
err
!=
nil
{
log
.
Print
ln
(
"error parsing line %q from %s: %s"
,
line
,
addr
,
err
)
log
.
Print
f
(
"error parsing line %q from %s: %s"
,
line
,
addr
,
err
)
continue
}
go
srv
.
Handler
.
HandleMetric
(
metric
)
}
if
readerr
==
io
.
EOF
{
// if was EOF, finished handling
return
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment