Skip to content

Commit

Permalink
Allow connecting to multiple gearmand servers and combining the resul…
Browse files Browse the repository at this point in the history
…ting status lines
  • Loading branch information
nickpeirson committed Aug 11, 2015
1 parent 50e2267 commit e21a672
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.externalToolBuilders
/.DS_Store
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ Usage of gearman_gtop:
-all=false: Show all queues, even if the have no workers or jobs
-filterExclude="": Exclude queues containing this string. Can provide multiple separated by commas.
-filterInclude="": Include queues containing this string. Can provide multiple separated by commas.
-h="localhost": Gearmand host to connect to (shorthand)
-host="localhost": Gearmand host to connect to
-h="localhost:4730": Gearmand host to connect to. Specify multiple separated by ';' (shorthand)
-host="localhost:4730": Gearmand host to connect to. Specify multiple separated by ';'
-l=false: Log debug to /tmp/gearman_gtop.log (shorthand)
-log=false: Log debug to /tmp/gearman_gtop.log
-p="4730": Gearmand port to connect to (shorthand)
-port="4730": Gearmand port to connect to
-sort="1": Index of the column to sort by
```
### Runtime
Expand Down
39 changes: 27 additions & 12 deletions gearman_gtop.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ func init() {
allUsage := "Show all queues, even if the have no workers or jobs"
flag.BoolVar(&showAll, "all", allDefault, allUsage)
flag.BoolVar(&showAll, "a", allDefault, allUsage+" (shorthand)")
hostDefault := "localhost"
hostUsage := "Gearmand host to connect to"
hostDefault := "localhost:4730"
hostUsage := "Gearmand host to connect to. Specify multiple separated by ';'"
flag.StringVar(&gearmanHost, "host", hostDefault, hostUsage)
flag.StringVar(&gearmanHost, "h", hostDefault, hostUsage+" (shorthand)")
portDefault := "4730"
portUsage := "Gearmand port to connect to"
flag.StringVar(&gearmanPort, "port", portDefault, portUsage)
flag.StringVar(&gearmanPort, "p", portDefault, portUsage+" (shorthand)")
flag.StringVar(&initialSortIndex, "sort", "1", "Index of the column to sort by")
flag.StringVar(&queueNameInclude, "filterInclude", "", "Include queues containing this string. Can provide multiple separated by commas.")
flag.StringVar(&queueNameExclude, "filterExclude", "", "Exclude queues containing this string. Can provide multiple separated by commas.")
Expand Down Expand Up @@ -151,16 +147,35 @@ func handleEvents() {

func (d *display) updateLines() {
log.Println("Connecting to gearman")
gearadminClient := gearadmin.New(gearmanHost, gearmanPort)
defer gearadminClient.Close()
connectionDetails := strings.Split(gearmanHost, ";")
var clients []gearadmin.Client
for _, connectionDetail := range connectionDetails {
splitConnectionDetail := strings.Split(connectionDetail, ":")
if len(splitConnectionDetail) > 2 {
fatal("Invalid connection string: " + connectionDetail)
return
}
host := splitConnectionDetail[0]
port := "4730"
if len(splitConnectionDetail) == 2 {
port = splitConnectionDetail[1]
}
gearadminClient := gearadmin.New(host, port)
defer gearadminClient.Close()
clients = append(clients, gearadminClient)
}
responseFilter := statusFilter(initialiseFilters())
for {
log.Println("Getting status")
start := time.Now()
statusLines, err := gearadminClient.StatusFiltered(responseFilter)
if err != nil {
fatal("Couldn't get gearman status from " + gearmanHost + ":" + gearmanPort + " (Error: " + err.Error() + ")")
return
statusLines := gearadmin.StatusLines{}
for _, client := range clients {
newStatusLines, err := client.StatusFiltered(responseFilter)
if err != nil {
fatal("Couldn't get gearman status from " + client.ConnectionString() + " (Error: " + err.Error() + ")")
return
}
statusLines = statusLines.Merge(newStatusLines)
}
d.statusLines = statusLines
d.sortLines()
Expand Down

0 comments on commit e21a672

Please sign in to comment.