Compare commits

..

No commits in common. "master" and "v1.0.8" have entirely different histories.

4 changed files with 16 additions and 33 deletions

6
api.go
View File

@ -54,12 +54,6 @@ 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()

View File

@ -120,14 +120,7 @@ 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)
@ -156,6 +149,7 @@ 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 {

View File

@ -15,10 +15,9 @@ 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--"
)
type metricExporterHandler struct {
@ -42,6 +41,7 @@ func dumpMetricExporterPusher() error {
}
func InitMetrics(instanceValue string) {
var instance = instanceValue
if instanceValue == "" {
instance = getInstanceIpAddress()
} else if ap := strings.Split(instanceValue, ":"); len(ap) == 2 &&
@ -54,7 +54,7 @@ func InitMetrics(instanceValue string) {
prometheus.CounterOpts{
Name: "api_requests_total",
Help: "How many HTTP requests processed",
//ConstLabels: prometheus.Labels{"instance": instance},
ConstLabels: prometheus.Labels{"instance": instance},
},
[]string{"api", "errcode", "appid"},
)
@ -63,14 +63,14 @@ func InitMetrics(instanceValue string) {
Name: "api_requests_summary",
Help: "The api request summary of cost.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
//ConstLabels: prometheus.Labels{"instance": instance},
ConstLabels: prometheus.Labels{"instance": instance},
},
[]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),
}
}
@ -90,11 +90,7 @@ func SetupMetricsExporterPusher(pushgateway string, jobname string) {
jobname = fmt.Sprintf("api-metrics-job-%s", getExeFilename())
}
var pusher = push.
New(pushgateway, jobname).
Grouping("instance", instance).
Gatherer(MetricRegistry)
var pusher = push.New(pushgateway, jobname).Gatherer(metricRegistry)
MetricExporterPusher = func() error {
RecordMetrics("push_metrics_to_prometheus", "0", "selfmonitoring", 1.0)
return pusher.Push()

View File

@ -47,7 +47,6 @@ type Handler interface {
type HandlerFunc func(*Context) error
type IRoutes interface {
GET(uri string, handler Handler)
POST(uri string, handler Handler)
}