Skip to content

Commit

Permalink
Update from ncabatoff/process-exporter (#3)
Browse files Browse the repository at this point in the history
* update deps

* Finish updating to Go 1.22

* Update Dockerfile for Go 1.22

* Add -recheck-with-time-limit support (ncabatoff#223)

process-exporter already supports the -recheck flag which makes it run
the whole matching logic on each scrape. This is very useful when trying
to monitor processes which change their names shortly after start.

Sadly, -recheck carries a rather high performance penalty. At the same
time, process name changes are very common directly after start, are
seldomly expected during usage.

This commit introduces -recheck-with-time-limit which rechecks processes
N seconds after their start and stops doing so afterwards. This combines
the accuracy benefits of -recheck with the performance gains of not
using -recheck.

* Fix server start error (ncabatoff#295)

* Update release action to use newer actions.  Use latest goreleaser version.  Use CGO_ENABLED in its config instead of tags.

* Upgrade prometheus/procfs dependency, use Go1.21 (ncabatoff#296)

* Upgrade prometheus/procfs dependency and therefore set Go1.21 in go.mod

* Fix broken compatibility with prometheus/procfs

* Update README for Go1.21

---------

Co-authored-by: Thomas Delbende <[email protected]>

* split image workflow from build (ncabatoff#299)

Various GHA improvements.

* Bump golang.org/x/net from 0.22.0 to 0.23.0 (ncabatoff#298)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.22.0 to 0.23.0.
- [Commits](golang/net@v0.22.0...v0.23.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Nick Cabatoff <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: ncabatoff <[email protected]>
Co-authored-by: Christian Hoffmann <[email protected]>
Co-authored-by: AiDaiP <[email protected]>
Co-authored-by: Maxi_Mega <[email protected]>
Co-authored-by: Thomas Delbende <[email protected]>
Co-authored-by: Nick Cabatoff <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
8 people authored Jun 16, 2024
1 parent 935906b commit 299ab82
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 576 deletions.
55 changes: 6 additions & 49 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,14 @@ jobs:
- name: setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.22'

- uses: actions/checkout@master
- uses: actions/checkout@v4
with:
fetch-depth: 0

- run: make style
- run: make vet
- run: make test
- run: make build
- run: make integ

image:
runs-on: ubuntu-latest
steps:
- name: setup buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: login to docker hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- uses: actions/checkout@master

- name: generate docker metadata
id: meta
uses: docker/metadata-action@v3
with:
context: .
# list of Docker images to use as base name for tags
images: |
ncabatoff/process-exporter
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
- name: build docker image and, if not PR, push
uses: docker/build-push-action@v2
with:
file: ./Dockerfile
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- run: make BRANCH=${{ github.head_ref || github.ref_name }} build
- run: make integ
51 changes: 51 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
push:
branches: [master]
pull_request:

jobs:
image:
runs-on: ubuntu-latest
steps:
- name: setup buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest

- name: login to docker hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: generate docker metadata
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ncabatoff/process-exporter
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
- name: build docker image and, if not PR, push
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: '1.17'
go-version: '1.22'

- run: make test

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: "~> 0.182"
version: "~> 1.25"
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
builds:
- main: cmd/process-exporter/main.go
binary: process-exporter
flags: -tags netgo
ldflags:
- -s -w
- -X github.com/prometheus/common/version.BuildDate={{.Date}}
- -X github.com/prometheus/common/version.BuildUser=goreleaser
- -X github.com/prometheus/common/version.Revision={{.FullCommit}}
- -X main.version={{.Version}}

env:
- CGO_ENABLED=0
goos:
- linux
goarch:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM --platform=$BUILDPLATFORM golang:1.17 AS build
FROM --platform=$BUILDPLATFORM golang:1.22 AS build
ARG TARGETARCH
ARG BUILDPLATFORM
WORKDIR /go/src/github.com/ncabatoff/process-exporter
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ docker:
docker run --rm --volumes-from configs "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" $(SMOKE_TEST)

dockertest:
docker run --rm -it -v `pwd`:/go/src/github.com/ncabatoff/process-exporter golang:1.15 make -C /go/src/github.com/ncabatoff/process-exporter test
docker run --rm -it -v `pwd`:/go/src/github.com/ncabatoff/process-exporter golang:1.22 make -C /go/src/github.com/ncabatoff/process-exporter test

dockerinteg:
docker run --rm -it -v `pwd`:/go/src/github.com/ncabatoff/process-exporter golang:1.15 make -C /go/src/github.com/ncabatoff/process-exporter build integ
docker run --rm -it -v `pwd`:/go/src/github.com/ncabatoff/process-exporter golang:1.22 make -C /go/src/github.com/ncabatoff/process-exporter build integ

.PHONY: update-go-deps
update-go-deps:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ as well as group name.
re-evaluated. This is disabled by default as an optimization, but since
processes can choose to change their names, this may result in a process
falling into the wrong group if we happen to see it for the first time before
it's assumed its proper name.
it's assumed its proper name. You can use -recheck-with-time-limit to enable this
feature only for a specific duration after process starts.

-procnames is intended as a quick alternative to using a config file. Details
in the following section.
Expand Down Expand Up @@ -371,7 +372,7 @@ An example Grafana dashboard to view the metrics is available at https://grafana

## Building

Requires Go 1.13 installed.
Requires Go 1.21 (at least) installed.
```
make
```
Expand Down Expand Up @@ -414,4 +415,4 @@ process_max_fds 1.048576e+06
process_open_fds 10
```

For further information about TLS configuration, please visit: [exporter-toolkit](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)
For further information about TLS configuration, please visit: [exporter-toolkit](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md)
29 changes: 20 additions & 9 deletions cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ncabatoff/process-exporter/collector"
"github.com/ncabatoff/process-exporter/config"
"github.com/prometheus/client_golang/prometheus"
verCollector "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
promVersion "github.com/prometheus/common/version"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (nmr *nameMapperRegex) MatchAndName(nacl common.ProcAttributes) (bool, stri

func init() {
promVersion.Version = version
prometheus.MustRegister(promVersion.NewCollector("process_exporter"))
prometheus.MustRegister(verCollector.NewCollector("process_exporter"))
}

func main() {
Expand Down Expand Up @@ -172,6 +173,8 @@ func main() {
"path to YAML web config file")
recheck = flag.Bool("recheck", false,
"recheck process names on each scrape")
recheckTimeLimit = flag.Duration("recheck-with-time-limit", 0,
"recheck processes only this much time after their start, but no longer.")
debug = flag.Bool("debug", false,
"log debugging information to stdout")
showVersion = flag.Bool("version", false,
Expand Down Expand Up @@ -231,15 +234,20 @@ func main() {
matchnamer = namemapper
}

if *recheckTimeLimit != 0 {
*recheck = true
}

pc, err := collector.NewProcessCollector(
collector.ProcessCollectorOption{
ProcFSPath: *procfsPath,
Children: *children,
Threads: *threads,
GatherSMaps: *smaps,
Namer: matchnamer,
Recheck: *recheck,
Debug: *debug,
ProcFSPath: *procfsPath,
Children: *children,
Threads: *threads,
GatherSMaps: *smaps,
Namer: matchnamer,
Recheck: *recheck,
RecheckTimeLimit: *recheckTimeLimit,
Debug: *debug,
},
)
if err != nil {
Expand Down Expand Up @@ -271,7 +279,10 @@ func main() {
</html>`))
})
server := &http.Server{Addr: *listenAddress}
if err := web.ListenAndServe(server, *tlsConfigFile, logger); err != nil {
if err := web.ListenAndServe(server, &web.FlagConfig{
WebListenAddresses: &[]string{*listenAddress},
WebConfigFile: tlsConfigFile,
}, logger); err != nil {
log.Fatalf("Failed to start the server: %v", err)
os.Exit(1)
}
Expand Down
18 changes: 10 additions & 8 deletions collector/process_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"log"
"time"

common "github.com/ncabatoff/process-exporter"
"github.com/ncabatoff/process-exporter/proc"
Expand Down Expand Up @@ -155,13 +156,14 @@ type (
}

ProcessCollectorOption struct {
ProcFSPath string
Children bool
Threads bool
GatherSMaps bool
Namer common.MatchNamer
Recheck bool
Debug bool
ProcFSPath string
Children bool
Threads bool
GatherSMaps bool
Namer common.MatchNamer
Recheck bool
RecheckTimeLimit time.Duration
Debug bool
}

NamedProcessCollector struct {
Expand All @@ -186,7 +188,7 @@ func NewProcessCollector(options ProcessCollectorOption) (*NamedProcessCollector
fs.GatherSMaps = options.GatherSMaps
p := &NamedProcessCollector{
scrapeChan: make(chan scrapeRequest),
Grouper: proc.NewGrouper(options.Namer, options.Children, options.Threads, options.Recheck, options.Debug),
Grouper: proc.NewGrouper(options.Namer, options.Children, options.Threads, options.Recheck, options.RecheckTimeLimit, options.Debug),
source: fs,
threads: options.Threads,
smaps: options.GatherSMaps,
Expand Down
38 changes: 30 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
module github.com/ncabatoff/process-exporter

go 1.13
go 1.21

require (
github.com/google/go-cmp v0.5.6
github.com/kr/pretty v0.3.0 // indirect
github.com/google/go-cmp v0.6.0
github.com/ncabatoff/fakescraper v0.0.0-20201102132415-4b37ba603d65
github.com/ncabatoff/go-seq v0.0.0-20180805175032-b08ef85ed833
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.29.0
github.com/prometheus/exporter-toolkit v0.7.0
github.com/prometheus/procfs v0.7.3
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.52.3
github.com/prometheus/exporter-toolkit v0.11.0
github.com/prometheus/procfs v0.14.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit 299ab82

Please sign in to comment.