Skip to content

Commit 45a5edb

Browse files
author
Tim Middleton
authored
Add --opens to start monitoring command to open the dashboard (#319)
1 parent 1d6c8b8 commit 45a5edb

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

pkg/cmd/monitoring.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
"path"
1919
"path/filepath"
2020
"regexp"
21+
"runtime"
2122
"strings"
23+
"time"
2224
)
2325

2426
const (
@@ -70,7 +72,8 @@ var (
7072
"prometheus.yaml",
7173
}
7274

73-
useDockerCompose bool
75+
useDockerComposeParam bool
76+
openHomePageParam bool
7477
)
7578

7679
// initMonitoringCmd represents the init monitoring command.
@@ -224,7 +227,24 @@ Prometheus using docker compose.`,
224227
grafanaURL := fmt.Sprintf("http://localhost:%v/d/coh-main/coherence-dashboard-main", grafanaPort)
225228
cmd.Printf("\nOpen the Grafana dashboard at %s, using admin/admin\n\n", grafanaURL)
226229

227-
return mon.dockerCommand([]string{"ps"})
230+
err = mon.dockerCommand([]string{"ps"})
231+
if err != nil {
232+
return err
233+
}
234+
235+
if openHomePageParam {
236+
time.Sleep(2 * time.Second)
237+
if runtime.GOOS == "darwin" {
238+
return exec.Command("open", grafanaURL).Run()
239+
}
240+
if isWindows() {
241+
return exec.Command("rundll32", "url.dll,FileProtocolHandler", grafanaURL).Run()
242+
}
243+
// Linux
244+
return exec.Command("xdg-open", grafanaURL).Run()
245+
}
246+
247+
return nil
228248
},
229249
}
230250

@@ -401,7 +421,7 @@ func (m *monitoring) dockerComposeCommand(args []string) error {
401421
finalArgs := args
402422
command := "docker"
403423

404-
if useDockerCompose {
424+
if useDockerComposeParam {
405425
command = dockerCompose
406426
} else {
407427
updatedArgs := []string{"compose"}
@@ -476,6 +496,7 @@ func streamOutput(r io.Reader, w io.Writer) {
476496
func init() {
477497
initMonitoringCmd.Flags().BoolVarP(&automaticallyConfirm, "yes", "y", false, confirmOptionMessage)
478498
stopMonitoringCmd.Flags().BoolVarP(&automaticallyConfirm, "yes", "y", false, confirmOptionMessage)
479-
stopMonitoringCmd.Flags().BoolVarP(&useDockerCompose, dockerCompose, "D", false, useDockerComposeMessage)
480-
startMonitoringCmd.Flags().BoolVarP(&useDockerCompose, dockerCompose, "D", false, useDockerComposeMessage)
499+
stopMonitoringCmd.Flags().BoolVarP(&useDockerComposeParam, dockerCompose, "D", false, useDockerComposeMessage)
500+
startMonitoringCmd.Flags().BoolVarP(&useDockerComposeParam, dockerCompose, "D", false, useDockerComposeMessage)
501+
startMonitoringCmd.Flags().BoolVarP(&openHomePageParam, "open", "O", false, "open the monitoring page after starting")
481502
}

0 commit comments

Comments
 (0)