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
a52d3596
Commit
a52d3596
authored
Apr 15, 2012
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging and naming cleanup
parent
e2cfa525
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
gostatsd.go
gostatsd.go
+11
-14
No files found.
gostatsd.go
View file @
a52d3596
...
...
@@ -56,17 +56,16 @@ func (m Metric) String() string {
}
func
main
()
{
var
metric
s
=
make
(
chan
Metric
)
go
metricListener
(
metric
s
)
go
metricAggregator
(
metric
s
)
var
metric
Chan
=
make
(
chan
Metric
)
go
metricListener
(
metric
Chan
)
go
metricAggregator
(
metric
Chan
)
// Run forever
select
{}
}
func
metricListener
(
metric
s
chan
Metric
)
{
func
metricListener
(
metric
Chan
chan
Metric
)
{
conn
,
err
:=
net
.
ListenPacket
(
"udp"
,
":8125"
)
if
err
!=
nil
{
// Do something about it
log
.
Fatal
(
err
)
return
}
...
...
@@ -74,10 +73,10 @@ func metricListener(metrics chan Metric) {
for
{
nbytes
,
_
,
err
:=
conn
.
ReadFrom
(
msg
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Printf
(
"%s"
,
err
)
continue
}
go
handleMessage
(
metric
s
,
string
(
msg
[
:
nbytes
]))
go
handleMessage
(
metric
Chan
,
string
(
msg
[
:
nbytes
]))
}
}
...
...
@@ -157,7 +156,7 @@ func flushMetrics(counters MetricMap, gauges MetricMap, timers MetricListMap, fl
}
func
metricAggregator
(
metric
s
chan
Metric
)
{
func
metricAggregator
(
metric
Chan
chan
Metric
)
{
var
counters
=
make
(
MetricMap
)
var
gauges
=
make
(
MetricMap
)
var
timers
=
make
(
MetricListMap
)
...
...
@@ -168,8 +167,7 @@ func metricAggregator(metrics chan Metric) {
for
{
select
{
case
metric
:=
<-
metrics
:
log
.
Printf
(
"Got %s"
,
metric
)
case
metric
:=
<-
metricChan
:
// Incoming metrics
switch
metric
.
Type
{
case
COUNTER
:
v
,
ok
:=
counters
[
metric
.
Bucket
]
...
...
@@ -189,7 +187,7 @@ func metricAggregator(metrics chan Metric) {
timers
[
metric
.
Bucket
]
=
[]
float64
{
metric
.
Value
}
}
}
case
<-
flushTimer
.
C
:
case
<-
flushTimer
.
C
:
// Time to flush to graphite
go
flushMetrics
(
counters
,
gauges
,
timers
,
flushInterval
)
// Reset counters
...
...
@@ -288,14 +286,13 @@ func parseMessage(msg string) ([]Metric, error) {
return
metricList
,
nil
}
func
handleMessage
(
metric
_c
han
chan
Metric
,
msg
string
)
{
func
handleMessage
(
metric
C
han
chan
Metric
,
msg
string
)
{
metrics
,
err
:=
parseMessage
(
msg
)
if
err
!=
nil
{
log
.
Printf
(
"Error parsing metric %s"
,
err
)
}
else
{
for
_
,
metric
:=
range
metrics
{
log
.
Printf
(
"%s"
,
metric
)
metric_chan
<-
metric
metricChan
<-
metric
}
}
}
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