Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
gostatsd
Commits
7abcd625
Commit
7abcd625
authored
Jul 27, 2012
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up console code, fixed bugs with empty command
parent
be0aab99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
statsd/console.go
statsd/console.go
+20
-9
No files found.
statsd/console.go
View file @
7abcd625
...
...
@@ -44,17 +44,29 @@ type consoleConn struct {
}
func
(
c
*
consoleConn
)
serve
()
{
defer
c
.
conn
.
Close
()
buf
:=
make
([]
byte
,
1024
)
for
{
c
.
conn
.
Write
([]
byte
(
"console> "
))
nbytes
,
err
:=
c
.
conn
.
Read
(
buf
)
if
err
!=
nil
{
// Connection has likely closed
return
}
var
command
string
var
args
[]
string
var
result
string
switch
parts
:=
strings
.
Fields
(
string
(
buf
[
:
nbytes
]));
parts
[
0
]
{
if
parts
:=
strings
.
Fields
(
string
(
buf
[
:
nbytes
]));
len
(
parts
)
>
0
{
command
=
parts
[
0
]
if
len
(
parts
)
>
1
{
args
=
parts
[
1
:
]
}
}
switch
command
{
case
"help"
:
result
=
"Commands: stats, counters, timers, gauges, delcounters, deltimers, delgauges, quit
\n
"
case
"stats"
:
...
...
@@ -83,32 +95,31 @@ func (c *consoleConn) serve() {
c
.
server
.
Aggregator
.
Unlock
()
case
"delcounters"
:
c
.
server
.
Aggregator
.
Lock
()
for
_
,
k
:=
range
p
ar
ts
[
1
:
]
{
for
_
,
k
:=
range
ar
gs
{
delete
(
c
.
server
.
Aggregator
.
counters
,
k
)
}
c
.
server
.
Aggregator
.
Unlock
()
case
"deltimers"
:
c
.
server
.
Aggregator
.
Lock
()
for
_
,
k
:=
range
p
ar
ts
[
1
:
]
{
for
_
,
k
:=
range
ar
gs
{
delete
(
c
.
server
.
Aggregator
.
timers
,
k
)
}
c
.
server
.
Aggregator
.
Unlock
()
case
"delgauges"
:
c
.
server
.
Aggregator
.
Lock
()
for
_
,
k
:=
range
p
ar
ts
[
1
:
]
{
for
_
,
k
:=
range
ar
gs
{
delete
(
c
.
server
.
Aggregator
.
gauges
,
k
)
}
c
.
server
.
Aggregator
.
Unlock
()
case
"quit"
:
result
=
"
quit
"
result
=
"
goodbye
\n
"
default
:
result
=
fmt
.
Sprintf
(
"unknown command: %s
\n
"
,
parts
[
0
]
)
result
=
fmt
.
Sprintf
(
"unknown command: %s
\n
"
,
command
)
}
if
result
==
"quit"
{
c
.
conn
.
Write
([]
byte
(
result
))
if
result
==
"goodbye
\n
"
{
return
}
else
{
c
.
conn
.
Write
([]
byte
(
result
))
}
}
}
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