Compare commits
4 Commits
Author | Date | ||
---|---|---|---|
![]() |
98eac47127 | ||
![]() |
69b0fb05aa | ||
![]() |
ba9357e166 | ||
![]() |
9df516247c |
6
api.go
6
api.go
@ -54,6 +54,12 @@ func (e *Engine) POST(uri string, handler Handler) {
|
||||
e.Engine.POST(uri, h)
|
||||
}
|
||||
|
||||
func (e *Engine) GET(uri string, handler Handler) {
|
||||
h := handlerWrapper(handler)
|
||||
log.Infof("api handler [%v] registor success", handler)
|
||||
e.Engine.GET(uri, h)
|
||||
}
|
||||
|
||||
// handlerWrapper
|
||||
func handlerWrapper(handler Handler) gin.HandlerFunc {
|
||||
handlerFunc := handler.HandlerFunc()
|
||||
|
@ -120,7 +120,14 @@ func (c *Context) SetCookie(cookie *http.Cookie) {
|
||||
http.SetCookie(c.Writer, cookie)
|
||||
}
|
||||
|
||||
func (c *Context) AlreadyHaveResult() (done bool, entry string) {
|
||||
return c.resultentry != "", c.resultentry
|
||||
}
|
||||
|
||||
func (c *Context) RESULT(output interface{}) error {
|
||||
if c.resultentry == "" {
|
||||
c.resultentry = "RESULT"
|
||||
}
|
||||
var t = reflect.TypeOf(output)
|
||||
defer func(o *interface{}) {
|
||||
b, err := json.Marshal(o)
|
||||
@ -149,7 +156,6 @@ func (c *Context) RESULT(output interface{}) error {
|
||||
cost := time.Now().Sub(c.starttime).Milliseconds()
|
||||
noticeStr := fmt.Sprintf("cost: %dms, output: '%s'", cost, string(b))
|
||||
log.NoticefWithDepth(calldepth, noticeStr)
|
||||
|
||||
}(&output)
|
||||
|
||||
if _, ok := t.FieldByName("ErrCode"); !ok {
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
var (
|
||||
MetricExporterPusher = func() error { return nil }
|
||||
MetricExporterHandler Handler = nil
|
||||
metricRegistry *prometheus.Registry = nil
|
||||
MetricRegistry *prometheus.Registry = nil
|
||||
metricApiCounter *prometheus.CounterVec = nil
|
||||
metricApiSummary *prometheus.SummaryVec = nil
|
||||
instance string = "--unknown--"
|
||||
@ -68,9 +68,9 @@ func InitMetrics(instanceValue string) {
|
||||
[]string{"api", "errcode", "appid"},
|
||||
)
|
||||
|
||||
metricRegistry = prometheus.NewRegistry()
|
||||
metricRegistry.MustRegister(metricApiCounter)
|
||||
metricRegistry.MustRegister(metricApiSummary)
|
||||
MetricRegistry = prometheus.NewRegistry()
|
||||
MetricRegistry.MustRegister(metricApiCounter)
|
||||
MetricRegistry.MustRegister(metricApiSummary)
|
||||
}
|
||||
|
||||
func SetupMetricsExporterHandler(apiname string) {
|
||||
@ -78,10 +78,10 @@ func SetupMetricsExporterHandler(apiname string) {
|
||||
apiname = "premetheus_metrics_exporter"
|
||||
}
|
||||
|
||||
opt := promhttp.HandlerOpts{Registry: metricRegistry}
|
||||
opt := promhttp.HandlerOpts{Registry: MetricRegistry}
|
||||
MetricExporterHandler = &metricExporterHandler{
|
||||
name: apiname,
|
||||
promhttpHandler: promhttp.HandlerFor(metricRegistry, opt),
|
||||
promhttpHandler: promhttp.HandlerFor(MetricRegistry, opt),
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func SetupMetricsExporterPusher(pushgateway string, jobname string) {
|
||||
var pusher = push.
|
||||
New(pushgateway, jobname).
|
||||
Grouping("instance", instance).
|
||||
Gatherer(metricRegistry)
|
||||
Gatherer(MetricRegistry)
|
||||
|
||||
MetricExporterPusher = func() error {
|
||||
RecordMetrics("push_metrics_to_prometheus", "0", "selfmonitoring", 1.0)
|
||||
|
Loading…
Reference in New Issue
Block a user