Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#62 add support for printing version via the long cli flag --version #68

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a0734a1
chore (.gitignore): ignore .vscode folder and any *.code-workspace files
dsidirop Feb 6, 2022
979f846
clean (toputils.go): consolidate 1024-related constants used in Psize…
dsidirop Feb 6, 2022
c235b19
clean (toputils.go): neutral cleanups in Psize() to make it more read…
dsidirop Feb 7, 2022
4de3db5
feat (cli flags): add new flag '-b' which causes all traffic to be pr…
dsidirop Feb 7, 2022
9721b8f
Merge pull request #1 from dsidirop/ksidirop/NTOP-0053-flag-to-displa…
dsidirop Feb 7, 2022
1e0be58
clean (Psize unit tests): refactor the test harness to have it employ…
dsidirop Feb 7, 2022
d2e1879
Merge pull request #2 from dsidirop/ksidirop/NTOP-0053-flag-to-displa…
dsidirop Feb 7, 2022
2f22922
clean (Psize unit tests): refactor the test harness to have it employ…
dsidirop Feb 7, 2022
884c494
Merge branch 'master' of https://github.com/dsidirop/nats-top into ks…
dsidirop Feb 7, 2022
c0c8c1f
Merge pull request #3 from dsidirop/ksidirop/NTOP-0053-flag-to-displa…
dsidirop Feb 7, 2022
d7ef625
chore (.gitignore): ignore .vscode folder and any *.code-workspace files
ksidirop-laerdal Feb 8, 2022
64edada
feat (new cli flag): add new flag '-b' to print traffic in raw bytes
ksidirop-laerdal Feb 8, 2022
ed12dae
Merge pull request #4 from dsidirop/ksidirop/NTOP-0053-support-raw-by…
dsidirop Feb 8, 2022
398aee6
Merge branch 'main' of github.com:nats-io/nats-top
ksidirop-laerdal Feb 8, 2022
184d950
clean (StartUI): trivial neutral cleanups
ksidirop-laerdal Feb 8, 2022
9ca0311
refa (redraw mech): the redraw channel now records the reason behind …
ksidirop-laerdal Feb 8, 2022
9edf722
feat (cli -r <max>): new flag "-r <max>" to specify the maximum numbe…
ksidirop-laerdal Feb 8, 2022
03078ef
Merge pull request #6 from dsidirop/ksidirop/NTOP-0052-support-refres…
dsidirop Feb 8, 2022
6e6ce7b
feat (FetchStats()): extracted the fetching logic of MonitorStats() i…
ksidirop-laerdal Feb 8, 2022
6d6ea58
feat (MonitorStats()): simplify the method by having it invoke FetchS…
ksidirop-laerdal Feb 8, 2022
e6ce7c9
clean (FetchStats()): trivial simplification
ksidirop-laerdal Feb 8, 2022
4aa3ad6
feat (cli flag -o): new flag to save a snapshot of the output directl…
ksidirop-laerdal Feb 8, 2022
5bf03b9
Merge pull request #7 from dsidirop/ksidirop/NTOP-0057-new-cli-flag-s…
dsidirop Feb 8, 2022
7df6868
feat (cli flag '-o -'): passing '-o -' now prints the snapshot to the…
ksidirop-laerdal Feb 8, 2022
240cd40
Merge pull request #8 from dsidirop/ksidirop/NTOP-0057-new-cli-flag-s…
dsidirop Feb 8, 2022
4e4bed8
Merge branch 'main' of https://github.com/nats-io/nats-top
dsidirop Feb 13, 2022
21acd7c
sidefix (nats-top): replace log.Fatalf(...) that are followed by call…
dsidirop Feb 13, 2022
cd0725c
clean (nats-top): remove method exitWithError() since it's not being …
dsidirop Feb 13, 2022
480150b
sideclean (refreshOptionHeader): use fmt.Print() instead of fmt.Printf()
dsidirop Feb 13, 2022
dcf20c0
clean (nats-top): remove 'defaultHeader' as it was not being used any…
dsidirop Feb 13, 2022
6cd3a89
clean (nats-top): move comments on the side to conserve vertical space
dsidirop Feb 13, 2022
05178d5
clean (nats-top): move comments on the side to conserve vertical space
dsidirop Feb 13, 2022
4f302cc
revert (nats-top.go): revert a hunk that sneaked-in unintentionally i…
ksidirop-laerdal Feb 14, 2022
8134383
feat (file output formatter): turn the default "plain-text" formatter…
ksidirop-laerdal Feb 14, 2022
8deed03
feat (generate csv): introduce new method generateParagraphCSV() tail…
ksidirop-laerdal Feb 14, 2022
075f4cb
Merge pull request #9 from dsidirop/ksidirop/NTOP-59-new-cli-flag-for…
dsidirop Feb 14, 2022
0b8ef70
Merge branch 'main' of https://github.com/nats-io/nats-top
dsidirop May 13, 2022
8275aea
feat (--version): add support for printing version via the --version …
dsidirop May 13, 2022
e5362e2
Merge pull request #11 from dsidirop/ksidirop/NTOP-0062-add-version-flag
dsidirop May 13, 2022
6321c4a
feat (--display-subscriptions-column): new flag
dsidirop May 13, 2022
181a392
feat (version): bump to 0.5.3 (old was: 0.5.2)
dsidirop May 13, 2022
0faf7f8
fix (csv output): when emitting csv output via '-o' the subs will be …
dsidirop May 13, 2022
4152a5a
clean (nats-top): trivial neutral cleanups in generateParagraphCSV()
dsidirop May 13, 2022
d891961
clean (nats-top.go): trivial simplifications in StartUI()
dsidirop May 13, 2022
b9b08d0
clean (nats-top.go): more trivial simplifications in StartUI()
dsidirop May 13, 2022
d27485c
Merge pull request #12 from dsidirop/ksidirop/NTOP-0069-new-flag--dis…
dsidirop May 13, 2022
45411cc
clean (.gitignore)
dsidirop May 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ _testmain.go
/nats-top

