Skip to content
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

Resync with upstream. #48

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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.23.1'

- 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.23.1'

- 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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ load-generator
integration-tester
dist
/vendor
/.vscode
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.23.1 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.23.1 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.23.1 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)
31 changes: 22 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,10 +173,13 @@ 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,
"print version information and exit")
removeEmptyGroups = flag.Bool("remove-empty-groups", false, "forget process groups with no processes")
)
flag.Parse()

Expand Down Expand Up @@ -231,15 +235,21 @@ 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,
RemoveEmptyGroups: *removeEmptyGroups,
},
)
if err != nil {
Expand Down Expand Up @@ -271,7 +281,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
19 changes: 11 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,15 @@ 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
RemoveEmptyGroups bool
}

NamedProcessCollector struct {
Expand All @@ -186,7 +189,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, options.RemoveEmptyGroups),
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