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
c4ae795c
Commit
c4ae795c
authored
Jun 14, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
customize brpc metrics path
parent
29de815d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
13 deletions
+31
-13
prometheus_metrics_service.cpp
src/brpc/builtin/prometheus_metrics_service.cpp
+7
-4
prometheus_metrics_service.h
src/brpc/builtin/prometheus_metrics_service.h
+5
-5
builtin_service.proto
src/brpc/builtin_service.proto
+2
-2
server.cpp
src/brpc/server.cpp
+10
-1
server.h
src/brpc/server.h
+2
-0
brpc_prometheus_metrics_unittest.cpp
test/brpc_prometheus_metrics_unittest.cpp
+5
-1
No files found.
src/brpc/builtin/prometheus_metrics_service.cpp
View file @
c4ae795c
...
...
@@ -32,6 +32,9 @@ DECLARE_int32(bvar_latency_p3);
namespace
brpc
{
DEFINE_string
(
prometheus_metrics_path
,
"/metrics"
,
"The HTTP resource "
"path from which prometheus fetch metrics."
);
// This is a class that convert bvar result to prometheus output.
// Currently the output only includes gauge and summary for two
// reasons:
...
...
@@ -174,10 +177,10 @@ bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix(
return
true
;
}
void
PrometheusMetricsService
::
default_method
(
::
google
::
protobuf
::
RpcController
*
cntl_base
,
const
::
brpc
::
MetricsRequest
*
,
::
brpc
::
MetricsResponse
*
,
::
google
::
protobuf
::
Closure
*
done
)
{
void
PrometheusMetricsService
::
metrics
(
::
google
::
protobuf
::
RpcController
*
cntl_base
,
const
::
brpc
::
MetricsRequest
*
,
::
brpc
::
MetricsResponse
*
,
::
google
::
protobuf
::
Closure
*
done
)
{
ClosureGuard
done_guard
(
done
);
Controller
*
cntl
=
static_cast
<
Controller
*>
(
cntl_base
);
cntl
->
http_response
().
set_content_type
(
"text/plain"
);
...
...
src/brpc/builtin/prometheus_metrics_service.h
View file @
c4ae795c
...
...
@@ -22,15 +22,15 @@
namespace
brpc
{
class
PrometheusMetricsService
:
public
b
rpc_vars_metric
s
{
class
PrometheusMetricsService
:
public
b
var
s
{
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
;
void
metrics
(
::
google
::
protobuf
::
RpcController
*
cntl_base
,
const
::
brpc
::
MetricsRequest
*
request
,
::
brpc
::
MetricsResponse
*
response
,
::
google
::
protobuf
::
Closure
*
done
)
override
;
private
:
Server
*
_server
;
};
...
...
src/brpc/builtin_service.proto
View file @
c4ae795c
...
...
@@ -97,8 +97,8 @@ service sockets {
rpc
default_method
(
SocketsRequest
)
returns
(
SocketsResponse
);
}
service
b
rpc_vars_metric
s
{
rpc
default_method
(
MetricsRequest
)
returns
(
MetricsResponse
);
service
b
var
s
{
rpc
metrics
(
MetricsRequest
)
returns
(
MetricsResponse
);
}
service
badmethod
{
...
...
src/brpc/server.cpp
View file @
c4ae795c
...
...
@@ -110,6 +110,7 @@ DEFINE_bool(enable_threads_service, false, "Enable /threads");
DECLARE_int32
(
usercode_backup_threads
);
DECLARE_bool
(
usercode_in_pthread
);
DECLARE_string
(
prometheus_metrics_path
);
const
int
INITIAL_SERVICE_CAP
=
64
;
const
int
INITIAL_CERT_MAP
=
64
;
...
...
@@ -484,7 +485,10 @@ int Server::AddBuiltinServices() {
LOG
(
ERROR
)
<<
"Fail to add ListService"
;
return
-
1
;
}
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
PrometheusMetricsService
(
this
)))
{
ServiceOptions
options
;
options
.
ownership
=
SERVER_OWNS_SERVICE
;
options
.
restful_mappings
=
FLAGS_prometheus_metrics_path
+
" => metrics"
;
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
PrometheusMetricsService
(
this
),
options
))
{
LOG
(
ERROR
)
<<
"Fail to add MetricsService"
;
return
-
1
;
}
...
...
@@ -1411,6 +1415,11 @@ int Server::AddService(google::protobuf::Service* service,
int
Server
::
AddBuiltinService
(
google
::
protobuf
::
Service
*
service
)
{
ServiceOptions
options
;
options
.
ownership
=
SERVER_OWNS_SERVICE
;
return
AddBuiltinService
(
service
,
options
);
}
int
Server
::
AddBuiltinService
(
google
::
protobuf
::
Service
*
service
,
const
ServiceOptions
&
options
)
{
return
AddServiceInternal
(
service
,
true
,
options
);
}
...
...
src/brpc/server.h
View file @
c4ae795c
...
...
@@ -530,6 +530,8 @@ friend class Controller;
const
ServiceOptions
&
options
);
int
AddBuiltinService
(
google
::
protobuf
::
Service
*
service
);
int
AddBuiltinService
(
google
::
protobuf
::
Service
*
service
,
const
ServiceOptions
&
options
);
// Remove all methods of `service' from internal structures.
void
RemoveMethodsOf
(
google
::
protobuf
::
Service
*
service
);
...
...
test/brpc_prometheus_metrics_unittest.cpp
View file @
c4ae795c
...
...
@@ -10,6 +10,10 @@
#include "butil/strings/string_piece.h"
#include "echo.pb.h"
namespace
brpc
{
DECLARE_string
(
prometheus_metrics_path
);
}
// brpc
int
main
(
int
argc
,
char
*
argv
[])
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
...
...
@@ -45,7 +49,7 @@ TEST(PrometheusMetrics, sanity) {
channel_opts
.
protocol
=
"http"
;
ASSERT_EQ
(
0
,
channel
.
Init
(
"127.0.0.1:8614"
,
&
channel_opts
));
brpc
::
Controller
cntl
;
cntl
.
http_request
().
uri
()
=
"/brpc_vars_metrics"
;
cntl
.
http_request
().
uri
()
=
brpc
::
FLAGS_prometheus_metrics_path
;
channel
.
CallMethod
(
NULL
,
&
cntl
,
NULL
,
NULL
,
NULL
);
ASSERT_FALSE
(
cntl
.
Failed
());
std
::
string
res
=
cntl
.
response_attachment
().
to_string
();
...
...
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