Skip to content
Open
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 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.21 AS build
ARG TARGETARCH
ARG BUILDPLATFORM
WORKDIR /go/src/github.com/ncabatoff/process-exporter
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= ncabatoff/process-exporter

BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILDDATE ?= $(shell date --iso-8601=seconds)
BUILDDATE ?= $(shell date -Iseconds)
BUILDUSER ?= $(shell whoami)@$(shell hostname)
REVISION ?= $(shell git rev-parse HEAD)
TAG_VERSION ?= $(shell git describe --tags --abbrev=0)
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ install via [docker](https://hub.docker.com/r/ncabatoff/process-exporter/).

Usage:

```
process-exporter [options] -config.path filename.yml
```bash
process-exporter [options] -config.path filename.yml
```

or via docker:

```
docker run -d --rm -p 9256:9256 --privileged -v /proc:/host/proc -v `pwd`:/config ncabatoff/process-exporter --procfs /host/proc -config.path /config/filename.yml
```bash
docker run -d --rm -p 9256:9256 --privileged -v /proc:/host/proc -v `pwd`:/config ncabatoff/process-exporter --procfs /host/proc -config.path /config/filename.yml

```

Expand Down Expand Up @@ -318,7 +318,7 @@ The extra label `state` can have these values: `Running`, `Sleeping`, `Waiting`,

## Group Thread Metrics

Since publishing thread metrics adds a lot of overhead, use the `-threads` command-line argument to disable them,
Since publishing thread metrics adds a lot of overhead, use the `-threads` command-line argument to disable them,
if necessary.

All these metrics start with `namedprocess_namegroup_` and have at minimum
Expand Down Expand Up @@ -367,17 +367,19 @@ minimal: each time a scrape occurs, it will parse of /proc/$pid/stat and

## Dashboards

An example Grafana dashboard to view the metrics is available at https://grafana.net/dashboards/249
An example Grafana dashboard to view the metrics is available at https://grafana.com/grafana/dashboards/249-named-processes/

## Building

Requires Go 1.13 installed.
Requires Go 1.21 installed.
```
make
```

## Exposing metrics through HTTPS

Process exporter supports TLS and basic auth through using the --web.config.file format described below and in the [exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Process exporter supports TLS and basic auth through using the --web.config.file format described below and in the [exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
Process exporter supports TLS and basic auth through using the --web.config.file format described below and in the [exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/3f0df9ed8ef420d6000d64638f5fe6c4e7b71912/docs/web-configuration.md).

permalink


web-config.yml
```
# Minimal TLS configuration example. Additionally, a certificate and a key file
Expand All @@ -386,8 +388,10 @@ tls_server_config:
cert_file: server.crt
key_file: server.key
```

Running
```

$ ./process-exporter -web.config.file web-config.yml &
$ curl -sk https://localhost:9256/metrics | grep process

Expand All @@ -414,4 +418,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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/3f0df9ed8ef420d6000d64638f5fe6c4e7b71912/docs/web-configuration.md)

1 change: 0 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '--tag=gcr.io/$PROJECT_ID/process-exporter', '.', '-f', 'Dockerfile.cloudbuild']
images: ['gcr.io/$PROJECT_ID/process-exporter']

7 changes: 4 additions & 3 deletions cmd/load-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"io/ioutil"
"math/rand"
"runtime"
"syscall"
"unsafe"

sys "golang.org/x/sys/unix"
)

var ready = make(chan struct{})
Expand Down Expand Up @@ -50,9 +51,9 @@ func setPrName(name string) error {
bytes := append([]byte(name), 0)
ptr := unsafe.Pointer(&bytes[0])

_, _, errno := syscall.RawSyscall6(syscall.SYS_PRCTL, syscall.PR_SET_NAME, uintptr(ptr), 0, 0, 0, 0)
_, _, errno := sys.RawSyscall6(sys.SYS_PRCTL, sys.PR_SET_NAME, uintptr(ptr), 0, 0, 0, 0)
if errno != 0 {
return syscall.Errno(errno)
return sys.Errno(errno)
}
return nil
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/alecthomas/kingpin/v2"
"github.com/ncabatoff/fakescraper"
common "github.com/ncabatoff/process-exporter"
"github.com/ncabatoff/process-exporter/collector"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/prometheus/common/promlog"
promVersion "github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
)

// Version is set at build time use ldflags.
Expand All @@ -29,14 +31,14 @@ func printManual() {
fmt.Print(`Usage:
process-exporter [options] -config.path filename.yml

or
or

process-exporter [options] -procnames name1,...,nameN [-namemapping k1,v1,...,kN,vN]

The recommended option is to use a config file, but for convenience and
backwards compatibility the -procnames/-namemapping options exist as an
alternative.

The -children option (default:true) makes it so that any process that otherwise
isn't part of its own group becomes part of the first group found (if any) when
walking the process tree upwards. In other words, resource usage of
Expand All @@ -46,14 +48,14 @@ as a different group name.
Command-line process selection (procnames/namemapping):

Every process not in the procnames list is ignored. Otherwise, all processes
found are reported on as a group based on the process name they share.
found are reported on as a group based on the process name they share.
Here 'process name' refers to the value found in the second field of
/proc/<pid>/stat, which is truncated at 15 chars.

The -namemapping option allows assigning a group name based on a combination of
the process name and command line. For example, using
the process name and command line. For example, using

-namemapping "python2,([^/]+)\.py,java,-jar\s+([^/]+).jar"
-namemapping "python2,([^/]+)\.py,java,-jar\s+([^/]+).jar"

will make it so that each different python2 and java -jar invocation will be
tracked with distinct metrics. Processes whose remapped name is absent from
Expand Down Expand Up @@ -146,8 +148,6 @@ func init() {

func main() {
var (
listenAddress = flag.String("web.listen-address", ":9256",
"Address on which to expose metrics and web interface.")
metricsPath = flag.String("web.telemetry-path", "/metrics",
"Path under which to expose metrics.")
onceToStdoutDelay = flag.Duration("once-to-stdout-delay", 0,
Expand All @@ -168,16 +168,16 @@ func main() {
"print manual")
configPath = flag.String("config.path", "",
"path to YAML config file")
tlsConfigFile = flag.String("web.config.file", "",
"path to YAML web config file")
recheck = flag.Bool("recheck", false,
"recheck process names on each scrape")
debug = flag.Bool("debug", false,
"log debugging information to stdout")
showVersion = flag.Bool("version", false,
"print version information and exit")
toolkitFlags = webflag.AddFlags(kingpin.CommandLine, ":9256")
)
flag.Parse()
kingpin.Parse()

promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)
Expand Down Expand Up @@ -270,8 +270,8 @@ func main() {
</body>
</html>`))
})
server := &http.Server{Addr: *listenAddress}
if err := web.ListenAndServe(server, *tlsConfigFile, logger); err != nil {
server := &http.Server{}
if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil {
log.Fatalf("Failed to start the server: %v", err)
os.Exit(1)
}
Expand Down
41 changes: 33 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
module github.com/ncabatoff/process-exporter

go 1.13
go 1.21.0

require (
github.com/google/go-cmp v0.5.6
github.com/kr/pretty v0.3.0 // indirect
github.com/alecthomas/kingpin/v2 v2.4.0
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.18.0
github.com/prometheus/common v0.46.0
github.com/prometheus/exporter-toolkit v0.11.0
github.com/prometheus/procfs v0.12.0
golang.org/x/sys v0.16.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
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.5.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
Loading