# VSCode

.vscode/**
*.code-workspace
67 changes: 29 additions & 38 deletions nats-top.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ import (
ui "gopkg.in/gizak/termui.v1"
)

const version = "0.5.2"
const version = "0.5.3"

var (
host = flag.String("s", "127.0.0.1", "The nats server host.")
port = flag.Int("m", 8222, "The NATS server monitoring port.")
conns = flag.Int("n", 1024, "Maximum number of connections to poll.")
delay = flag.Int("d", 1, "Refresh interval in seconds.")
sortBy = flag.String("sort", "cid", "Value for which to sort by the connections.")
lookupDNS = flag.Bool("lookup", false, "Enable client addresses DNS lookup.")
outputFile = flag.String("o", "", "Save the very first nats-top snapshot to the given file and exit. If '-' is passed then the snapshot is printed the standard output.")
showVersion = flag.Bool("v", false, "Show nats-top version.")
outputDelimiter = flag.String("l", "", "Specifies the delimiter to use for the output file when the '-o' parameter is used. By default this option is unset which means that standard grid-like plain-text output will be used.")
displayRawBytes = flag.Bool("b", false, "Display traffic in raw bytes.")
maxStatsRefreshes = flag.Int("r", -1, "Specifies the maximum number of times nats-top should refresh nats-stats before exiting.")
host = flag.String("s", "127.0.0.1", "The nats server host.")
port = flag.Int("m", 8222, "The NATS server monitoring port.")
conns = flag.Int("n", 1024, "Maximum number of connections to poll.")
delay = flag.Int("d", 1, "Refresh interval in seconds.")
sortBy = flag.String("sort", "cid", "Value for which to sort by the connections.")
lookupDNS = flag.Bool("lookup", false, "Enable client addresses DNS lookup.")
outputFile = flag.String("o", "", "Save the very first nats-top snapshot to the given file and exit. If '-' is passed then the snapshot is printed the standard output.")
showVersion = false
outputDelimiter = flag.String("l", "", "Specifies the delimiter to use for the output file when the '-o' parameter is used. By default this option is unset which means that standard grid-like plain-text output will be used.")
displayRawBytes = flag.Bool("b", false, "Display traffic in raw bytes.")
maxStatsRefreshes = flag.Int("r", -1, "Specifies the maximum number of times nats-top should refresh nats-stats before exiting.")
displaySubscriptionsColumn = flag.Bool("display-subscriptions-column", false, "Display subscriptions column upon launch.")

// Secure options
httpsPort = flag.Int("ms", 0, "The NATS server secure monitoring port.")
Expand All @@ -40,7 +41,7 @@ var (

const usageHelp = `
usage: nats-top [-s server] [-m http_port] [-ms https_port] [-n num_connections] [-d delay_secs] [-r max] [-o FILE] [-l DELIMITER] [-sort by]
[-cert FILE] [-key FILE ][-cacert FILE] [-k] [-b]
[-cert FILE] [-key FILE] [-cacert FILE] [-k] [-b] [-v|--version]

`

Expand All @@ -49,14 +50,16 @@ func usage() {
}

func init() {
flag.BoolVar(&showVersion, "v", false, "Same as --version.")
flag.BoolVar(&showVersion, "version", false, "Show nats-top version.")

log.SetFlags(0)
flag.Usage = usage
flag.Parse()
}

func main() {

if *showVersion {
if showVersion {
log.Printf("nats-top v%s", version)
os.Exit(0)
}
Expand Down Expand Up @@ -100,6 +103,10 @@ func main() {
}
engine.SortOpt = sortOpt

if *displaySubscriptionsColumn {
engine.DisplaySubs = true
}

if *outputFile != "" {
saveStatsSnapshotToFile(engine, outputFile, *outputDelimiter)
return
Expand Down Expand Up @@ -403,6 +410,7 @@ func generateParagraphCSV(
inMsgs, inBytes, inMsgsRate, inBytesRate,
outMsgs, outBytes, outMsgsRate, outBytesRate,
)

text += fmt.Sprintf("\n\nConnections Polled:[__DELIM__]%d\n", numConns)

displaySubs := engine.DisplaySubs
Expand Down Expand Up @@ -485,14 +493,14 @@ func generateParagraphCSV(
connLineInfo = append(connLineInfo, conn.Uptime, conn.LastActivity)

if displaySubs {
subs := strings.Join(conn.Subs, "[__DELIM__]")
subs := "[__DELIM__]" + strings.Join(conn.Subs, " ") // its safer to use a couple of whitespaces instead of commas to separate the subs because comma is reserved to separate entire columns!
connLineInfo = append(connLineInfo, subs)
}

text += fmt.Sprintf(connValues, connLineInfo...) // Add line to screen!
text += fmt.Sprintf(connValues, connLineInfo...)
}

text = strings.Replace(text, "[__DELIM__]", delimiter, -1)
text = strings.ReplaceAll(text, "[__DELIM__]", delimiter)

return text
}
Expand Down Expand Up @@ -567,7 +575,6 @@ func StartUI(engine *top.Engine) {
// Flags for capturing options
waitingSortOption := false
waitingLimitOption := false
displaySubscriptions := false

optionBuf := ""
refreshOptionHeader := func() {
Expand Down Expand Up @@ -659,13 +666,7 @@ func StartUI(engine *top.Engine) {
}

if e.Type == ui.EventKey && e.Ch == 's' && !(waitingLimitOption || waitingSortOption) {
if displaySubscriptions {
displaySubscriptions = false
engine.DisplaySubs = false
} else {
displaySubscriptions = true
engine.DisplaySubs = true
}
engine.DisplaySubs = !engine.DisplaySubs
}

if e.Type == ui.EventKey && viewMode == HelpViewMode {
Expand Down Expand Up @@ -697,21 +698,11 @@ func StartUI(engine *top.Engine) {
}

if e.Type == ui.EventKey && (e.Ch == 'd') && !(waitingSortOption || waitingLimitOption) {
switch *lookupDNS {
case true:
*lookupDNS = false
case false:
*lookupDNS = true
}
*lookupDNS = !*lookupDNS
}

if e.Type == ui.EventKey && (e.Ch == 'b') && !(waitingSortOption || waitingLimitOption) {
switch *displayRawBytes {
case true:
*displayRawBytes = false
case false:
*displayRawBytes = true
}
*displayRawBytes = !*displayRawBytes
}

if e.Type == ui.EventResize {
Expand Down