Skip to content

Commit

Permalink
updated pkg paths, updated flush behavior, 1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
rsvihladremio committed Jul 3, 2023
1 parent d5d1bf6 commit ce0e9c4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
12 changes: 11 additions & 1 deletion changelog.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
26 changes: 21 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 <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())
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,
Expand Down
7 changes: 1 addition & 6 deletions pkg/sysmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package pkg

import (
"bufio"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion script/build
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions script/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
go build -ldflags "$LDFLAGS" -o .\bin\statcapn.exe
2 changes: 1 addition & 1 deletion script/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions script/release-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
zip ./bin/statcapn-windows-arm64.zip ./bin/statcapn.exe
4 changes: 2 additions & 2 deletions script/release-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Compress-Archive -Path ./bin/statcapn.exe -DestinationPath ./bin/statcapn-windows-arm64.zip

0 comments on commit ce0e9c4

Please sign in to comment.