Skip to content

Update swap.go to only log once on startup if swap metrics can't be collected #107

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

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ local-deb-package: ## Create local deb package

local-rpm-package: ## Create local rpm package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
VERSION=$(shell echo ${VERSION} | tr -d 'v') nfpm pkg --config ./scripts/.local-nfpm.yaml --packager rpm --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT.rpm;
VERSION=$(shell echo ${VERSION} | tr -d 'v') nfpm pkg --config ./scripts/.local-nfpm.yaml --packager rpm --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.rpm;

local-txz-package: ## Create local txz package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=freebsd go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
Expand Down
4 changes: 2 additions & 2 deletions scripts/packages/packager/local-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cp build/nginx-agent /staging/usr/local/bin

chmod +x /staging/usr/local/etc/rc.d/nginx-agent

VERSION="$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')-SNAPSHOT" envsubst < scripts/packages/manifest > /staging/+MANIFEST
VERSION="$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')-SNAPSHOT-$(git rev-parse --short HEAD)" envsubst < scripts/packages/manifest > /staging/+MANIFEST

pkg -o ABI="FreeBSD:13:amd64" create --format txz \
-m /staging \
Expand All @@ -31,7 +31,7 @@ pkg -o ABI="FreeBSD:13:amd64" create --format txz \
# but since version 1.17.0 pkg will now always create a file with the extesion pkg no matter what the format is.
# See 1.17.0 release notes for more info: https://cgit.freebsd.org/ports/commit/?id=e497a16a286972bfcab908209b11ee6a13d99dc9
cd build/
ln -s nginx-agent-"$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')"-SNAPSHOT.pkg nginx-agent-"$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')"-SNAPSHOT.txz
ln -s nginx-agent-"$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')"-SNAPSHOT-"$(git rev-parse --short HEAD)".pkg nginx-agent-"$(git describe --match 'v[0-9]*' --abbrev=0 | tr -d 'v')"-SNAPSHOT-"$(git rev-parse --short HEAD)".txz
cd ..

rm -rf /staging
13 changes: 11 additions & 2 deletions src/core/metrics/sources/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func NewSwapSource(namespace string, env core.Environment) *Swap {
statFunc = cgroupSwapSource.SwapMemoryStat
}

// Verify if swap metrics can be collected on startup
_, err := statFunc()
if err != nil {
if e, ok := err.(*os.PathError); ok {
log.Warnf("Unable to collect Swap metrics because the file %v was not found", e.Path)
}
log.Warnf("Unable to collect Swap metrics: %v", err)
}

return &Swap{&namedMetric{namespace, "swap"}, statFunc}
}

Expand All @@ -35,10 +44,10 @@ func (c *Swap) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<- *proto.
swapStats, err := c.statFunc()
if err != nil {
if e, ok := err.(*os.PathError); ok {
log.Warnf("Unable to collect Swap metrics because the file %v was not found", e.Path)
log.Debugf("Unable to collect Swap metrics because the file %v was not found", e.Path)
return
}
log.Errorf("Failed to collect Swap metrics: %v", err)
log.Debugf("Unable to collect Swap metrics: %v", err)
return
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.