Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
0
Merge Requests
0
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
caddy
Commits
426d1652
Commit
426d1652
authored
Mar 21, 2016
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expvar: Allow no args; publish number of goroutines
parent
a3127bed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
9 deletions
+32
-9
caddy/setup/expvar.go
caddy/setup/expvar.go
+22
-3
caddy/setup/expvar_test.go
caddy/setup/expvar_test.go
+9
-6
dist/CHANGES.txt
dist/CHANGES.txt
+1
-0
No files found.
caddy/setup/expvar.go
View file @
426d1652
package
setup
import
(
_
"expvar"
stdexpvar
"expvar"
"runtime"
"sync"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/expvar"
...
...
@@ -14,6 +16,9 @@ func ExpVar(c *Controller) (middleware.Middleware, error) {
return
nil
,
err
}
// publish any extra information/metrics we may want to capture
publishExtraVars
()
expvar
:=
expvar
.
ExpVar
{
Resource
:
resource
}
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
...
...
@@ -24,12 +29,13 @@ func ExpVar(c *Controller) (middleware.Middleware, error) {
func
expVarParse
(
c
*
Controller
)
(
expvar
.
Resource
,
error
)
{
var
resource
expvar
.
Resource
var
err
error
for
c
.
Next
()
{
args
:=
c
.
RemainingArgs
()
switch
len
(
args
)
{
case
0
:
resource
=
expvar
.
Resource
(
defaultExpvarPath
)
case
1
:
resource
=
expvar
.
Resource
(
args
[
0
])
default
:
...
...
@@ -39,3 +45,16 @@ func expVarParse(c *Controller) (expvar.Resource, error) {
return
resource
,
err
}
func
publishExtraVars
()
{
// By using sync.Once instead of an init() function, we don't clutter
// the app's expvar export unnecessarily, or risk colliding with it.
publishOnce
.
Do
(
func
()
{
stdexpvar
.
Publish
(
"Goroutines"
,
stdexpvar
.
Func
(
func
()
interface
{}
{
return
runtime
.
NumGoroutine
()
}))
})
}
var
publishOnce
sync
.
Once
// publishing variables should only be done once
var
defaultExpvarPath
=
"/debug/vars"
caddy/setup/expvar_test.go
View file @
426d1652
...
...
@@ -7,29 +7,32 @@ import (
)
func
TestExpvar
(
t
*
testing
.
T
)
{
c
:=
NewTestController
(
`expvar /d/v`
)
c
:=
NewTestController
(
`expvar`
)
mid
,
err
:=
ExpVar
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, got: %v"
,
err
)
}
if
mid
==
nil
{
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
c
=
NewTestController
(
`expvar /d/v`
)
mid
,
err
=
ExpVar
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, got: %v"
,
err
)
}
if
mid
==
nil
{
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
EmptyNext
)
myHandler
,
ok
:=
handler
.
(
expvar
.
ExpVar
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type ExpVar, got: %#v"
,
handler
)
}
if
myHandler
.
Resource
!=
"/d/v"
{
t
.
Errorf
(
"Expected /d/v as expvar resource"
)
}
if
!
SameNext
(
myHandler
.
Next
,
EmptyNext
)
{
t
.
Error
(
"'Next' field of handler was not set properly"
)
}
...
...
dist/CHANGES.txt
View file @
426d1652
...
...
@@ -2,6 +2,7 @@ CHANGES
<master>
- New pprof directive for exposing process performance profile
- New expvar directive for reading memory/GC performance
- New -restart option to force in-process restarts on Unix systems
- Toggle case-sensitive path matching with environment variable
- proxy: New max_conns setting to limit max connections per upstream
...
...
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