Skip to content

Commit ce0e9c4

Browse files
committed
updated pkg paths, updated flush behavior, 1.1 release
1 parent d5d1bf6 commit ce0e9c4

File tree

8 files changed

+41
-20
lines changed

8 files changed

+41
-20
lines changed

changelog.MD

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.1.1] - 2023-07-03
6+
7+
### Changed
8+
9+
- default is an effectively "unlimited" duration for statcapn
10+
- no longer buffer output to files, this allows a control+c to get a complete useful file
11+
512
## [0.1.0] - 2023-07-03
613

714
### Added
815

916
- initial release
10-
- support for Linux, Mac (Darwin), and Windows all on arm64 and amd64 platforms
17+
- support for Linux, Mac (Darwin), and Windows all on arm64 and amd64 platforms
18+
19+
[0.1.1]: https://github.com/rsvihladremio/statcapn/compare/v0.1.0...v0.1.1
20+
[0.1.0]: https://github.com/rsvihladremio/statcapn/releases/tag/v0.1.0

main.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ package main
1818
import (
1919
"errors"
2020
"flag"
21+
"fmt"
2122
"log"
23+
"math"
24+
"os"
2225

2326
"github.com/rsvihladremio/statcapn/pkg"
27+
"github.com/rsvihladremio/statcapn/pkg/versions"
2428
)
2529

