diff --git a/changelog.MD b/changelog.MD index 6b3bec2..0a8edf2 100644 --- a/changelog.MD +++ b/changelog.MD @@ -2,9 +2,19 @@ All notable changes to this project will be documented in this file. +## [0.1.1] - 2023-07-03 + +### Changed + +- default is an effectively "unlimited" duration for statcapn +- no longer buffer output to files, this allows a control+c to get a complete useful file + ## [0.1.0] - 2023-07-03 ### Added - initial release -- support for Linux, Mac (Darwin), and Windows all on arm64 and amd64 platforms \ No newline at end of file +- support for Linux, Mac (Darwin), and Windows all on arm64 and amd64 platforms + +[0.1.1]: https://github.com/rsvihladremio/statcapn/compare/v0.1.0...v0.1.1 +[0.1.0]: https://github.com/rsvihladremio/statcapn/releases/tag/v0.1.0 diff --git a/main.go b/main.go index 3e5359a..e0a4057 100644 --- a/main.go +++ b/main.go @@ -18,9 +18,13 @@ package main import ( "errors" "flag" + "fmt" "log" + "math" + "os" "github.com/rsvihladremio/statcapn/pkg" + "github.com/rsvihladremio/statcapn/pkg/versions" ) func main() { @@ -35,11 +39,23 @@ func ArgParse() pkg.Args { var durationSeconds int var outFile string - flag.IntVar(&intervalSeconds, "i", 1, "number of seconds between execution of collection") - flag.IntVar(&durationSeconds, "d", 60, "number of seconds for duration of all collection") - flag.Parse() - if flag.NArg() > 0 { - outFile = flag.Arg(0) + fs := flag.NewFlagSet("statcapn", flag.ExitOnError) + + fs.IntVar(&intervalSeconds, "i", 1, "number of seconds between execution of collection") + fs.IntVar(&durationSeconds, "d", math.MaxInt, "number of seconds for duration of all collection") + + // Customize the usage message + fs.Usage = func() { + fmt.Fprintf(os.Stderr, "statcapn %s-%s\n\nstandard usage:\n\tstatcapn -i -d metrics.txt\n\nFor json output:\n\tstatcapn -i -d metrics.json\n\nflags:\n\n", versions.GetVersion(), versions.GetGitSha()) + fs.PrintDefaults() + } + + if err := fs.Parse(os.Args[1:]); err != nil { + fmt.Println(err) + os.Exit(1) + } + if fs.NArg() > 0 { + outFile = fs.Arg(0) } return pkg.Args{ IntervalSeconds: intervalSeconds, diff --git a/pkg/sysmetrics.go b/pkg/sysmetrics.go index 61a201c..8a1f956 100644 --- a/pkg/sysmetrics.go +++ b/pkg/sysmetrics.go @@ -16,7 +16,6 @@ package pkg import ( - "bufio" "encoding/json" "fmt" "io" @@ -212,11 +211,7 @@ func SystemMetrics(args Args) error { // we manually close this so we do not care that we are not handling the error defer f.Close() - bufWriter := bufio.NewWriter(w) cleanup = func() error { - if err := bufWriter.Flush(); err != nil { - return fmt.Errorf("unable to flush metrics file %v due to error %w", outputFile, err) - } if err := f.Close(); err != nil { return fmt.Errorf("unable to close metrics file %v due to error %w", outputFile, err) } @@ -229,7 +224,7 @@ func SystemMetrics(args Args) error { return fmt.Errorf("unable to marshal row %#v due to error %w", row, err) } txt := fmt.Sprintf("%v\n", string(str)) - _, err = bufWriter.Write([]byte(txt)) + _, err = f.Write([]byte(txt)) if err != nil { return fmt.Errorf("unable to write to json file due to error %w", err) } diff --git a/script/build b/script/build index b52c811..bd39ea1 100755 --- a/script/build +++ b/script/build @@ -40,5 +40,5 @@ fi # this is also set in script/release and is a copy paste GIT_SHA=`git rev-parse --short HEAD` VERSION=`git rev-parse --abbrev-ref HEAD` -LDFLAGS="-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION" +LDFLAGS="-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION" go build -ldflags "$LDFLAGS" -o ./bin/statcapn diff --git a/script/build.ps1 b/script/build.ps1 index b5dfcb0..7d9410f 100644 --- a/script/build.ps1 +++ b/script/build.ps1 @@ -11,7 +11,7 @@ Set-Location -Path (Get-Item (Split-Path -Parent $MyInvocation.MyCommand.Definit # Get Git SHA and Version $GIT_SHA = git rev-parse --short HEAD $VERSION = git rev-parse --abbrev-ref HEAD -$LDFLAGS = "-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION" +$LDFLAGS = "-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION" # Build again and copy default-ddc.yaml -go build -ldflags "$LDFLAGS" -o .\bin\statcapn.exe \ No newline at end of file +go build -ldflags "$LDFLAGS" -o .\bin\statcapn.exe diff --git a/script/install b/script/install index b10bcdc..1f13d42 100755 --- a/script/install +++ b/script/install @@ -25,7 +25,7 @@ if [[ "$ARCH" == "x86_64" ]]; then fi DOWNLOAD=statcapn-$OS-$ARCH.zip -curl -o $DOWNLOAD -L "https://github.com/dremio/statcapn/releases/latest/download/$DOWNLOAD" +curl -o $DOWNLOAD -L "https://github.com/rsvihladremio/statcapn/releases/latest/download/$DOWNLOAD" unzip $DOWNLOAD sudo mkdir -p /usr/local/share/statcapn diff --git a/script/release-build b/script/release-build index 6936525..1d77116 100755 --- a/script/release-build +++ b/script/release-build @@ -38,7 +38,7 @@ fi # this is also set in script/build and is a copy paste GIT_SHA=`git rev-parse --short HEAD` VERSION=$1 -LDFLAGS="-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION" +LDFLAGS="-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION" echo "Cleaning bin folder…" date "+%H:%M:%S" @@ -68,4 +68,4 @@ zip ./bin/statcapn-windows-amd64.zip ./bin/statcapn.exe echo "Building windows-arm64…" date "+%H:%M:%S" GOOS=windows GOARCH=arm64 go build -ldflags "$LDFLAGS" -o ./bin/statcapn.exe -zip ./bin/statcapn-windows-arm64.zip ./bin/statcapn.exe \ No newline at end of file +zip ./bin/statcapn-windows-arm64.zip ./bin/statcapn.exe diff --git a/script/release-build.ps1 b/script/release-build.ps1 index 45b75bb..6878b65 100644 --- a/script/release-build.ps1 +++ b/script/release-build.ps1 @@ -9,7 +9,7 @@ Set-Location -Path (Get-Item (Split-Path -Parent $MyInvocation.MyCommand.Definit # Get Git SHA and Version $GIT_SHA = git rev-parse --short HEAD $VERSION = $args[0] -$LDFLAGS = "-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION" +$LDFLAGS = "-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION" Write-Output "Cleaning bin folder…" Get-Date -Format "HH:mm:ss" @@ -53,4 +53,4 @@ Get-Date -Format "HH:mm:ss" $env:GOOS="windows" $env:GOARCH="arm64" go build -ldflags "$LDFLAGS" -o ./bin/statcapn.exe -Compress-Archive -Path ./bin/statcapn.exe -DestinationPath ./bin/statcapn-windows-arm64.zip \ No newline at end of file +Compress-Archive -Path ./bin/statcapn.exe -DestinationPath ./bin/statcapn-windows-arm64.zip