2019-08-06 18:53:14 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"runtime"
|
|
|
|
"time"
|
|
|
|
|
2019-11-27 18:12:39 +02:00
|
|
|
"github.com/micro/go-micro/debug/log"
|
|
|
|
|
2019-08-06 18:53:14 +02:00
|
|
|
proto "github.com/micro/go-micro/debug/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-11-26 19:04:44 +02:00
|
|
|
// DefaultHandler is default debug handler
|
2019-08-06 18:53:14 +02:00
|
|
|
DefaultHandler = newDebug()
|
|
|
|
)
|
|
|
|
|
2019-11-26 19:04:44 +02:00
|
|
|
type Debug struct {
|
|
|
|
started int64
|
2019-11-27 18:12:39 +02:00
|
|
|
log.Logger
|
2019-11-26 19:04:44 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 18:53:14 +02:00
|
|
|
func newDebug() *Debug {
|
|
|
|
return &Debug{
|
|
|
|
started: time.Now().Unix(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Debug) Health(ctx context.Context, req *proto.HealthRequest, rsp *proto.HealthResponse) error {
|
|
|
|
rsp.Status = "ok"
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.StatsResponse) error {
|
|
|
|
var mstat runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&mstat)
|
|
|
|
|
|
|
|
rsp.Started = uint64(d.started)
|
|
|
|
rsp.Uptime = uint64(time.Now().Unix() - d.started)
|
|
|
|
rsp.Memory = mstat.Alloc
|
|
|
|
rsp.Gc = mstat.PauseTotalNs
|
|
|
|
rsp.Threads = uint64(runtime.NumGoroutine())
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-26 17:39:55 +02:00
|
|
|
|
2019-11-26 19:04:44 +02:00
|
|
|
func (d *Debug) Log(ctx context.Context, req *proto.LogRequest, rsp proto.Debug_LogStream) error {
|
2019-11-26 17:39:55 +02:00
|
|
|
return nil
|
|
|
|
}
|