Export custom metrics by defining a metrics.Sample slice with your metric names and calling metrics.Read to retrieve values. You can then format and send these values to your monitoring system.
import "runtime/metrics"
func getCustomMetrics() {
sample := []metrics.Sample{
{Name: "/custom/your_metric:bytes"},
}
metrics.Read(sample)
for _, s := range sample {
// Process s.Value (e.g., send to Prometheus)
}
}
Note: Custom metrics must be registered in your code using metrics.Register (if supported in your Go version) or rely on existing runtime metrics like /godebug/non-default-behavior/<name>:events for GODEBUG settings.