Skip to content

Commit be8b1b9

Browse files
chundonglinlinwinlinvipduiniuluantanqin
committed
API: Support server/pid/service label for exporter and api. (#3385)
* Exporter: Support server/pid/service.(#3378) * API: Support return server/pid/service.(#3378) * Use 8-length service id. * Update release v5.0.135 v6.0.16 PICK 02653ce Co-authored-by: winlin <[email protected]> Co-authored-by: Haibo Chen <[email protected]>
1 parent 9bf45be commit be8b1b9

7 files changed

+66
-2
lines changed

trunk/doc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The changelog for SRS.
88

99
## SRS 5.0 Changelog
1010

11+
* v5.0, 2023-01-17, Merge [#3385](https://github.com/ossrs/srs/pull/3385): API: Support server/pid/service label for exporter and api. v5.0.135 (#3385)
1112
* v5.0, 2023-01-17, Merge [#3383](https://github.com/ossrs/srs/pull/3383): GB: Fix PSM parsing indicator bug. v5.0.134 (#3383)
1213
* v5.0, 2023-01-08, Merge [#3308](https://github.com/ossrs/srs/pull/3308): DVR: Improve file write performance by fwrite with cache. v5.0.133
1314
* v5.0, 2023-01-06, DVR: Support blackbox test based on hooks. v5.0.132

trunk/src/app/srs_app_config.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@ srs_error_t SrsConfig::check_normal_config()
26062606

26072607
// TODO: FIXME: remove it in future.
26082608
if (m == "hls_storage" || m == "hls_mount") {
2609-
srs_warn("HLS RAM is removed in SRS3+, read https://github.com/ossrs/srs/issues/513.");
2609+
srs_warn("HLS RAM is removed in SRS3+");
26102610
}
26112611
}
26122612
} else if (n == "http_hooks") {

trunk/src/app/srs_app_http_api.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
184184

185185
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
186186
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
187+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
188+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
187189

188190
SrsJsonObject* urls = SrsJsonAny::object();
189191
obj->set("urls", urls);
@@ -222,6 +224,8 @@ srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
222224

223225
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
224226
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
227+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
228+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
225229

226230
SrsJsonObject* urls = SrsJsonAny::object();
227231
obj->set("urls", urls);
@@ -248,6 +252,8 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
248252

249253
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
250254
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
255+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
256+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
251257

252258
SrsJsonObject* urls = SrsJsonAny::object();
253259
obj->set("urls", urls);
@@ -297,6 +303,8 @@ srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
297303

298304
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
299305
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
306+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
307+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
300308

301309
SrsJsonObject* data = SrsJsonAny::object();
302310
obj->set("data", data);
@@ -326,6 +334,8 @@ srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
326334

327335
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
328336
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
337+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
338+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
329339

330340
srs_api_dump_summaries(obj);
331341

@@ -349,6 +359,8 @@ srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
349359

350360
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
351361
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
362+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
363+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
352364

353365
SrsJsonObject* data = SrsJsonAny::object();
354366
obj->set("data", data);
@@ -394,6 +406,8 @@ srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHtt
394406

395407
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
396408
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
409+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
410+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
397411

398412
SrsJsonObject* data = SrsJsonAny::object();
399413
obj->set("data", data);
@@ -471,6 +485,8 @@ srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsH
471485

472486
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
473487
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
488+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
489+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
474490

475491
SrsJsonObject* data = SrsJsonAny::object();
476492
obj->set("data", data);
@@ -510,6 +526,8 @@ srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
510526

511527
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
512528
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
529+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
530+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
513531

514532
SrsJsonObject* data = SrsJsonAny::object();
515533
obj->set("data", data);
@@ -550,6 +568,8 @@ srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
550568

551569
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
552570
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
571+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
572+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
553573

554574
SrsJsonObject* data = SrsJsonAny::object();
555575
obj->set("data", data);
@@ -577,6 +597,8 @@ srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
577597

578598
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
579599
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
600+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
601+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
580602

581603
SrsJsonObject* data = SrsJsonAny::object();
582604
obj->set("data", data);
@@ -645,6 +667,8 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
645667

646668
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
647669
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
670+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
671+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
648672

649673
SrsJsonObject* data = SrsJsonAny::object();
650674
obj->set("data", data);
@@ -700,6 +724,8 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
700724

701725
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
702726
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
727+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
728+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
703729

704730
if (r->is_http_get()) {
705731
if (!vhost) {
@@ -756,6 +782,8 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
756782

757783
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
758784
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
785+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
786+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
759787

760788
if (r->is_http_get()) {
761789
if (!stream) {
@@ -816,6 +844,8 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
816844

817845
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
818846
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
847+
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
848+
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
819849

820850
if (r->is_http_get()) {
821851
if (!client) {
@@ -1121,6 +1151,9 @@ srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
11211151
ss << "# HELP srs_build_info A metric with a constant '1' value labeled by build_date, version from which SRS was built.\n"
11221152
<< "# TYPE srs_build_info gauge\n"
11231153
<< "srs_build_info{"
1154+
<< "server=\"" << stat->server_id() << "\","
1155+
<< "service=\"" << stat->service_id() << "\","
1156+
<< "pid=\"" << stat->service_pid() << "\","
11241157
<< "build_date=\"" << SRS_BUILD_DATE << "\","
11251158
<< "major=\"" << VERSION_MAJOR << "\","
11261159
<< "version=\"" << RTMP_SIG_SRS_VERSION << "\","

trunk/src/app/srs_app_rtc_api.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
170170

171171
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
172172
res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
173+
res->set("service", SrsJsonAny::str(SrsStatistic::instance()->service_id().c_str()));
174+
res->set("pid", SrsJsonAny::str(SrsStatistic::instance()->service_pid().c_str()));
173175

174176
// TODO: add candidates in response json?
175177
res->set("sdp", SrsJsonAny::str(ruc.local_sdp_str_.c_str()));
@@ -451,6 +453,8 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
451453

452454
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
453455
res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
456+
res->set("service", SrsJsonAny::str(SrsStatistic::instance()->service_id().c_str()));
457+
res->set("pid", SrsJsonAny::str(SrsStatistic::instance()->service_pid().c_str()));
454458

455459
// TODO: add candidates in response json?
456460
res->set("sdp", SrsJsonAny::str(ruc.local_sdp_str_.c_str()));

trunk/src/app/srs_app_statistic.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,24 @@ std::string SrsStatistic::server_id()
543543
return server_id_;
544544
}
545545

546+
std::string SrsStatistic::service_id()
547+
{
548+
if (service_id_.empty()) {
549+
service_id_ = srs_random_str(8);
550+
}
551+
552+
return service_id_;
553+
}
554+
555+
std::string SrsStatistic::service_pid()
556+
{
557+
if (service_pid_.empty()) {
558+
service_pid_ = srs_int2str(getpid());
559+
}
560+
561+
return service_pid_;
562+
}
563+
546564
srs_error_t SrsStatistic::dumps_vhosts(SrsJsonArray* arr)
547565
{
548566
srs_error_t err = srs_success;

trunk/src/app/srs_app_statistic.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ class SrsStatistic
122122
static SrsStatistic *_instance;
123123
// The id to identify the sever.
124124
std::string server_id_;
125+
// The id to identify the service.
126+
std::string service_id_;
127+
// The pid to identify the service process.
128+
std::string service_pid_;
125129
private:
126130
// The key: vhost id, value: vhost object.
127131
std::map<std::string, SrsStatisticVhost*> vhosts;
@@ -196,6 +200,10 @@ class SrsStatistic
196200
// Get the server id, used to identify the server.
197201
// For example, when restart, the server id must changed.
198202
virtual std::string server_id();
203+
// Get the service id, used to identify the restart of service.
204+
virtual std::string service_id();
205+
// Get the service pid, used to identify the service process.
206+
virtual std::string service_pid();
199207
// Dumps the vhosts to amf0 array.
200208
virtual srs_error_t dumps_vhosts(SrsJsonArray* arr);
201209
// Dumps the streams to amf0 array.

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 134
12+
#define VERSION_REVISION 135
1313

1414
#endif

0 commit comments

Comments
 (0)