Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gostatsd
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ale
gostatsd
Commits
bb699a08
Commit
bb699a08
authored
Jul 27, 2012
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documented the stuff in receiver.go
parent
af1815e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
example/example.go
example/example.go
+1
-1
statsd/receiver.go
statsd/receiver.go
+21
-2
statsd/server.go
statsd/server.go
+1
-1
No files found.
example/example.go
View file @
bb699a08
...
...
@@ -9,6 +9,6 @@ func main() {
f
:=
func
(
m
statsd
.
Metric
)
{
log
.
Printf
(
"%s"
,
m
)
}
r
:=
statsd
.
MetricReceiver
{
":8125"
,
f
}
r
:=
statsd
.
MetricReceiver
{
":8125"
,
HanlderFunc
(
f
)
}
r
.
ListenAndReceive
()
}
statsd/receiver.go
View file @
bb699a08
...
...
@@ -5,15 +5,31 @@ import (
"net"
)
// DefaultMetricsAddr is the default address on which a MetricReceiver will listen
const
DefaultMetricsAddr
=
":8125"
type
Handler
func
(
Metric
)
// Objects implementing the Handler interface can be used to handle metrics for a MetricReceiver
type
Handler
interface
{
HandleMetric
(
m
Metric
)
}
// The HandlerFunc type is an adapter to allow the use of ordinary functions as metric handlers
type
HandlerFunc
func
(
Metric
)
// HandleMetric calls f(m)
func
(
f
HandlerFunc
)
HandleMetric
(
m
Metric
)
{
f
(
m
)
}
// MetricReceiver receives data on its listening port and converts lines in to Metrics.
// For each Metric it calls r.Handler.HandleMetric()
type
MetricReceiver
struct
{
Addr
string
// UDP address on which to listen for metrics
Handler
Handler
// handler to invoke
}
// ListenAndReceive listens on the UDP network address of srv.Addr and then calls
// Receive to handle the incoming datagrams. If Addr is blank then DefaultMetricsAddr is used.
func
(
r
*
MetricReceiver
)
ListenAndReceive
()
error
{
addr
:=
r
.
Addr
if
addr
==
""
{
...
...
@@ -26,6 +42,8 @@ func (r *MetricReceiver) ListenAndReceive() error {
return
r
.
Receive
(
c
)
}
// Receive accepts incoming datagrams on c and calls r.Handler.HandleMetric() for each line in the
// datagram that successfully parses in to a Metric
func
(
r
*
MetricReceiver
)
Receive
(
c
net
.
PacketConn
)
error
{
defer
c
.
Close
()
...
...
@@ -42,12 +60,13 @@ func (r *MetricReceiver) Receive(c net.PacketConn) error {
panic
(
"not reached"
)
}
// handleMessage handles the contents of a datagram and attempts to parse a Metric from each line
func
(
srv
*
MetricReceiver
)
handleMessage
(
msg
[]
byte
)
{
metrics
,
err
:=
parseMessage
(
string
(
msg
))
if
err
!=
nil
{
log
.
Printf
(
"Error parsing metric %s"
,
err
)
}
for
_
,
metric
:=
range
metrics
{
srv
.
Handler
(
metric
)
srv
.
Handler
.
HandleMetric
(
metric
)
}
}
statsd/server.go
View file @
bb699a08
...
...
@@ -429,7 +429,7 @@ func ListenAndServe(metricAddr string, consoleAddr string, graphiteAddr string,
f
:=
func
(
metric
Metric
)
{
metricChan
<-
metric
}
s
:=
MetricReceiver
{
metricAddr
,
f
}
s
:=
MetricReceiver
{
metricAddr
,
HandlerFunc
(
f
)
}
go
s
.
ListenAndReceive
()
go
metricAggregator
(
graphiteAddr
,
metricChan
,
consoleChan
,
flushInterval
)
...
...
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