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
a5e9bebf
Commit
a5e9bebf
authored
Jul 27, 2012
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the flush interval configurable
parent
0118f614
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
22 deletions
+22
-22
gostatsd/gostatsd.go
gostatsd/gostatsd.go
+11
-7
statsd/server.go
statsd/server.go
+11
-15
No files found.
gostatsd/gostatsd.go
View file @
a5e9bebf
...
...
@@ -4,28 +4,32 @@ import (
"flag"
"github.com/kisielk/gostatsd/statsd"
"log"
"time"
)
var
(
metricsAddr
string
consoleAddr
string
graphiteAddr
string
metricsAddr
string
consoleAddr
string
graphiteAddr
string
flushInterval
time
.
Duration
)
func
init
()
{
const
(
defaultMetricsAddr
=
":8125"
defaultConsoleAddr
=
":8126"
defaultGraphiteAddr
=
"localhost:2003"
defaultMetricsAddr
=
":8125"
defaultConsoleAddr
=
":8126"
defaultGraphiteAddr
=
"localhost:2003"
defaultFlushInterval
=
10
*
time
.
Second
)
flag
.
StringVar
(
&
metricsAddr
,
"l"
,
defaultMetricsAddr
,
"Address on which to listen for metrics"
)
flag
.
StringVar
(
&
consoleAddr
,
"c"
,
defaultConsoleAddr
,
"Address on which to listen for console sessions"
)
flag
.
StringVar
(
&
graphiteAddr
,
"g"
,
defaultGraphiteAddr
,
"Address of the graphite server"
)
flag
.
DurationVar
(
&
flushInterval
,
"f"
,
defaultFlushInterval
,
"How often to flush metrics to the graphite server"
)
}
func
main
()
{
flag
.
Parse
()
err
:=
statsd
.
ListenAndServe
(
metricsAddr
,
consoleAddr
,
graphiteAddr
)
err
:=
statsd
.
ListenAndServe
(
metricsAddr
,
consoleAddr
,
graphiteAddr
,
flushInterval
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
statsd/server.go
View file @
a5e9bebf
...
...
@@ -20,12 +20,10 @@ var (
regInvalid
=
regexp
.
MustCompile
(
"[^a-zA-Z_
\\
-0-9
\\
.]"
)
)
var
flushInterval
time
.
Duration
var
graphiteServer
string
var
percentThresholds
[]
float64
func
init
()
{
flushInterval
=
10
*
time
.
Second
percentThresholds
=
[]
float64
{
90.0
}
}
...
...
@@ -72,7 +70,6 @@ func (m Metric) String() string {
type
MetricMap
map
[
string
]
float64
type
MetricListMap
map
[
string
][]
float64
type
GraphiteClient
struct
{
conn
*
net
.
Conn
}
...
...
@@ -158,13 +155,13 @@ func aggregateMetrics(counters MetricMap, gauges MetricMap, timers MetricListMap
for
k
,
v
:=
range
counters
{
perSecond
:=
v
/
flushInterval
.
Seconds
()
metrics
[
"stats."
+
k
]
=
perSecond
metrics
[
"stats_counts."
+
k
]
=
v
metrics
[
"stats."
+
k
]
=
perSecond
metrics
[
"stats_counts."
+
k
]
=
v
numStats
+=
1
}
for
k
,
v
:=
range
gauges
{
metrics
[
"stats.gauges."
+
k
]
=
v
metrics
[
"stats.gauges."
+
k
]
=
v
numStats
+=
1
}
...
...
@@ -174,15 +171,15 @@ func aggregateMetrics(counters MetricMap, gauges MetricMap, timers MetricListMap
min
:=
v
[
0
]
max
:=
v
[
count
-
1
]
metrics
[
"stats.timers."
+
k
+
".lower"
]
=
min
metrics
[
"stats.timers."
+
k
+
".upper"
]
=
max
metrics
[
"stats.timers."
+
k
+
".count"
]
=
float64
(
count
)
metrics
[
"stats.timers."
+
k
+
".lower"
]
=
min
metrics
[
"stats.timers."
+
k
+
".upper"
]
=
max
metrics
[
"stats.timers."
+
k
+
".count"
]
=
float64
(
count
)
for
_
,
threshold
:=
range
percentThresholds
{
mean
,
upper
:=
thresholdStats
(
v
,
threshold
)
thresholdName
:=
strconv
.
FormatFloat
(
threshold
,
'f'
,
1
,
64
)
metrics
[
"stats.timers."
+
k
+
"mean_"
+
thresholdName
]
=
mean
metrics
[
"stats.timers."
+
k
+
"upper_"
+
thresholdName
]
=
upper
metrics
[
"stats.timers."
+
k
+
"mean_"
+
thresholdName
]
=
mean
metrics
[
"stats.timers."
+
k
+
"upper_"
+
thresholdName
]
=
upper
}
numStats
+=
1
}
...
...
@@ -191,7 +188,7 @@ func aggregateMetrics(counters MetricMap, gauges MetricMap, timers MetricListMap
return
metrics
}
func
metricAggregator
(
graphiteAddr
string
,
metricChan
chan
Metric
,
consoleChan
chan
ConsoleRequest
)
(
err
error
)
{
func
metricAggregator
(
graphiteAddr
string
,
metricChan
chan
Metric
,
consoleChan
chan
ConsoleRequest
,
flushInterval
time
.
Duration
)
(
err
error
)
{
graphite
,
err
:=
NewGraphiteClient
(
graphiteAddr
)
if
err
!=
nil
{
return
...
...
@@ -307,7 +304,6 @@ func metricAggregator(graphiteAddr string, metricChan chan Metric, consoleChan c
return
}
// Normalize a bucket name by replacing or translating invalid characters
func
normalizeBucketName
(
name
string
)
string
{
nospaces
:=
regSpaces
.
ReplaceAllString
(
name
,
"_"
)
...
...
@@ -444,11 +440,11 @@ func consoleServer(addr string, consoleChan chan ConsoleRequest) {
}
}
func
ListenAndServe
(
metricAddr
string
,
consoleAddr
string
,
graphiteAddr
string
)
error
{
func
ListenAndServe
(
metricAddr
string
,
consoleAddr
string
,
graphiteAddr
string
,
flushInterval
time
.
Duration
)
error
{
var
metricChan
=
make
(
chan
Metric
)
var
consoleChan
=
make
(
chan
ConsoleRequest
)
go
metricListener
(
metricAddr
,
metricChan
)
go
metricAggregator
(
graphiteAddr
,
metricChan
,
consoleChan
)
go
metricAggregator
(
graphiteAddr
,
metricChan
,
consoleChan
,
flushInterval
)
go
consoleServer
(
consoleAddr
,
consoleChan
)
// Run forever
select
{}
...
...
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