2630
func main() {
@@ -35,11 +39,23 @@ func ArgParse() pkg.Args {
3539
var durationSeconds int
3640
var outFile string
3741

38-
flag.IntVar(&intervalSeconds, "i", 1, "number of seconds between execution of collection")
39-
flag.IntVar(&durationSeconds, "d", 60, "number of seconds for duration of all collection")
40-
flag.Parse()
41-
if flag.NArg() > 0 {
42-
outFile = flag.Arg(0)
42+
fs := flag.NewFlagSet("statcapn", flag.ExitOnError)
43+
44+
fs.IntVar(&intervalSeconds, "i", 1, "number of seconds between execution of collection")
45+
fs.IntVar(&durationSeconds, "d", math.MaxInt, "number of seconds for duration of all collection")
46+
47+
// Customize the usage message
48+
fs.Usage = func() {
49+
fmt.Fprintf(os.Stderr, "statcapn %s-%s\n\nstandard usage:\n\tstatcapn -i <interval> -d <duration_seconds> metrics.txt\n\nFor json output:\n\tstatcapn -i <interval> -d <duration_seconds> metrics.json\n\nflags:\n\n", versions.GetVersion(), versions.GetGitSha())
50+
fs.PrintDefaults()
51+
}
52+
53+
if err := fs.Parse(os.Args[1:]); err != nil {
54+
fmt.Println(err)
55+
os.Exit(1)
56+
}
57+
if fs.NArg() > 0 {
58+
outFile = fs.Arg(0)
4359
}
4460
return pkg.Args{
4561
IntervalSeconds: intervalSeconds,

pkg/sysmetrics.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package pkg
1717

1818
import (
19-
"bufio"
2019
"encoding/json"
2120
"fmt"
2221
"io"
@@ -212,11 +211,7 @@ func SystemMetrics(args Args) error {
212211
// we manually close this so we do not care that we are not handling the error
213212
defer f.Close()
214213

215-
bufWriter := bufio.NewWriter(w)
216214
cleanup = func() error {
217-
if err := bufWriter.Flush(); err != nil {
218-
return fmt.Errorf("unable to flush metrics file %v due to error %w", outputFile, err)
219-
}
220215
if err := f.Close(); err != nil {
221216
return fmt.Errorf("unable to close metrics file %v due to error %w", outputFile, err)
222217
}
@@ -229,7 +224,7 @@ func SystemMetrics(args Args) error {
229224
return fmt.Errorf("unable to marshal row %#v due to error %w", row, err)
230225
}
231226
txt := fmt.Sprintf("%v\n", string(str))
232-
_, err = bufWriter.Write([]byte(txt))
227+
_, err = f.Write([]byte(txt))
233228
if err != nil {
234229
return fmt.Errorf("unable to write to json file due to error %w", err)
235230
}

script/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ fi
4040
# this is also set in script/release and is a copy paste
4141
GIT_SHA=`git rev-parse --short HEAD`
4242
VERSION=`git rev-parse --abbrev-ref HEAD`
43-
LDFLAGS="-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION"
43+
LDFLAGS="-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION"
4444
go build -ldflags "$LDFLAGS" -o ./bin/statcapn

script/build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Set-Location -Path (Get-Item (Split-Path -Parent $MyInvocation.MyCommand.Definit
1111
# Get Git SHA and Version
1212
$GIT_SHA = git rev-parse --short HEAD
1313
$VERSION = git rev-parse --abbrev-ref HEAD
14-
$LDFLAGS = "-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION"
14+
$LDFLAGS = "-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION"
1515

1616
# Build again and copy default-ddc.yaml
17-
go build -ldflags "$LDFLAGS" -o .\bin\statcapn.exe
17+
go build -ldflags "$LDFLAGS" -o .\bin\statcapn.exe

script/install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [[ "$ARCH" == "x86_64" ]]; then
2525
fi
2626

2727
DOWNLOAD=statcapn-$OS-$ARCH.zip
28-
curl -o $DOWNLOAD -L "https://github.com/dremio/statcapn/releases/latest/download/$DOWNLOAD"
28+
curl -o $DOWNLOAD -L "https://github.com/rsvihladremio/statcapn/releases/latest/download/$DOWNLOAD"
2929
unzip $DOWNLOAD
3030

3131
sudo mkdir -p /usr/local/share/statcapn

script/release-build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fi
3838
# this is also set in script/build and is a copy paste
3939
GIT_SHA=`git rev-parse --short HEAD`
4040
VERSION=$1
41-
LDFLAGS="-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION"
41+
LDFLAGS="-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION"
4242

4343
echo "Cleaning bin folder…"
4444
date "+%H:%M:%S"
@@ -68,4 +68,4 @@ zip ./bin/statcapn-windows-amd64.zip ./bin/statcapn.exe
6868
echo "Building windows-arm64…"
6969
date "+%H:%M:%S"
7070
GOOS=windows GOARCH=arm64 go build -ldflags "$LDFLAGS" -o ./bin/statcapn.exe
71-
zip ./bin/statcapn-windows-arm64.zip ./bin/statcapn.exe
71+
zip ./bin/statcapn-windows-arm64.zip ./bin/statcapn.exe

script/release-build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Set-Location -Path (Get-Item (Split-Path -Parent $MyInvocation.MyCommand.Definit
99
# Get Git SHA and Version
1010
$GIT_SHA = git rev-parse --short HEAD
1111
$VERSION = $args[0]
12-
$LDFLAGS = "-X github.com/dremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/dremio/statcapn/pkg/versions.version=$VERSION"
12+
$LDFLAGS = "-X github.com/rsvihladremio/statcapn/pkg/versions.gitSha=$GIT_SHA -X github.com/rsvihladremio/statcapn/pkg/versions.version=$VERSION"
1313

1414
Write-Output "Cleaning bin folder…"
1515
Get-Date -Format "HH:mm:ss"
@@ -53,4 +53,4 @@ Get-Date -Format "HH:mm:ss"
5353
$env:GOOS="windows"
5454
$env:GOARCH="arm64"
5555
go build -ldflags "$LDFLAGS" -o ./bin/statcapn.exe
56-
Compress-Archive -Path ./bin/statcapn.exe -DestinationPath ./bin/statcapn-windows-arm64.zip
56+
Compress-Archive -Path ./bin/statcapn.exe -DestinationPath ./bin/statcapn-windows-arm64.zip

0 commit comments

Comments
 (0)