Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
9f5e081a
Commit
9f5e081a
authored
Apr 06, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some monitoring refactoring
parent
be80bf51
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
middleware/prometheus/handler.go
middleware/prometheus/handler.go
+7
-5
middleware/prometheus/metrics.go
middleware/prometheus/metrics.go
+1
-1
middleware/recorder.go
middleware/recorder.go
+6
-2
No files found.
middleware/prometheus/handler.go
View file @
9f5e081a
package
metrics
package
metrics
import
(
import
(
"strconv"
"time"
"time"
"golang.org/x/net/context"
"golang.org/x/net/context"
...
@@ -12,7 +11,6 @@ import (
...
@@ -12,7 +11,6 @@ import (
func
(
m
Metrics
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
func
(
m
Metrics
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
state
:=
middleware
.
State
{
W
:
w
,
Req
:
r
}
state
:=
middleware
.
State
{
W
:
w
,
Req
:
r
}
qname
:=
state
.
Name
()
qname
:=
state
.
Name
()
qtype
:=
state
.
Type
()
qtype
:=
state
.
Type
()
zone
:=
middleware
.
Zones
(
m
.
ZoneNames
)
.
Matches
(
qname
)
zone
:=
middleware
.
Zones
(
m
.
ZoneNames
)
.
Matches
(
qname
)
...
@@ -24,10 +22,14 @@ func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -24,10 +22,14 @@ func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
rw
:=
middleware
.
NewResponseRecorder
(
w
)
rw
:=
middleware
.
NewResponseRecorder
(
w
)
status
,
err
:=
m
.
Next
.
ServeDNS
(
ctx
,
rw
,
r
)
status
,
err
:=
m
.
Next
.
ServeDNS
(
ctx
,
rw
,
r
)
m
.
Report
(
zone
,
qtype
,
rw
)
return
status
,
err
}
func
(
m
Metrics
)
Report
(
zone
,
qtype
string
,
rw
*
middleware
.
ResponseRecorder
)
{
requestCount
.
WithLabelValues
(
zone
,
qtype
)
.
Inc
()
requestCount
.
WithLabelValues
(
zone
,
qtype
)
.
Inc
()
requestDuration
.
WithLabelValues
(
zone
,
qtype
)
.
Observe
(
float64
(
time
.
Since
(
rw
.
Start
())
/
time
.
Second
))
requestDuration
.
WithLabelValues
(
zone
,
qtype
)
.
Observe
(
float64
(
time
.
Since
(
rw
.
Start
())
/
time
.
Second
))
responseSize
.
WithLabelValues
(
zone
,
qtype
)
.
Observe
(
float64
(
rw
.
Size
()))
responseSize
.
WithLabelValues
(
zone
,
qtype
)
.
Observe
(
float64
(
rw
.
Size
()))
responseRcode
.
WithLabelValues
(
zone
,
strconv
.
Itoa
(
rw
.
Rcode
()),
qtype
)
.
Inc
()
responseRcode
.
WithLabelValues
(
zone
,
rw
.
Rcode
(),
qtype
)
.
Inc
()
return
status
,
err
}
}
middleware/prometheus/metrics.go
View file @
9f5e081a
...
@@ -62,7 +62,7 @@ func define(subsystem string) {
...
@@ -62,7 +62,7 @@ func define(subsystem string) {
Namespace
:
namespace
,
Namespace
:
namespace
,
Subsystem
:
subsystem
,
Subsystem
:
subsystem
,
Name
:
"request_duration_seconds"
,
Name
:
"request_duration_seconds"
,
Buckets
:
append
([]
float64
{
0
,
0001
,
0.0005
,
0.001
,
0
.0025
},
prometheus
.
DefBuckets
...
),
Buckets
:
append
([]
float64
{
.0001
,
.0005
,
.001
,
.0025
},
prometheus
.
DefBuckets
...
),
Help
:
"Histogram of the time (in seconds) each request took."
,
Help
:
"Histogram of the time (in seconds) each request took."
,
},
[]
string
{
"zone"
,
"qtype"
})
},
[]
string
{
"zone"
,
"qtype"
})
...
...
middleware/recorder.go
View file @
9f5e081a
package
middleware
package
middleware
import
(
import
(
"strconv"
"time"
"time"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -58,8 +59,11 @@ func (r *ResponseRecorder) Size() int {
...
@@ -58,8 +59,11 @@ func (r *ResponseRecorder) Size() int {
}
}
// Rcode returns the rcode.
// Rcode returns the rcode.
func
(
r
*
ResponseRecorder
)
Rcode
()
int
{
func
(
r
*
ResponseRecorder
)
Rcode
()
string
{
return
r
.
rcode
if
rcode
,
ok
:=
dns
.
RcodeToString
[
r
.
rcode
];
ok
{
return
rcode
}
return
"RCODE"
+
strconv
.
Itoa
(
r
.
rcode
)
}
}
// Start returns the start time of the ResponseRecorder.
// Start returns the start time of the ResponseRecorder.
...
...
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