From bd8b7a88a708901fe59c0adc4273a4871e491e0e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 10 Mar 2021 12:01:18 +0200 Subject: [PATCH] lib/httpserver: export `vm_available_memory_bytes` and `vm_available_cpu_cores` metrics These metrics are useful for tracking the available memory and CPU cores for VictoriaMetrics apps. --- docs/CHANGELOG.md | 1 + lib/httpserver/metrics.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd48af9e8..b574ded3d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,7 @@ - `histogram_stdvar(buckets)` - returns standard variance for the given buckets. - `histogram_stddev(buckets)` - returns standard deviation for the given buckets. * FEATURE: reduce median query duration by up to 2x. See https://github.com/VictoriaMetrics/VictoriaMetrics/commit/18fe0ff14bc78860c5569e2b70de1db78fac61be +* FEATURE: export `vm_available_memory_bytes` and `vm_available_cpu_cores` metrics, which show the number of available RAM and available CPU cores for VictoriaMetrics apps. * FEATURE: vmagent: add ability to replicate scrape targets among `vmagent` instances in the cluster with `-promscrape.cluster.replicationFactor` command-line flag. See [these docs](https://victoriametrics.github.io/vmagent.html#scraping-big-number-of-targets). * FATURE: vmagent: accept `scrape_offset` option at `scrape_config`. This option may be useful when scrapes must start at the specified offset of every scrape interval. See [these docs](https://victoriametrics.github.io/vmagent.html#troubleshooting) for details. * FEATURE: vmauth: allow using regexp paths in `url_map`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1112) for details. diff --git a/lib/httpserver/metrics.go b/lib/httpserver/metrics.go index 281bd0ba2..a14603710 100644 --- a/lib/httpserver/metrics.go +++ b/lib/httpserver/metrics.go @@ -12,6 +12,7 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup" "github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/memory" "github.com/VictoriaMetrics/metrics" @@ -48,6 +49,8 @@ func writePrometheusMetrics(w io.Writer) { fmt.Fprintf(w, "vm_app_version{version=%q, short_version=%q} 1\n", buildinfo.Version, versionRe.FindString(buildinfo.Version)) fmt.Fprintf(w, "vm_allowed_memory_bytes %d\n", memory.Allowed()) + fmt.Fprintf(w, "vm_available_memory_bytes %d\n", memory.Allowed()+memory.Remaining()) + fmt.Fprintf(w, "vm_available_cpu_cores %d\n", cgroup.AvailableCPUs()) // Export start time and uptime in seconds fmt.Fprintf(w, "vm_app_start_timestamp %d\n", startTime.Unix())