This repository was archived by the owner on Feb 12, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathadmin_telnet.go
More file actions
110 lines (94 loc) · 4.5 KB
/
Copy pathadmin_telnet.go
File metadata and controls
110 lines (94 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"errors"
"github.com/graphite-ng/carbon-relay-ng/telnet"
"net"
"strings"
)
func max(a, b int) int {
if a > b {
return a
}
return b
}
func tcpViewHandler(req telnet.Req) (err error) {
if len(req.Command) != 1 {
return errors.New("extraneous arguments")
}
(*req.Conn).Write([]byte(table.Print() + "\n--\n"))
return
}
func tcpModHandler(req telnet.Req) (err error) {
err = applyCommand(table, strings.Join(req.Command, " "))
if err != nil {
return err
}
(*req.Conn).Write([]byte("ok\n"))
return
}
func tcpHelpHandler(req telnet.Req) (err error) {
writeHelp(*req.Conn, []byte(""))
return
}
func tcpDefaultHandler(req telnet.Req) (err error) {
writeHelp(*req.Conn, []byte("unknown command\n"))
return
}
func writeHelp(conn net.Conn, write_first []byte) { // bytes.Buffer
//write_first.WriteTo(conn)
conn.Write(write_first)
help := `
commands:
help show this menu
view view full current routing table
addBlack <prefix|sub|regex> <substring> blacklist (drops matching metrics as soon as they are received)
addAgg <func> <regex> <fmt> <interval> <wait> add a new aggregation rule.
<func>: aggregation function to use
sum
avg
<regex> regex to match incoming metrics. supports groups (numbered, see fmt)
<fmt> format of output metric. you can use $1, $2, etc to refer to numbered groups
<interval> align odd timestamps of metrics into buckets by this interval in seconds.
<wait> amount of seconds to wait for "late" metric messages before computing and flushing final result.
addRoute <type> <key> [opts] <dest> [<dest>[...]] add a new route. note 2 spaces to separate destinations
<type>:
sendAllMatch send metrics in the route to all destinations
sendFirstMatch send metrics in the route to the first one that matches it
consistentHashing distribute metrics between destinations using a hash algorithm
<opts>:
prefix=<str> only take in metrics that have this prefix
sub=<str> only take in metrics that match this substring
regex=<regex> only take in metrics that match this regex (expensive!)
<dest>: <addr> <opts>
<addr> a tcp endpoint. i.e. ip:port or hostname:port
<opts>:
prefix=<str> only take in metrics that have this prefix
sub=<str> only take in metrics that match this substring
regex=<regex> only take in metrics that match this regex (expensive!)
flush=<int> flush interval in ms
reconn=<int> reconnection interval in ms
pickle={true,false} pickle output format instead of the default text protocol
spool={true,false} enable spooling for this endpoint
addDest <routeKey> <dest> not implemented yet
modDest <routeKey> <dest> <opts>: modify dest by updating one or more space separated option strings
addr=<addr> new tcp address
prefix=<str> new matcher prefix
sub=<str> new matcher substring
regex=<regex> new matcher regex
modRoute <routeKey> <opts>: modify route by updating one or more space separated option strings
prefix=<str> new matcher prefix
sub=<str> new matcher substring
regex=<regex> new matcher regex
`
conn.Write([]byte(help))
}
func adminListener(addr string) error {
telnet.HandleFunc("add", tcpModHandler)
telnet.HandleFunc("del", tcpModHandler)
telnet.HandleFunc("mod", tcpModHandler)
telnet.HandleFunc("view", tcpViewHandler)
telnet.HandleFunc("help", tcpHelpHandler)
telnet.HandleFunc("", tcpDefaultHandler)
log.Notice("admin TCP listener starting on %v", addr)
return telnet.ListenAndServe(addr)
}