Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
72bd3f60
Commit
72bd3f60
authored
Jan 22, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add metrics.PrometheusCollectorsFromFields
parent
b8f4faa2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
25 deletions
+26
-25
metrics.go
pkg/api/metrics.go
+3
-12
metrics.go
pkg/metrics/metrics.go
+20
-0
metrics.go
pkg/pingpong/metrics.go
+3
-13
No files found.
pkg/api/metrics.go
View file @
72bd3f60
...
...
@@ -2,9 +2,9 @@ package api
import
(
"net/http"
"reflect"
"time"
m
"github.com/janos/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
...
...
@@ -35,17 +35,8 @@ func newMetrics() (m metrics) {
}
}
func
(
s
*
server
)
Metrics
()
(
cs
[]
prometheus
.
Collector
)
{
v
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
s
.
metrics
))
for
i
:=
0
;
i
<
v
.
NumField
();
i
++
{
if
!
v
.
Field
(
i
)
.
CanInterface
()
{
continue
}
if
u
,
ok
:=
v
.
Field
(
i
)
.
Interface
()
.
(
prometheus
.
Collector
);
ok
{
cs
=
append
(
cs
,
u
)
}
}
return
cs
func
(
s
*
server
)
Metrics
()
[]
prometheus
.
Collector
{
return
m
.
PrometheusCollectorsFromFields
(
s
.
metrics
)
}
func
(
s
*
server
)
pageviewMetricsHandler
(
h
http
.
Handler
)
http
.
Handler
{
...
...
pkg/metrics/metrics.go
0 → 100644
View file @
72bd3f60
package
metrics
import
(
"reflect"
"github.com/prometheus/client_golang/prometheus"
)
func
PrometheusCollectorsFromFields
(
i
interface
{})
(
cs
[]
prometheus
.
Collector
)
{
v
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
i
))
for
i
:=
0
;
i
<
v
.
NumField
();
i
++
{
if
!
v
.
Field
(
i
)
.
CanInterface
()
{
continue
}
if
u
,
ok
:=
v
.
Field
(
i
)
.
Interface
()
.
(
prometheus
.
Collector
);
ok
{
cs
=
append
(
cs
,
u
)
}
}
return
cs
}
pkg/pingpong/metrics.go
View file @
72bd3f60
package
pingpong
import
(
"reflect"
m
"github.com/janos/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
...
...
@@ -37,15 +36,6 @@ func newMetrics() (m metrics) {
}
}
func
(
s
*
Service
)
Metrics
()
(
cs
[]
prometheus
.
Collector
)
{
v
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
s
.
metrics
))
for
i
:=
0
;
i
<
v
.
NumField
();
i
++
{
if
!
v
.
Field
(
i
)
.
CanInterface
()
{
continue
}
if
u
,
ok
:=
v
.
Field
(
i
)
.
Interface
()
.
(
prometheus
.
Collector
);
ok
{
cs
=
append
(
cs
,
u
)
}
}
return
cs
func
(
s
*
Service
)
Metrics
()
[]
prometheus
.
Collector
{
return
m
.
PrometheusCollectorsFromFields
(
s
.
metrics
)
}
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