Skip to content

Commit

Permalink
Merge branch 'release/0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schmitz committed Jun 26, 2019
2 parents b3ae2c1 + 70af370 commit 20442f6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
zookeeper_exporter
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ usage: zookeeper_exporter --zk.hosts=ZK.HOSTS [<flags>]
A zookeeper metrics exporter for prometheus, with zk_version and leaderServes=no support.
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--web.listen-address="0.0.0.0:9898"
Address on which to expose metrics
--zk.hosts=ZK.HOSTS list of ip:port of ZK hosts, comma separated
--zk.poll-interval=30 How often to poll the ZK servers
--zk.connect-timeout=5 Timeout value for connecting to ZK
--zk.connect-rw-deadline=5
Socket deadline for read & write operations
--version Show application version.
Address on which to expose metrics
--zk.hosts=ZK.HOSTS list of ip:port of ZK hosts, comma separated
--metrics.namespace="zookeeper__"
string to prepend to all metric names
--zk.poll-interval=30 How often to poll the ZK servers
--zk.connect-timeout=4 Timeout value for opening socket to ZK
--zk.connect-deadline=3 Connection deadline for read & write operations
--version Show application version.
$ zookeeper_exporter --zk.hosts=10.0.0.9:2181,10.0.0.10:2181
~~~
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.9
0.1
17 changes: 11 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ var (
"list of ip:port of ZK hosts, comma separated",
).Required().String()

metricsNamespace = app.Flag(
"metrics.namespace",
"string to prepend to all metric names",
).Default("zookeeper__").String()

pollInterval = app.Flag(
"zk.poll-interval",
"How often to poll the ZK servers",
).Default("30").Int()

zkTimeout = app.Flag(
"zk.connect-timeout",
"Timeout value for connecting to ZK",
).Default("5").Int()
"Timeout value for opening socket to ZK",
).Default("4").Int()

zkRWDeadLine = app.Flag(
"zk.connect-rw-deadline",
"Socket deadline for read & write operations",
).Default("5").Int()
"zk.connect-deadline",
"Connection deadline for read & write operations",
).Default("3").Float()

log = logrus.New()
)
Expand Down Expand Up @@ -82,7 +87,7 @@ func main() {
// Create new metrics interface
metrics := newMetrics()

// Start an export thread per server
// Start one poller per server
for _, ipport := range zkHosts {
p := newPoller(intervalDuration, *metrics, *newZKServer(ipport))
go p.pollForMetrics()
Expand Down
5 changes: 1 addition & 4 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const (
follower serverState = 1
leader serverState = 2
standalone serverState = 3

// metric namespace - prepended to all metric names
namespace = "zookeeper__"
)

type zkMetrics struct {
Expand Down Expand Up @@ -75,7 +72,7 @@ func getState(s string) serverState {

// prepends the namespace in front of all metric names
func prependNamespace(rawMetricName string) string {
return namespace + rawMetricName
return *metricsNamespace + rawMetricName
}

// Creates a map of all known metrics exposed by zookeeper's mntr command
Expand Down
11 changes: 6 additions & 5 deletions zk_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
monitorCMD = "mntr"
okCMD = "ruok"
enviCMD = "envi"
enviCMD = "envi" // Might use this in the future?
)

// zkServer object
Expand Down Expand Up @@ -73,7 +73,8 @@ func (zk *zkServer) getOKStatus() (string, error) {
}

func (zk *zkServer) sendCommand(cmd string) ([]byte, error) {
conn, err := net.Dial("tcp", zk.ipPort)
dialer := net.Dialer{Timeout: time.Duration(*zkTimeout) * time.Second}
conn, err := dialer.Dial("tcp", zk.ipPort)
if err != nil {
// log.Warnf("[%v] failed to dial zkServer: %v", zk.ipPort, err)
return []byte{}, err
Expand All @@ -85,12 +86,12 @@ func (zk *zkServer) sendCommand(cmd string) ([]byte, error) {
}()

// ensure these socket fail fast if ZK having problems
deadline := 3 * time.Second
RWDeadLine := time.Duration(*zkRWDeadLine) * time.Second

if err := conn.SetReadDeadline(time.Now().Add(deadline)); err != nil {
if err := conn.SetReadDeadline(time.Now().Add(RWDeadLine)); err != nil {
log.Errorf("[%v] failed to set Read Deadline on conn: %v", zk.ipPort, err)
}
if err := conn.SetWriteDeadline(time.Now().Add(deadline)); err != nil {
if err := conn.SetWriteDeadline(time.Now().Add(RWDeadLine)); err != nil {
log.Errorf("[%v] failed to set Write Deadline on conn: %v", zk.ipPort, err)
}

Expand Down

0 comments on commit 20442f6

Please sign in to comment.