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
06921718
Commit
06921718
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
make the GraphiteClient reconnect on error
parent
1d3ac345
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gostatsd/gostatsd.go
+2
-1
2 additions, 1 deletion
gostatsd/gostatsd.go
statsd/graphite.go
+23
-4
23 additions, 4 deletions
statsd/graphite.go
with
25 additions
and
5 deletions
gostatsd/gostatsd.go
+
2
−
1
View file @
06921718
...
...
@@ -2,9 +2,10 @@ package main
import
(
"flag"
"github.com/kisielk/gostatsd/statsd"
"log"
"time"
"git.autistici.org/ale/gostatsd/statsd"
)
const
(
...
...
This diff is collapsed.
Click to expand it.
statsd/graphite.go
+
23
−
4
View file @
06921718
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"net"
"regexp"
"sync"
"time"
)
...
...
@@ -24,19 +25,38 @@ func normalizeBucketName(name string) string {
// GraphiteClient is an object that is used to send messages to a Graphite server's UDP interface
type
GraphiteClient
struct
{
conn
*
net
.
Conn
addr
string
conn
net
.
Conn
lock
sync
.
Mutex
}
// SendMetrics sends the metrics in a MetricsMap to the Graphite server
func
(
client
*
GraphiteClient
)
SendMetrics
(
metrics
MetricMap
)
(
err
error
)
{
// Connect opportunistically.
client
.
lock
.
Lock
()
if
client
.
conn
==
nil
{
client
.
conn
,
err
=
net
.
Dial
(
"tcp"
,
client
.
addr
)
}
conn
:=
client
.
conn
client
.
lock
.
Unlock
()
if
err
!=
nil
{
return
err
}
buf
:=
new
(
bytes
.
Buffer
)
now
:=
time
.
Now
()
.
Unix
()
for
k
,
v
:=
range
metrics
{
nk
:=
normalizeBucketName
(
k
)
fmt
.
Fprintf
(
buf
,
"%s %f %d
\n
"
,
nk
,
v
,
now
)
}
_
,
err
=
buf
.
WriteTo
(
*
client
.
conn
)
_
,
err
=
buf
.
WriteTo
(
conn
)
if
err
!=
nil
{
conn
.
Close
()
client
.
lock
.
Lock
()
if
client
.
conn
==
conn
{
client
.
conn
=
nil
}
client
.
lock
.
Unlock
()
return
err
}
return
nil
...
...
@@ -44,7 +64,6 @@ func (client *GraphiteClient) SendMetrics(metrics MetricMap) (err error) {
// NewGraphiteClient constructs a GraphiteClient object by connecting to an address
func
NewGraphiteClient
(
addr
string
)
(
client
GraphiteClient
,
err
error
)
{
conn
,
err
:=
net
.
Dial
(
"tcp"
,
addr
)
client
=
GraphiteClient
{
&
conn
}
client
=
GraphiteClient
{
addr
:
addr
}
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