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
ad1596aa
Commit
ad1596aa
authored
Jun 17, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add DumpPrometheusMetricsToIOBuf
parent
6aa2d593
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
prometheus_metrics_service.cpp
src/brpc/builtin/prometheus_metrics_service.cpp
+12
-4
prometheus_metrics_service.h
src/brpc/builtin/prometheus_metrics_service.h
+3
-0
server_private_accessor.h
src/brpc/details/server_private_accessor.h
+2
-0
No files found.
src/brpc/builtin/prometheus_metrics_service.cpp
View file @
ad1596aa
...
...
@@ -22,6 +22,7 @@
#include "brpc/closure_guard.h" // ClosureGuard
#include "brpc/builtin/prometheus_metrics_service.h"
#include "brpc/builtin/common.h"
#include "brpc/details/server_private_accessor.h"
#include "bvar/bvar.h"
namespace
bvar
{
...
...
@@ -181,14 +182,21 @@ 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
)
{
cntl
->
SetFailed
(
"Fail to dump metrics"
);
return
;
}
}
int
DumpPrometheusMetricsToIOBuf
(
const
Server
*
server
,
butil
::
IOBuf
*
output
)
{
butil
::
IOBufBuilder
os
;
PrometheusMetricsDumper
dumper
(
&
os
,
_server
->
ServerPrefix
());
PrometheusMetricsDumper
dumper
(
&
os
,
brpc
::
ServerPrivateAccessor
(
server
).
ServerPrefix
());
const
int
ndump
=
bvar
::
Variable
::
dump_exposed
(
&
dumper
,
NULL
);
if
(
ndump
<
0
)
{
cntl
->
SetFailed
(
"Fail to dump metrics"
);
return
;
return
-
1
;
}
os
.
move_to
(
cntl
->
response_attachment
());
os
.
move_to
(
*
output
);
return
0
;
}
}
// namespace brpc
src/brpc/builtin/prometheus_metrics_service.h
View file @
ad1596aa
...
...
@@ -31,10 +31,13 @@ public:
const
::
brpc
::
MetricsRequest
*
request
,
::
brpc
::
MetricsResponse
*
response
,
::
google
::
protobuf
::
Closure
*
done
)
override
;
private
:
Server
*
_server
;
};
int
DumpPrometheusMetricsToIOBuf
(
const
Server
*
server
,
butil
::
IOBuf
*
output
);
}
// namepace brpc
#endif // BRPC_PROMETHEUS_METRICS_SERVICE_H
src/brpc/details/server_private_accessor.h
View file @
ad1596aa
...
...
@@ -97,6 +97,8 @@ public:
RestfulMap
*
global_restful_map
()
const
{
return
_server
->
_global_restful_map
;
}
std
::
string
ServerPrefix
()
const
{
return
_server
->
ServerPrefix
();
}
private
:
const
Server
*
_server
;
...
...
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