Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e7b56c63
Commit
e7b56c63
authored
Sep 09, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech(metrics): move all request counters into one middleware
parent
583790e6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
14 deletions
+41
-14
pkg/api/common.go
+0
-3
pkg/cmd/grafana-server/web.go
+1
-0
pkg/metrics/metrics.go
+2
-0
pkg/middleware/middleware.go
+0
-11
pkg/middleware/request_metrics.go
+38
-0
No files found.
pkg/api/common.go
View file @
e7b56c63
...
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"net/http"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/setting"
"gopkg.in/macaron.v1"
...
...
@@ -88,10 +87,8 @@ func ApiError(status int, message string, err error) *NormalResponse {
switch
status
{
case
404
:
metrics
.
M_Api_Status_404
.
Inc
(
1
)
data
[
"message"
]
=
"Not Found"
case
500
:
metrics
.
M_Api_Status_500
.
Inc
(
1
)
data
[
"message"
]
=
"Internal Server Error"
}
...
...
pkg/cmd/grafana-server/web.go
View file @
e7b56c63
...
...
@@ -53,6 +53,7 @@ func newMacaron() *macaron.Macaron {
m
.
Use
(
middleware
.
GetContextHandler
())
m
.
Use
(
middleware
.
Sessioner
(
&
setting
.
SessionOptions
))
m
.
Use
(
middleware
.
RequestMetrics
())
return
m
}
...
...
pkg/metrics/metrics.go
View file @
e7b56c63
...
...
@@ -15,6 +15,7 @@ var (
M_Page_Status_404
Counter
M_Api_Status_500
Counter
M_Api_Status_404
Counter
M_Api_Status_200
Counter
M_Api_User_SignUpStarted
Counter
M_Api_User_SignUpCompleted
Counter
M_Api_User_SignUpInvite
Counter
...
...
@@ -57,6 +58,7 @@ func initMetricVars(settings *MetricSettings) {
M_Api_Status_500
=
RegCounter
(
"api.resp_status"
,
"code"
,
"500"
)
M_Api_Status_404
=
RegCounter
(
"api.resp_status"
,
"code"
,
"404"
)
M_Api_Status_200
=
RegCounter
(
"api.resp_status"
,
"code"
,
"200"
)
M_Api_User_SignUpStarted
=
RegCounter
(
"api.user.signup_started"
)
M_Api_User_SignUpCompleted
=
RegCounter
(
"api.user.signup_completed"
)
...
...
pkg/middleware/middleware.go
View file @
e7b56c63
...
...
@@ -208,15 +208,6 @@ func (ctx *Context) Handle(status int, title string, err error) {
}
}
switch
status
{
case
200
:
metrics
.
M_Page_Status_200
.
Inc
(
1
)
case
404
:
metrics
.
M_Page_Status_404
.
Inc
(
1
)
case
500
:
metrics
.
M_Page_Status_500
.
Inc
(
1
)
}
ctx
.
Data
[
"Title"
]
=
title
ctx
.
HTML
(
status
,
strconv
.
Itoa
(
status
))
}
...
...
@@ -243,10 +234,8 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
switch
status
{
case
404
:
metrics
.
M_Api_Status_404
.
Inc
(
1
)
resp
[
"message"
]
=
"Not Found"
case
500
:
metrics
.
M_Api_Status_500
.
Inc
(
1
)
resp
[
"message"
]
=
"Internal Server Error"
}
...
...
pkg/middleware/request_metrics.go
0 → 100644
View file @
e7b56c63
package
middleware
import
(
"net/http"
"strings"
"github.com/grafana/grafana/pkg/metrics"
"gopkg.in/macaron.v1"
)
func
RequestMetrics
()
macaron
.
Handler
{
return
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
,
c
*
macaron
.
Context
)
{
rw
:=
res
.
(
macaron
.
ResponseWriter
)
c
.
Next
()
status
:=
rw
.
Status
()
if
strings
.
HasPrefix
(
req
.
URL
.
Path
,
"/api/"
)
{
switch
status
{
case
200
:
metrics
.
M_Api_Status_200
.
Inc
(
1
)
case
404
:
metrics
.
M_Api_Status_404
.
Inc
(
1
)
case
500
:
metrics
.
M_Api_Status_500
.
Inc
(
1
)
}
}
else
{
switch
status
{
case
200
:
metrics
.
M_Page_Status_200
.
Inc
(
1
)
case
404
:
metrics
.
M_Page_Status_404
.
Inc
(
1
)
case
500
:
metrics
.
M_Page_Status_500
.
Inc
(
1
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment