summaryrefslogtreecommitdiff
path: root/bookpipeline/cmd/lspipeline/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-09-24 18:39:21 +0100
committerNick White <git@njw.name>2019-09-24 18:39:21 +0100
commit46dae3fb7d431aa95ae645b97d60c1fb1d6e9daa (patch)
tree552318e0073a688d773b6702cdae33672116ae13 /bookpipeline/cmd/lspipeline/main.go
parent7ae391451e8245f6b51758b48f924e51b68c15fa (diff)
Do ssh log collection concurrently
Diffstat (limited to 'bookpipeline/cmd/lspipeline/main.go')
-rw-r--r--bookpipeline/cmd/lspipeline/main.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/bookpipeline/cmd/lspipeline/main.go b/bookpipeline/cmd/lspipeline/main.go
index 9fb7a78..4a131b4 100644
--- a/bookpipeline/cmd/lspipeline/main.go
+++ b/bookpipeline/cmd/lspipeline/main.go
@@ -160,6 +160,18 @@ func getRecentSSHLogs(ip string, id string, n int) (string, error) {
return string(out), nil
}
+func getRecentSSHLogsChan(ips []string, id string, lognum int, logs chan string) {
+ for _, ip := range ips {
+ sshlog, err := getRecentSSHLogs(ip, id, lognum)
+ if err != nil {
+ log.Printf("Error getting SSH logs for %s: %s\n", ip, err)
+ continue
+ }
+ logs <- fmt.Sprintf("%s\n%s", ip, sshlog)
+ }
+ close(logs)
+}
+
func main() {
keyfile := flag.String("i", "", "private key file for SSH")
lognum := flag.Int("n", 5, "number of lines to include in SSH logs")
@@ -184,6 +196,7 @@ func main() {
queues := make(chan queueDetails)
inprogress := make(chan string, 100)
done := make(chan string, 100)
+ logs := make(chan string, 10)
go getInstances(conn, instances)
go getQueueDetails(conn, queues)
@@ -207,6 +220,8 @@ func main() {
fmt.Printf("\n")
}
+ go getRecentSSHLogsChan(ips, *keyfile, *lognum, logs)
+
fmt.Println("\n# Queues")
for i := range queues {
fmt.Printf("%s: %s available, %s in progress\n", i.name, i.numAvailable, i.numInProgress)
@@ -224,13 +239,8 @@ func main() {
if len(ips) > 0 {
fmt.Println("\n# Recent logs")
- for _, ip := range ips {
- logs, err := getRecentSSHLogs(ip, *keyfile, *lognum)
- if err != nil {
- log.Printf("Error running ssh for %s: %v\n", ip, err)
- continue
- }
- fmt.Printf("\n%s\n%s\n", ip, logs)
+ for i := range logs {
+ fmt.Printf("\n%s", i)
}
}
}