Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
a7db87e3
Commit
a7db87e3
authored
Nov 24, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track total and active requests
parent
b48dca47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
internal/helper/logging.go
internal/helper/logging.go
+7
-0
internal/metrics/metrics.go
internal/metrics/metrics.go
+24
-0
No files found.
internal/helper/logging.go
View file @
a7db87e3
...
...
@@ -6,7 +6,10 @@ import (
"log"
"net/http"
"os"
"strconv"
"time"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/metrics"
)
var
responseLogger
*
log
.
Logger
...
...
@@ -27,6 +30,7 @@ type LoggingResponseWriter struct {
}
func
NewLoggingResponseWriter
(
rw
http
.
ResponseWriter
)
LoggingResponseWriter
{
metrics
.
RequestsActive
.
Inc
()
return
LoggingResponseWriter
{
rw
:
rw
,
started
:
time
.
Now
(),
...
...
@@ -62,4 +66,7 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
fmt
.
Sprintf
(
"%s %s %s"
,
r
.
Method
,
r
.
RequestURI
,
r
.
Proto
),
l
.
status
,
l
.
written
,
r
.
Referer
(),
r
.
UserAgent
(),
duration
.
Seconds
(),
)
metrics
.
RequestsActive
.
Dec
()
metrics
.
RequestsTotal
.
WithLabelValues
(
strconv
.
Itoa
(
l
.
status
),
r
.
Method
)
.
Inc
()
}
internal/metrics/metrics.go
0 → 100644
View file @
a7db87e3
package
metrics
import
(
"github.com/prometheus/client_golang/prometheus"
)
var
(
RequestsActive
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"http_requests_active"
,
Help
:
"Number of HTTP requests currently being handled."
,
})
RequestsTotal
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"http_requests_total"
,
Help
:
"How many HTTP requests processed, partitioned by status code and HTTP method."
,
},
[]
string
{
"code"
,
"method"
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
RequestsActive
)
prometheus
.
MustRegister
(
RequestsTotal
)
}
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