-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5406 from ethereum-optimism/jg/metrics_docs
op-node/doc: Document op-batcher & op-proposer metrics
- Loading branch information
Showing
10 changed files
with
183 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package doc | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ethereum-optimism/optimism/op-batcher/metrics" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var Subcommands = cli.Commands{ | ||
{ | ||
Name: "metrics", | ||
Usage: "Dumps a list of supported metrics to stdout", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "format", | ||
Value: "markdown", | ||
Usage: "Output format (json|markdown)", | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
m := metrics.NewMetrics("default") | ||
supportedMetrics := m.Document() | ||
format := ctx.String("format") | ||
|
||
if format != "markdown" && format != "json" { | ||
return fmt.Errorf("invalid format: %s", format) | ||
} | ||
|
||
if format == "json" { | ||
enc := json.NewEncoder(os.Stdout) | ||
return enc.Encode(supportedMetrics) | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) | ||
table.SetCenterSeparator("|") | ||
table.SetAutoWrapText(false) | ||
table.SetHeader([]string{"Metric", "Description", "Labels", "Type"}) | ||
var data [][]string | ||
for _, metric := range supportedMetrics { | ||
labels := strings.Join(metric.Labels, ",") | ||
data = append(data, []string{metric.Name, metric.Help, labels, metric.Type}) | ||
} | ||
table.AppendBulk(data) | ||
table.Render() | ||
return nil | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package doc | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ethereum-optimism/optimism/op-proposer/metrics" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var Subcommands = cli.Commands{ | ||
{ | ||
Name: "metrics", | ||
Usage: "Dumps a list of supported metrics to stdout", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "format", | ||
Value: "markdown", | ||
Usage: "Output format (json|markdown)", | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
m := metrics.NewMetrics("default") | ||
supportedMetrics := m.Document() | ||
format := ctx.String("format") | ||
|
||
if format != "markdown" && format != "json" { | ||
return fmt.Errorf("invalid format: %s", format) | ||
} | ||
|
||
if format == "json" { | ||
enc := json.NewEncoder(os.Stdout) | ||
return enc.Encode(supportedMetrics) | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) | ||
table.SetCenterSeparator("|") | ||
table.SetAutoWrapText(false) | ||
table.SetHeader([]string{"Metric", "Description", "Labels", "Type"}) | ||
var data [][]string | ||
for _, metric := range supportedMetrics { | ||
labels := strings.Join(metric.Labels, ",") | ||
data = append(data, []string{metric.Name, metric.Help, labels, metric.Type}) | ||
} | ||
table.AppendBulk(data) | ||
table.Render() | ||
return nil | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters