2018-08-22 13:08:52 +03:00
|
|
|
// Copyright 2018 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-12-11 02:01:46 +03:00
|
|
|
package prometheus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
2015-04-30 07:27:14 +03:00
|
|
|
"runtime/debug"
|
2015-05-05 02:20:11 +03:00
|
|
|
"time"
|
2014-12-11 02:01:46 +03:00
|
|
|
)
|
|
|
|
|
2022-08-05 20:37:46 +03:00
|
|
|
// goRuntimeMemStats provides the metrics initially provided by runtime.ReadMemStats.
|
|
|
|
// From Go 1.17 those similar (and better) statistics are provided by runtime/metrics, so
|
|
|
|
// while eval closure works on runtime.MemStats, the struct from Go 1.17+ is
|
|
|
|
// populated using runtime/metrics.
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
func goRuntimeMemStats() memStatsMetrics {
|
|
|
|
return memStatsMetrics{
|
|
|
|
{
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("alloc_bytes"),
|
|
|
|
"Number of bytes allocated and still in use.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.Alloc) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("alloc_bytes_total"),
|
|
|
|
"Total number of bytes allocated, even if freed.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.TotalAlloc) },
|
|
|
|
valType: CounterValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("sys_bytes"),
|
|
|
|
"Number of bytes obtained from system.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.Sys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("lookups_total"),
|
|
|
|
"Total number of pointer lookups.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.Lookups) },
|
|
|
|
valType: CounterValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("mallocs_total"),
|
|
|
|
"Total number of mallocs.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.Mallocs) },
|
|
|
|
valType: CounterValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("frees_total"),
|
|
|
|
"Total number of frees.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.Frees) },
|
|
|
|
valType: CounterValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_alloc_bytes"),
|
|
|
|
"Number of heap bytes allocated and still in use.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapAlloc) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_sys_bytes"),
|
|
|
|
"Number of heap bytes obtained from system.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_idle_bytes"),
|
|
|
|
"Number of heap bytes waiting to be used.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapIdle) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_inuse_bytes"),
|
|
|
|
"Number of heap bytes that are in use.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapInuse) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_released_bytes"),
|
|
|
|
"Number of heap bytes released to OS.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapReleased) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("heap_objects"),
|
|
|
|
"Number of allocated objects.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapObjects) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("stack_inuse_bytes"),
|
|
|
|
"Number of bytes in use by the stack allocator.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackInuse) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("stack_sys_bytes"),
|
|
|
|
"Number of bytes obtained from system for stack allocator.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("mspan_inuse_bytes"),
|
|
|
|
"Number of bytes in use by mspan structures.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanInuse) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("mspan_sys_bytes"),
|
|
|
|
"Number of bytes used for mspan structures obtained from system.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("mcache_inuse_bytes"),
|
|
|
|
"Number of bytes in use by mcache structures.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheInuse) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("mcache_sys_bytes"),
|
|
|
|
"Number of bytes used for mcache structures obtained from system.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("buck_hash_sys_bytes"),
|
|
|
|
"Number of bytes used by the profiling bucket hash table.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.BuckHashSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("gc_sys_bytes"),
|
|
|
|
"Number of bytes used for garbage collection system metadata.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.GCSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("other_sys_bytes"),
|
|
|
|
"Number of bytes used for other system allocations.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.OtherSys) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
}, {
|
|
|
|
desc: NewDesc(
|
|
|
|
memstatNamespace("next_gc_bytes"),
|
|
|
|
"Number of heap bytes when next garbage collection will take place.",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
eval: func(ms *runtime.MemStats) float64 { return float64(ms.NextGC) },
|
|
|
|
valType: GaugeValue,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type baseGoCollector struct {
|
2017-02-15 08:06:22 +03:00
|
|
|
goroutinesDesc *Desc
|
|
|
|
threadsDesc *Desc
|
|
|
|
gcDesc *Desc
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
gcLastTimeDesc *Desc
|
2017-07-24 00:36:09 +03:00
|
|
|
goInfoDesc *Desc
|
2015-07-21 06:55:38 +03:00
|
|
|
}
|
|
|
|
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
func newBaseGoCollector() baseGoCollector {
|
|
|
|
return baseGoCollector{
|
2017-02-15 08:06:22 +03:00
|
|
|
goroutinesDesc: NewDesc(
|
|
|
|
"go_goroutines",
|
|
|
|
"Number of goroutines that currently exist.",
|
|
|
|
nil, nil),
|
|
|
|
threadsDesc: NewDesc(
|
|
|
|
"go_threads",
|
2017-07-24 00:36:09 +03:00
|
|
|
"Number of OS threads created.",
|
2017-02-15 08:06:22 +03:00
|
|
|
nil, nil),
|
2015-07-21 18:24:22 +03:00
|
|
|
gcDesc: NewDesc(
|
|
|
|
"go_gc_duration_seconds",
|
2020-01-06 15:36:51 +03:00
|
|
|
"A summary of the pause duration of garbage collection cycles.",
|
2015-07-21 18:24:22 +03:00
|
|
|
nil, nil),
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
gcLastTimeDesc: NewDesc(
|
2022-08-05 20:37:46 +03:00
|
|
|
"go_memstats_last_gc_time_seconds",
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
"Number of seconds since 1970 of last garbage collection.",
|
|
|
|
nil, nil),
|
2017-07-24 00:36:09 +03:00
|
|
|
goInfoDesc: NewDesc(
|
|
|
|
"go_info",
|
|
|
|
"Information about the Go environment.",
|
|
|
|
nil, Labels{"version": runtime.Version()}),
|
2015-07-21 06:55:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 18:24:22 +03:00
|
|
|
// Describe returns all descriptions of the collector.
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
func (c *baseGoCollector) Describe(ch chan<- *Desc) {
|
2017-02-15 08:06:22 +03:00
|
|
|
ch <- c.goroutinesDesc
|
|
|
|
ch <- c.threadsDesc
|
2015-07-21 18:24:22 +03:00
|
|
|
ch <- c.gcDesc
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
ch <- c.gcLastTimeDesc
|
2017-07-24 00:36:09 +03:00
|
|
|
ch <- c.goInfoDesc
|
2015-07-21 06:55:38 +03:00
|
|
|
}
|
|
|
|
|
2015-07-21 18:24:22 +03:00
|
|
|
// Collect returns the current state of all metrics of the collector.
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
func (c *baseGoCollector) Collect(ch chan<- Metric) {
|
2017-02-15 08:06:22 +03:00
|
|
|
ch <- MustNewConstMetric(c.goroutinesDesc, GaugeValue, float64(runtime.NumGoroutine()))
|
2022-08-05 17:28:54 +03:00
|
|
|
|
|
|
|
n := getRuntimeNumThreads()
|
|
|
|
ch <- MustNewConstMetric(c.threadsDesc, GaugeValue, n)
|
2015-07-21 18:24:22 +03:00
|
|
|
|
|
|
|
var stats debug.GCStats
|
|
|
|
stats.PauseQuantiles = make([]time.Duration, 5)
|
|
|
|
debug.ReadGCStats(&stats)
|
|
|
|
|
|
|
|
quantiles := make(map[float64]float64)
|
|
|
|
for idx, pq := range stats.PauseQuantiles[1:] {
|
|
|
|
quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds()
|
2015-07-21 06:55:38 +03:00
|
|
|
}
|
2015-07-21 18:24:22 +03:00
|
|
|
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
2018-04-13 23:59:56 +03:00
|
|
|
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles)
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
ch <- MustNewConstMetric(c.gcLastTimeDesc, GaugeValue, float64(stats.LastGC.UnixNano())/1e9)
|
2017-07-24 00:36:09 +03:00
|
|
|
ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1)
|
2019-05-04 02:00:59 +03:00
|
|
|
}
|
|
|
|
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
func memstatNamespace(s string) string {
|
|
|
|
return "go_memstats_" + s
|
2015-07-22 06:29:02 +03:00
|
|
|
}
|
|
|
|
|
Use the runtime/metrics package for the Go collector for 1.17+ (#955)
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
2022-01-16 19:41:56 +03:00
|
|
|
// memStatsMetrics provide description, evaluator, runtime/metrics name, and
|
|
|
|
// value type for memstat metrics.
|
2015-07-22 06:29:02 +03:00
|
|
|
type memStatsMetrics []struct {
|
|
|
|
desc *Desc
|
|
|
|
eval func(*runtime.MemStats) float64
|
|
|
|
valType ValueType
|
|
|
|
}
|