* process_collector: fill in most statistics on macOS
Unfortunately, the virtual memory, resident memory, and network stats will
require access to undocumented C functions. I was warned off of cgo in IRC
because it would then have to be enabled in a bunch of different projects that
use this module, but I already was against it because that would break the
ability to cross-compile. There is no interface to `dlopen` built into golang.
The `github.com/ebitengine/purego` module looks promising (I can cross-compile
and call these methods), but I'm currently getting unexpected results. I'll
follow up with that separately if I can get it working, but hopefully this stuff
is pretty uncontroversial.
Tested on macOS 10.14.6 (amd64), macOS 14.6.1 (amd64), and macOS 15.0 (arm64)
by spawning `/usr/bin/ulimit -a -S` and `/usr/sbin/lsof -c $my_process` from
the test exporter process, and `ps -o lstart,vsize,rss,utime,stime,command` from
the shell, and comparing results with the exported metrics.
I can't find documentation for `RLIMIT_AS` on macOS (specifically if it's in
bytes or pages). It's currently being reported back as `RLIM_INFINITY`, which
seems reasonable, because I've come across reports that the value is ignored
anyway[1]. The bash 3.2 code for the built-in `ulimit` divides the value
reported by `getrusage(2)` by 1024 when printing, as it does for `RLIMIT_DATA`,
which is documented as being bytes in `getrusage(2)`. The help for `ulimit`
indicates it prints both in kbytes, so it's reasonable to assume this is already
in bytes.
[1] https://issues.chromium.org/issues/40581251#comment3
Signed-off-by: Matt Harbison <mharbison72@gmail.com>
* Update prometheus/process_collector_darwin.go
Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Matt Harbison <57785103+mharbison72@users.noreply.github.com>
---------
Signed-off-by: Matt Harbison <mharbison72@gmail.com>
Signed-off-by: Matt Harbison <57785103+mharbison72@users.noreply.github.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
* changed the name of all variables with min/max name
Signed-off-by: Parth Lawania <parthlawania@gmail.com>
* removed predeclared ignore condition for min and max identifiers
Signed-off-by: Parth Lawania <parthlawania@gmail.com>
---------
Signed-off-by: Parth Lawania <parthlawania@gmail.com>
Co-authored-by: Parth Lawania <parth.lawania@super.money>
Now that 1.23 is out, update the supported version matrix to Go 1.21
through 1.23. This allows us to start using `log/slog`.
* Update generated tests.
Signed-off-by: SuperQ <superq@gmail.com>
* Removeed go_memstat_lookups_total which was always set to 0; added runtime/metrics info to memstat metric helps.
I know we ideally should not remove any metric from default list, but
this one is always zero, so let's save everyone's money.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Update prometheus/go_collector.go
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
* go collector: add default metrics acceptance tests; adding more context to HELP
The context and details for help were possible thanks to @vesari research, thanks for that!
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Update prometheus/go_collector.go
Co-authored-by: Arianna Vespri <36129782+vesari@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Arianna Vespri <36129782+vesari@users.noreply.github.com>
* feat: Support zstd encoding
This allows endpoints to respond with zstd compressed metric data, if
the requester supports it.
I have imported a content-encoding parser from
https://github.com/golang/gddo which is an archived repository to
support different content-encoding headers.
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Update prometheus/promhttp/http.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Update prometheus/promhttp/http.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Update prometheus/promhttp/http.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Integrate review comments
* String typed enum
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Test with gzip compression
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Update prometheus/promhttp/http.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Reorder error handling
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Apply suggestions from code review
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
* Include review suggestions
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
---------
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
* testutil compareMetricFamilies: make less error-prone
The functions `GatherAndCompare`, `ScrapeAndCompare` and others that use
`compareMetricFamilies` under the hood can return no error if
`metricNames` includes none of the names found in the scraped/gathered
results. To avoid false Positves (an error being the negative case), we
can return an error if there is is at least one name in `metricNames`
that is not in the filtered results.
Fixes: https://github.com/prometheus/client_golang/issues/1351
Signed-off-by: leonnicolas <leonloechner@gmx.de>
* Add missing metricNames to error
In to see which metric names are missing, we can add them to the error
message.
Signed-off-by: leonnicolas <leonloechner@gmx.de>
* Apply suggestions from code review
- remove if nil check
- use two nested loops instead of map
- use new function `hasMetricByName` for readability
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: leonnicolas <60091705+leonnicolas@users.noreply.github.com>
* prometheus/testutil/testutil_test.go: compare complete error
Before we would only compare the error prefix in `TestScrapeAndCompare`.
Signed-off-by: leonnicolas <leonloechner@gmx.de>
---------
Signed-off-by: leonnicolas <leonloechner@gmx.de>
Signed-off-by: leonnicolas <60091705+leonnicolas@users.noreply.github.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
CollectAndFormat is a helper function that returns the formatted metrics
to the caller, allowing them to use it how they want. This is different
to CollectAndCompare where the comparison is done strictly on behalf of
the caller. Often it is more convenient to perform a simple substring
match on the formatted metric.
Signed-off-by: Jack Cassidy <j.cassidy45@gmail.com>
If the ResponseWriter implements any of the following methods,
the ResponseController will call them as appropriate:
Flush()
FlushError() error // alternative Flush returning an error
Hijack() (net.Conn, *bufio.ReadWriter, error)
SetReadDeadline(deadline time.Time) error
SetWriteDeadline(deadline time.Time) error
EnableFullDuplex() error
If the ResponseWriter doesn't implement the methods,
the ResponseController will call Unwrap() method until it
finds a ResponseWriter in the chain
This commit implements Unwrap() method to simply return the
wrapped ResponseWriter
Signed-off-by: Igor Drozdov <ihardrozdov@gmail.com>
Change the lintMetricTypeInName linter inside promlint to only trigger an error when the metric name matches the type of the metric.
Signed-off-by: foehammer127 <foehammer@disroot.org>
* Remove support for go 1.19
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
* Replace rand.Seed, deprecated in go 1.20
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
---------
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
* collectors/version: Move to collectors directory and remove unrelated code.
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
* examples: Add Version Collector example
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
---------
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
Due to an inconsistency in the text protocol between encoding and
decoding, it was not possible to use the testutil.CollectAndCompare
function to test metrics with empty help values. To fix this, normalize
empty help values from the expected/want side of the test so that they
compare correctly with empty values on the actual/got side of the test.
Signed-off-by: Billy Keyes <bluekeyes@gmail.com>
* Refactor promlint validation structure
Signed-off-by: João Vilaça <jvilaca@redhat.com>
* Add support for custom validations in promlint
Signed-off-by: João Vilaça <jvilaca@redhat.com>
* Keep backwards compatibility
Signed-off-by: João Vilaça <jvilaca@redhat.com>
---------
Signed-off-by: João Vilaça <jvilaca@redhat.com>
* proccess_collector: add wasip1 stub
This resolves build failures like this when using the wasip1 support:
# github.com/prometheus/procfs
../../../go/pkg/mod/github.com/prometheus/procfs@v0.11.1/fs_statfs_type.go:25:18: undefined: syscall.Statfs_t
../../../go/pkg/mod/github.com/prometheus/procfs@v0.11.1/fs_statfs_type.go:26:17: undefined: syscall.Statfs
See https://go.dev/blog/wasi.
Signed-off-by: Stephan Renatus <stephan@styra.com>
* add build tags
Signed-off-by: Stephan Renatus <stephan@styra.com>
---------
Signed-off-by: Stephan Renatus <stephan@styra.com>