mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 10:04:18 +02:00
forgot to push
This commit is contained in:
55
pkg/printer/metrics.go
Normal file
55
pkg/printer/metrics.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2026 Thomas von Dein
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package printer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime/metrics"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printGoRoutineMetrics() {
|
||||||
|
fmt.Println("\nGoroutine metrics:")
|
||||||
|
printMetric("/sched/goroutines-created:goroutines", "Created")
|
||||||
|
printMetric("/sched/goroutines:goroutines", "Live")
|
||||||
|
printMetric("/sched/goroutines/not-in-go:goroutines", "Syscall/CGO")
|
||||||
|
printMetric("/sched/goroutines/runnable:goroutines", "Runnable")
|
||||||
|
printMetric("/sched/goroutines/running:goroutines", "Running")
|
||||||
|
printMetric("/sched/goroutines/waiting:goroutines", "Waiting")
|
||||||
|
|
||||||
|
fmt.Println("Thread metrics:")
|
||||||
|
printMetric("/sched/gomaxprocs:threads", "Max")
|
||||||
|
printMetric("/sched/threads/total:threads", "Live")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printMetric(name string, descr string) {
|
||||||
|
sample := []metrics.Sample{{Name: name}}
|
||||||
|
metrics.Read(sample)
|
||||||
|
|
||||||
|
var val string
|
||||||
|
|
||||||
|
switch sample[0].Value.Kind() {
|
||||||
|
case metrics.KindFloat64, metrics.KindFloat64Histogram:
|
||||||
|
val = fmt.Sprintf("%.2f", sample[0].Value.Float64())
|
||||||
|
case metrics.KindUint64:
|
||||||
|
val = strconv.FormatUint(sample[0].Value.Uint64(), 10)
|
||||||
|
case metrics.KindBad:
|
||||||
|
val = "n/a"
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf(" %s: %v\n", descr, val)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user