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
ef1a8604
Commit
ef1a8604
authored
Jun 23, 2016
by
Miek Gieben
Committed by
GitHub
Jun 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more metrics (#176)
parent
2fe42067
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
16 deletions
+52
-16
middleware/log/log.go
middleware/log/log.go
+1
-1
middleware/metrics/README.md
middleware/metrics/README.md
+6
-3
middleware/metrics/handler.go
middleware/metrics/handler.go
+17
-5
middleware/metrics/metrics.go
middleware/metrics/metrics.go
+24
-4
server/server.go
server/server.go
+4
-3
No files found.
middleware/log/log.go
View file @
ef1a8604
...
...
@@ -38,7 +38,7 @@ func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
answer
.
SetRcode
(
r
,
rcode
)
state
.
SizeAndDo
(
answer
)
metrics
.
Report
(
metrics
.
Dropped
,
state
.
Proto
()
,
rc
,
answer
.
Len
(),
time
.
Now
())
metrics
.
Report
(
state
,
metrics
.
Dropped
,
rc
,
answer
.
Len
(),
time
.
Now
())
w
.
WriteMsg
(
answer
)
}
rcode
=
0
...
...
middleware/metrics/README.md
View file @
ef1a8604
...
...
@@ -7,13 +7,16 @@ The following metrics are exported:
*
coredns_dns_request_count_total
*
coredns_dns_request_duration_seconds
*
coredns_dns_request_size_bytes
*
coredns_dns_request_do_count_total
*
coredns_dns_response_size_bytes
*
coredns_dns_response_rcode_count_total
Each counter has a label
`zone`
which is the zonename used for the request/response. and a label
`qtype`
which old the query type. The
`dns_request_count_total`
has an extra label
`proto`
which
holds the transport of the response ("udp" or "tcp"). The
`response_rcode_count_total`
has an extra
label
`rcode`
which holds the rcode of the response.
`qtype`
which old the query type. The
`dns_request_count_total`
has extra labels:
`proto`
which
holds the transport of the response ("udp" or "tcp") and the address family of the transport (1
= IP (IP version 4), 2 = IP6 (IP version 6)).
The
`response_rcode_count_total`
has an extra label
`rcode`
which holds the rcode of the response.
If monitoring is enabled queries that do not enter the middleware chain are exported under the fake
domain "dropped" (without a closing dot).
...
...
middleware/metrics/handler.go
View file @
ef1a8604
...
...
@@ -11,8 +11,8 @@ import (
func
(
m
Metrics
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
state
:=
middleware
.
State
{
W
:
w
,
Req
:
r
}
qname
:=
state
.
Name
()
net
:=
state
.
Proto
()
qname
:=
state
.
QName
()
zone
:=
middleware
.
Zones
(
m
.
ZoneNames
)
.
Matches
(
qname
)
if
zone
==
""
{
zone
=
"."
...
...
@@ -22,21 +22,33 @@ func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
rw
:=
middleware
.
NewResponseRecorder
(
w
)
status
,
err
:=
m
.
Next
.
ServeDNS
(
ctx
,
rw
,
r
)
Report
(
zone
,
net
,
rw
.
Rcode
(),
rw
.
Size
(),
rw
.
Start
())
Report
(
state
,
zone
,
rw
.
Rcode
(),
rw
.
Size
(),
rw
.
Start
())
return
status
,
err
}
// Report is a plain reporting function that the server can use for REFUSED and other
// queries that are turned down because they don't match any middleware.
func
Report
(
zone
,
net
,
rcode
string
,
size
int
,
start
time
.
Time
)
{
func
Report
(
state
middleware
.
State
,
zone
,
rcode
string
,
size
int
,
start
time
.
Time
)
{
if
requestCount
==
nil
{
// no metrics are enabled
return
}
requestCount
.
WithLabelValues
(
zone
,
net
)
.
Inc
()
// Proto and Family
net
:=
state
.
Proto
()
fam
:=
"1"
if
state
.
Family
()
==
2
{
fam
=
"2"
}
requestCount
.
WithLabelValues
(
zone
,
net
,
fam
)
.
Inc
()
requestDuration
.
WithLabelValues
(
zone
)
.
Observe
(
float64
(
time
.
Since
(
start
)
/
time
.
Second
))
requestSize
.
WithLabelValues
(
zone
)
.
Observe
(
float64
(
state
.
Size
()))
if
state
.
Do
()
{
requestDo
.
WithLabelValues
(
zone
)
.
Inc
()
}
responseSize
.
WithLabelValues
(
zone
)
.
Observe
(
float64
(
size
))
responseRcode
.
WithLabelValues
(
zone
,
rcode
)
.
Inc
()
}
middleware/metrics/metrics.go
View file @
ef1a8604
...
...
@@ -14,8 +14,11 @@ import (
var
(
requestCount
*
prometheus
.
CounterVec
requestDuration
*
prometheus
.
HistogramVec
responseSize
*
prometheus
.
HistogramVec
responseRcode
*
prometheus
.
CounterVec
requestSize
*
prometheus
.
HistogramVec
requestDo
*
prometheus
.
CounterVec
responseSize
*
prometheus
.
HistogramVec
responseRcode
*
prometheus
.
CounterVec
)
// Metrics holds the prometheus configuration. The metrics' path is fixed to be /metrics
...
...
@@ -42,6 +45,8 @@ func (m *Metrics) Start() error {
prometheus
.
MustRegister
(
requestCount
)
prometheus
.
MustRegister
(
requestDuration
)
prometheus
.
MustRegister
(
requestSize
)
prometheus
.
MustRegister
(
requestDo
)
prometheus
.
MustRegister
(
responseSize
)
prometheus
.
MustRegister
(
responseRcode
)
...
...
@@ -66,8 +71,8 @@ func define() {
Namespace
:
middleware
.
Namespace
,
Subsystem
:
subsystem
,
Name
:
"request_count_total"
,
Help
:
"Counter of DNS requests made per zone
and protocol
."
,
},
[]
string
{
"zone"
,
"proto"
})
Help
:
"Counter of DNS requests made per zone
, protocol and family
."
,
},
[]
string
{
"zone"
,
"proto"
,
"family"
})
requestDuration
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
middleware
.
Namespace
,
...
...
@@ -77,6 +82,21 @@ func define() {
Help
:
"Histogram of the time (in seconds) each request took."
,
},
[]
string
{
"zone"
})
requestSize
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
middleware
.
Namespace
,
Subsystem
:
subsystem
,
Name
:
"request_buffer_size_bytes"
,
Help
:
"Size of the EDNS0 UDP buffer in bytes (64K for TCP)."
,
Buckets
:
[]
float64
{
0
,
100
,
200
,
300
,
400
,
511
,
1023
,
2047
,
4095
,
8291
,
16e3
,
32e3
,
48e3
,
64e3
},
},
[]
string
{
"zone"
})
requestDo
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
middleware
.
Namespace
,
Subsystem
:
subsystem
,
Name
:
"request_do_count_total"
,
Help
:
"Counter of DNS requests with DO bit set per zone."
,
},
[]
string
{
"zone"
})
responseSize
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
middleware
.
Namespace
,
Subsystem
:
subsystem
,
...
...
server/server.go
View file @
ef1a8604
...
...
@@ -329,8 +329,9 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
if
m
,
err
:=
middleware
.
Edns0Version
(
r
);
err
!=
nil
{
// Wrong EDNS version, return at once.
rc
:=
middleware
.
RcodeToString
(
dns
.
RcodeBadVers
)
// TODO(miek): hardcoded "udp" here.
metrics
.
Report
(
metrics
.
Dropped
,
"udp"
,
rc
,
m
.
Len
(),
time
.
Now
())
state
:=
middleware
.
State
{
W
:
w
,
Req
:
r
}
metrics
.
Report
(
state
,
metrics
.
Dropped
,
rc
,
m
.
Len
(),
time
.
Now
())
w
.
WriteMsg
(
m
)
return
}
...
...
@@ -393,7 +394,7 @@ func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int) {
answer
.
SetRcode
(
r
,
rcode
)
state
.
SizeAndDo
(
answer
)
metrics
.
Report
(
metrics
.
Dropped
,
state
.
Proto
()
,
rc
,
answer
.
Len
(),
time
.
Now
())
metrics
.
Report
(
state
,
metrics
.
Dropped
,
rc
,
answer
.
Len
(),
time
.
Now
())
w
.
WriteMsg
(
answer
)
}
...
...
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