Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
81c8e7f2
Commit
81c8e7f2
authored
Jun 17, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make PrometheusMetricsService be global
parent
328772dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
15 deletions
+16
-15
prometheus_metrics_service.cpp
src/brpc/builtin/prometheus_metrics_service.cpp
+3
-3
prometheus_metrics_service.h
src/brpc/builtin/prometheus_metrics_service.h
+1
-7
server_private_accessor.h
src/brpc/details/server_private_accessor.h
+2
-3
server.cpp
src/brpc/server.cpp
+4
-2
server.h
src/brpc/server.h
+1
-0
brpc_prometheus_metrics_unittest.cpp
test/brpc_prometheus_metrics_unittest.cpp
+5
-0
No files found.
src/brpc/builtin/prometheus_metrics_service.cpp
View file @
81c8e7f2
...
...
@@ -182,15 +182,15 @@ void PrometheusMetricsService::default_method(::google::protobuf::RpcController*
ClosureGuard
done_guard
(
done
);
Controller
*
cntl
=
static_cast
<
Controller
*>
(
cntl_base
);
cntl
->
http_response
().
set_content_type
(
"text/plain"
);
if
(
DumpPrometheusMetricsToIOBuf
(
_server
,
&
cntl
->
response_attachment
())
!=
0
)
{
if
(
DumpPrometheusMetricsToIOBuf
(
&
cntl
->
response_attachment
())
!=
0
)
{
cntl
->
SetFailed
(
"Fail to dump metrics"
);
return
;
}
}
int
DumpPrometheusMetricsToIOBuf
(
const
Server
*
server
,
butil
::
IOBuf
*
output
)
{
int
DumpPrometheusMetricsToIOBuf
(
butil
::
IOBuf
*
output
)
{
butil
::
IOBufBuilder
os
;
PrometheusMetricsDumper
dumper
(
&
os
,
brpc
::
ServerPrivateAccessor
(
server
).
Server
Prefix
());
PrometheusMetricsDumper
dumper
(
&
os
,
brpc
::
ServerPrivateAccessor
(
NULL
).
Prefix
());
const
int
ndump
=
bvar
::
Variable
::
dump_exposed
(
&
dumper
,
NULL
);
if
(
ndump
<
0
)
{
return
-
1
;
...
...
src/brpc/builtin/prometheus_metrics_service.h
View file @
81c8e7f2
...
...
@@ -24,19 +24,13 @@ namespace brpc {
class
PrometheusMetricsService
:
public
brpc_metrics
{
public
:
PrometheusMetricsService
(
Server
*
server
)
:
_server
(
server
)
{}
void
default_method
(
::
google
::
protobuf
::
RpcController
*
cntl_base
,
const
::
brpc
::
MetricsRequest
*
request
,
::
brpc
::
MetricsResponse
*
response
,
::
google
::
protobuf
::
Closure
*
done
)
override
;
private
:
Server
*
_server
;
};
int
DumpPrometheusMetricsToIOBuf
(
const
Server
*
server
,
butil
::
IOBuf
*
output
);
int
DumpPrometheusMetricsToIOBuf
(
butil
::
IOBuf
*
output
);
}
// namepace brpc
...
...
src/brpc/details/server_private_accessor.h
View file @
81c8e7f2
...
...
@@ -30,7 +30,6 @@ namespace brpc {
class
ServerPrivateAccessor
{
public
:
explicit
ServerPrivateAccessor
(
const
Server
*
svr
)
{
CHECK
(
svr
);
_server
=
svr
;
}
...
...
@@ -98,8 +97,8 @@ public:
RestfulMap
*
global_restful_map
()
const
{
return
_server
->
_global_restful_map
;
}
std
::
string
ServerPrefix
()
const
{
return
_server
->
Server
Prefix
();
}
std
::
string
Prefix
()
const
{
return
Server
::
Prefix
();
}
private
:
const
Server
*
_server
;
};
...
...
src/brpc/server.cpp
View file @
81c8e7f2
...
...
@@ -265,8 +265,10 @@ static bvar::Vector<unsigned, 2> GetSessionLocalDataCount(void* arg) {
return
v
;
}
std
::
string
Server
::
Prefix
()
{
return
"rpc_server"
;
}
std
::
string
Server
::
ServerPrefix
()
const
{
return
butil
::
string_printf
(
"
rpc_server_%d"
,
listen_address
().
port
);
return
butil
::
string_printf
(
"
%s_%d"
,
Prefix
().
c_str
()
,
listen_address
().
port
);
}
void
*
Server
::
UpdateDerivedVars
(
void
*
arg
)
{
...
...
@@ -484,7 +486,7 @@ int Server::AddBuiltinServices() {
LOG
(
ERROR
)
<<
"Fail to add ListService"
;
return
-
1
;
}
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
PrometheusMetricsService
(
this
)
))
{
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
PrometheusMetricsService
))
{
LOG
(
ERROR
)
<<
"Fail to add MetricsService"
;
return
-
1
;
}
...
...
src/brpc/server.h
View file @
81c8e7f2
...
...
@@ -579,6 +579,7 @@ friend class Controller;
const
ServiceProperty
*
FindServicePropertyByName
(
const
butil
::
StringPiece
&
name
)
const
;
static
std
::
string
Prefix
();
std
::
string
ServerPrefix
()
const
;
// Mapping from hostname to corresponding SSL_CTX
...
...
test/brpc_prometheus_metrics_unittest.cpp
View file @
81c8e7f2
...
...
@@ -40,6 +40,11 @@ TEST(PrometheusMetrics, sanity) {
ASSERT_EQ
(
0
,
server
.
AddService
(
&
echo_svc
,
brpc
::
SERVER_DOESNT_OWN_SERVICE
));
ASSERT_EQ
(
0
,
server
.
Start
(
"127.0.0.1:8614"
,
NULL
));
brpc
::
Server
server2
;
DummyEchoServiceImpl
echo_svc2
;
ASSERT_EQ
(
0
,
server2
.
AddService
(
&
echo_svc2
,
brpc
::
SERVER_DOESNT_OWN_SERVICE
));
ASSERT_EQ
(
0
,
server2
.
Start
(
"127.0.0.1:8615"
,
NULL
));
brpc
::
Channel
channel
;
brpc
::
ChannelOptions
channel_opts
;
channel_opts
.
protocol
=
"http"
;
...
...
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