Skip to content

Commit e330d0a

Browse files
authored
Add fly dashboard metrics -g command to open metrics in browser directly (#4696)
* feat: add command to see app metrics directly * feat: undo changes to metrics command * feat: add new -g flag to existing command
1 parent 9ffd614 commit e330d0a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/command/dashboard/root.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/superfly/flyctl/internal/appconfig"
1010
"github.com/superfly/flyctl/internal/command"
1111
"github.com/superfly/flyctl/internal/flag"
12+
"github.com/superfly/flyctl/internal/flyutil"
1213
"github.com/superfly/flyctl/iostreams"
1314
)
1415

@@ -44,6 +45,12 @@ func newDashboardMetrics() *cobra.Command {
4445
flag.Add(cmd,
4546
flag.App(),
4647
flag.AppConfig(),
48+
flag.Bool{
49+
Name: "grafana",
50+
Shorthand: "g",
51+
Description: "Open Grafana metrics dashboard directly",
52+
Default: false,
53+
},
4754
)
4855
return cmd
4956
}
@@ -55,6 +62,18 @@ func runDashboard(ctx context.Context) error {
5562

5663
func runDashboardMetrics(ctx context.Context) error {
5764
appName := appconfig.NameFromContext(ctx)
65+
66+
if flag.GetBool(ctx, "grafana") {
67+
client := flyutil.ClientFromContext(ctx)
68+
app, err := client.GetAppBasic(ctx, appName)
69+
if err != nil {
70+
return fmt.Errorf("failed to get app info: %w", err)
71+
}
72+
73+
url := fmt.Sprintf("https://fly-metrics.net/d/fly-app/fly-app?orgId=%s&var-app=%s", app.Organization.InternalNumericID, appName)
74+
return runDashboardOpen(ctx, url)
75+
}
76+
5877
return runDashboardOpen(ctx, "https://fly.io/apps/"+appName+"/metrics")
5978
}
6079

0 commit comments

Comments
 (0)