client_golang/prometheus
Matt Harbison 25bda7ceb5
process_collector: fill in virtual and resident memory values on macOS using optional cgo (#1616)
Unfortunately, these values aren't available from getrusage(2), or any other
builtin Go API.  Go itself doesn't provide a mechanism (like on Windows) to call
into system libraries.  Using a 3rd party package[1] to dynamically call system
libraries was proposed and rejected, to avoid adding to the number of
dependencies.  That leaves using cgo, which is used here when available.  When
not available (either because of cross compiling or explicitly disabling it), a
stub function is linked instead, and the metrics are not exported.  That way,
cross compiling of other platforms is unaffected (and can also still be done
with Darwin too, but at the cost of not exporting these metrics).

Note that building an amd64 image on an arm64 mac or vice-versa is cross
compiling, and will use the stub method by default.  This can be avoided by
setting `CGO_ENABLED=1` in the environment to force the use of cgo for both
architectures.

I'm unsure of the usefulness of the potential adjustment made to the virtual
memory value after calling `mach_vm_region()`.  I've not seen that code get run
with a native amd64 or arm64 image, or with an amd64 image running under
Rosetta.  But that's what the `ps(1)` command does, and I think we should report
what the system tools do.

When I was testing this on a beta of macOS 15 with Go 1.21.13 (the current
minimum support for this module), the amd64 image ran fine under Rosetta, but
the arm64 image immediately printed a message that it was killed, even prior to
the cgo call.  This seems to be a recurring issue on macOS[2][3], and passing
`-ldflags -s` to `go build` avoided the issue.  Go 1.23.1 worked out of the box,
without fiddling with linker flags, so I don't think this is an issue- Go 1.21
is simply too old to support macOS 15, but I thought it was worth noting.  I
supposed we could gate the cgo code with an additional build flag, if anyone is
concerned about this.

[1] https://github.com/ebitengine/purego
[2] https://github.com/golang/go/issues/19841#issuecomment-293334802
[3] https://github.com/golang/go/issues/11887#issuecomment-125694604

Signed-off-by: Matt Harbison <mharbison72@gmail.com>
2024-09-27 17:29:44 +01:00
..
collectors Refactor default runtime metrics tests for Go collector so that default runtime metric set autogenerates (#1631) 2024-09-23 14:55:38 +01:00
graphite Update linting 2024-08-30 18:09:51 +02:00
internal changed the name of all variables with min/max name (#1606) 2024-09-02 07:41:40 -03:00
promauto docs: trivial grammar fixes to improve readability 2023-08-05 11:41:47 +01:00
promhttp fix: Unset Content-Encoding header when uncompressed 2024-08-23 18:53:42 +02:00
push deps: bump prometheus/common version 2024-02-23 13:28:17 -05:00
testutil Set allow-utf-8 in Format during tests to avoid escaping. 2024-09-05 15:16:46 -04:00
.gitignore Rearrange file and package per convention. 2013-04-04 15:27:09 +02:00
README.md Update status badgets 2021-06-23 10:12:43 +02:00
benchmark_test.go Do not allocate memory when there's no constraints (#1296) 2023-06-27 12:21:36 +01:00
build_info_collector.go Use the runtime/metrics package for the Go collector for 1.17+ (#955) 2022-01-16 16:41:56 +00:00
collector.go collectors.GoCollector: Added rule support for granular metric configuration. (#1102) 2022-08-05 19:37:46 +02:00
collector_test.go Enable same linters as the Prometheus repo itself (#1056) 2022-06-17 09:04:06 +02:00
counter.go Fix typos in comments, tests, and errors (#1346) 2023-09-21 12:31:08 +01:00
counter_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
desc.go Do not allocate memory when there's no constraints (#1296) 2023-06-27 12:21:36 +01:00
desc_test.go Add missing license headers 2018-08-22 13:53:56 +02:00
doc.go Indent example in godoc consistently (#1226) 2023-03-01 16:45:01 +00:00
example_clustermanager_test.go Nitpicking a doc comment 2018-11-20 13:41:38 +01:00
example_metricvec_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
example_timer_complex_test.go Enable same linters as the Prometheus repo itself (#1056) 2022-06-17 09:04:06 +02:00
example_timer_gauge_test.go Enable same linters as the Prometheus repo itself (#1056) 2022-06-17 09:04:06 +02:00
example_timer_test.go Enable same linters as the Prometheus repo itself (#1056) 2022-06-17 09:04:06 +02:00
examples_test.go Allow creating constant histogram and summary metrics with a created timestamp (#1537) 2024-07-01 17:35:47 -03:00
expvar_collector.go Do not allocate memory when there's no constraints (#1296) 2023-06-27 12:21:36 +01:00
expvar_collector_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
fnv.go Add missing license headers 2018-08-22 13:53:56 +02:00
gauge.go Fix typos in comments, tests, and errors (#1346) 2023-09-21 12:31:08 +01:00
gauge_test.go Bump prometheus/client_model (#1323) 2023-08-11 20:17:55 +01:00
gen_go_collector_metrics_set.go Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads (#1559) 2024-08-09 20:27:25 +01:00
get_pid.go Fix build against GopherJS (#897) 2022-08-05 16:28:54 +02:00
get_pid_gopherjs.go Fix build against GopherJS (#897) 2022-08-05 16:28:54 +02:00
go_collector.go Remove go_memstat_lookups_total; added runtime/metrics calculation to memstat metric's help. (#1577) 2024-08-14 12:11:51 +00:00
go_collector_go116.go gocollector: Added options to Go Collector for changing the (#1031) 2022-04-13 09:55:22 +01:00
go_collector_go116_test.go Use the runtime/metrics package for the Go collector for 1.17+ (#955) 2022-01-16 16:41:56 +00:00
go_collector_latest.go gocollector: Tiny fix for help message with runtime/metrics source. 2024-08-16 09:58:24 +01:00
go_collector_latest_test.go Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads (#1559) 2024-08-09 20:27:25 +01:00
go_collector_metrics_go120_test.go Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads (#1559) 2024-08-09 20:27:25 +01:00
go_collector_metrics_go121_test.go Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads (#1559) 2024-08-09 20:27:25 +01:00
go_collector_metrics_go122_test.go Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads (#1559) 2024-08-09 20:27:25 +01:00
go_collector_metrics_go123_test.go Update supported Go versions 2024-08-31 22:47:31 +02:00
go_collector_test.go Use simpler locking in the Go 1.17 collector (#975) 2022-01-25 08:43:45 +01:00
histogram.go Merge pull request #1627 from prometheus/release-1.20 2024-09-17 10:39:34 +02:00
histogram_test.go native histogram: use exemplars in concurrency test 2024-09-04 21:10:22 +02:00
labels.go Improve performance of WithLabelValues(...) 2023-10-04 18:09:15 +02:00
metric.go clean code use time.IsZero() replace t = time.Time{}, make code more readable 2024-05-15 22:05:50 +08:00
metric_test.go Replace deprecated github.com/golang/protobuf package (#1183) 2022-12-22 16:14:00 +01:00
num_threads.go Fix build against GopherJS (#897) 2022-08-05 16:28:54 +02:00
num_threads_gopherjs.go Fix build against GopherJS (#897) 2022-08-05 16:28:54 +02:00
observer.go Update documentation for exemplar label limit (#1095) 2022-07-27 17:45:49 +02:00
process_collector.go bugfix: Pass network metrics to processCollector's Describe() function 2024-08-20 11:44:35 +01:00
process_collector_cgo_darwin.c process_collector: fill in virtual and resident memory values on macOS using optional cgo (#1616) 2024-09-27 17:29:44 +01:00
process_collector_cgo_darwin.go process_collector: fill in virtual and resident memory values on macOS using optional cgo (#1616) 2024-09-27 17:29:44 +01:00
process_collector_darwin.go process_collector: fill in virtual and resident memory values on macOS using optional cgo (#1616) 2024-09-27 17:29:44 +01:00
process_collector_js.go Fix build against GopherJS (#897) 2022-08-05 16:28:54 +02:00
process_collector_nocgo_darwin.go process_collector: fill in virtual and resident memory values on macOS using optional cgo (#1616) 2024-09-27 17:29:44 +01:00
process_collector_other.go process_collector: fill in most statistics on macOS (#1600) 2024-09-04 15:56:01 +01:00
process_collector_test.go Use NewPedanticRegistry in Process' Collector tests 2024-08-20 11:44:35 +01:00
process_collector_wasip1.go proccess_collector: add wasip1 stub (#1350) 2023-10-10 09:46:36 +01:00
process_collector_windows.go feat: Change processMemoryCounters struct uint declaration to uintptr 2020-04-13 10:44:09 +08:00
process_collector_windows_test.go Implement process collector for Windows (#596) 2019-06-14 12:26:55 +02:00
registry.go improved code more clean (#1511) 2024-05-09 10:34:07 +01:00
registry_test.go Set allow-utf-8 in Format during tests to avoid escaping. 2024-09-05 15:16:46 -04:00
summary.go Allow creating constant histogram and summary metrics with a created timestamp (#1537) 2024-07-01 17:35:47 -03:00
summary_test.go changed the name of all variables with min/max name (#1606) 2024-09-02 07:41:40 -03:00
timer.go timer: Added support for exemplars. (#1233) 2023-03-21 19:35:31 +00:00
timer_test.go timer: Added support for exemplars. (#1233) 2023-03-21 19:35:31 +00:00
untyped.go Remove the deprecated uses of Untyped metrics 2017-08-29 17:31:45 +02:00
utils_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
value.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
value_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00
vec.go chore: fix function name in comment (#1497) 2024-04-11 14:53:09 +02:00
vec_test.go Reduce constrainLabels allocations (#1272) 2023-06-07 08:39:02 +01:00
vnext.go Add constrained labels and Constrained variant for all MetricVecs (#1151) 2022-12-13 13:47:52 +01:00
wrap.go Replace deprecated github.com/golang/protobuf package (#1183) 2022-12-22 16:14:00 +01:00
wrap_test.go Extend Counters, Summaries and Histograms with creation timestamp (#1313) 2023-09-21 10:46:54 +01:00

README.md

See Go Reference.