mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	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 02653ce2aa
Co-authored-by: winlin <winlin@vip.126.com>
Co-authored-by: Haibo Chen <495810242@qq.com>
			
			
This commit is contained in:
		
							parent
							
								
									9bf45bea01
								
							
						
					
					
						commit
						be8b1b94a6
					
				
					 7 changed files with 66 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -8,6 +8,7 @@ The changelog for SRS.
 | 
			
		|||
 | 
			
		||||
## SRS 5.0 Changelog
 | 
			
		||||
 | 
			
		||||
* 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)
 | 
			
		||||
* v5.0, 2023-01-17, Merge [#3383](https://github.com/ossrs/srs/pull/3383): GB: Fix PSM parsing indicator bug. v5.0.134 (#3383)
 | 
			
		||||
* 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
 | 
			
		||||
* v5.0, 2023-01-06, DVR: Support blackbox test based on hooks. v5.0.132
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2606,7 +2606,7 @@ srs_error_t SrsConfig::check_normal_config()
 | 
			
		|||
                    
 | 
			
		||||
                    // TODO: FIXME: remove it in future.
 | 
			
		||||
                    if (m == "hls_storage" || m == "hls_mount") {
 | 
			
		||||
                        srs_warn("HLS RAM is removed in SRS3+, read https://github.com/ossrs/srs/issues/513.");
 | 
			
		||||
                        srs_warn("HLS RAM is removed in SRS3+");
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else if (n == "http_hooks") {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -184,6 +184,8 @@ srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* urls = SrsJsonAny::object();
 | 
			
		||||
    obj->set("urls", urls);
 | 
			
		||||
| 
						 | 
				
			
			@ -222,6 +224,8 @@ srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* urls = SrsJsonAny::object();
 | 
			
		||||
    obj->set("urls", urls);
 | 
			
		||||
| 
						 | 
				
			
			@ -248,6 +252,8 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* urls = SrsJsonAny::object();
 | 
			
		||||
    obj->set("urls", urls);
 | 
			
		||||
| 
						 | 
				
			
			@ -297,6 +303,8 @@ srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -326,6 +334,8 @@ srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    srs_api_dump_summaries(obj);
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -349,6 +359,8 @@ srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -394,6 +406,8 @@ srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHtt
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -471,6 +485,8 @@ srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsH
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -510,6 +526,8 @@ srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -550,6 +568,8 @@ srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -577,6 +597,8 @@ srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -645,6 +667,8 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    SrsJsonObject* data = SrsJsonAny::object();
 | 
			
		||||
    obj->set("data", data);
 | 
			
		||||
| 
						 | 
				
			
			@ -700,6 +724,8 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    if (r->is_http_get()) {
 | 
			
		||||
        if (!vhost) {
 | 
			
		||||
| 
						 | 
				
			
			@ -756,6 +782,8 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    if (r->is_http_get()) {
 | 
			
		||||
        if (!stream) {
 | 
			
		||||
| 
						 | 
				
			
			@ -816,6 +844,8 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    
 | 
			
		||||
    obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
 | 
			
		||||
    obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
 | 
			
		||||
    obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
 | 
			
		||||
    
 | 
			
		||||
    if (r->is_http_get()) {
 | 
			
		||||
        if (!client) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1121,6 +1151,9 @@ srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
 | 
			
		|||
    ss << "# HELP srs_build_info A metric with a constant '1' value labeled by build_date, version from which SRS was built.\n"
 | 
			
		||||
        << "# TYPE srs_build_info gauge\n"
 | 
			
		||||
        << "srs_build_info{"
 | 
			
		||||
            << "server=\"" << stat->server_id() << "\","
 | 
			
		||||
            << "service=\"" << stat->service_id() << "\","
 | 
			
		||||
            << "pid=\"" << stat->service_pid() << "\","
 | 
			
		||||
            << "build_date=\"" << SRS_BUILD_DATE << "\","
 | 
			
		||||
            << "major=\"" << VERSION_MAJOR << "\","
 | 
			
		||||
            << "version=\"" << RTMP_SIG_SRS_VERSION << "\","
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -170,6 +170,8 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
 | 
			
		|||
 | 
			
		||||
    res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
 | 
			
		||||
    res->set("service", SrsJsonAny::str(SrsStatistic::instance()->service_id().c_str()));
 | 
			
		||||
    res->set("pid", SrsJsonAny::str(SrsStatistic::instance()->service_pid().c_str()));
 | 
			
		||||
 | 
			
		||||
    // TODO: add candidates in response json?
 | 
			
		||||
    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
 | 
			
		|||
 | 
			
		||||
    res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
 | 
			
		||||
    res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
 | 
			
		||||
    res->set("service", SrsJsonAny::str(SrsStatistic::instance()->service_id().c_str()));
 | 
			
		||||
    res->set("pid", SrsJsonAny::str(SrsStatistic::instance()->service_pid().c_str()));
 | 
			
		||||
 | 
			
		||||
    // TODO: add candidates in response json?
 | 
			
		||||
    res->set("sdp", SrsJsonAny::str(ruc.local_sdp_str_.c_str()));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -543,6 +543,24 @@ std::string SrsStatistic::server_id()
 | 
			
		|||
    return server_id_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string SrsStatistic::service_id()
 | 
			
		||||
{
 | 
			
		||||
    if (service_id_.empty()) {
 | 
			
		||||
        service_id_ = srs_random_str(8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return service_id_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string SrsStatistic::service_pid()
 | 
			
		||||
{
 | 
			
		||||
    if (service_pid_.empty()) {
 | 
			
		||||
        service_pid_ = srs_int2str(getpid());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return service_pid_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
srs_error_t SrsStatistic::dumps_vhosts(SrsJsonArray* arr)
 | 
			
		||||
{
 | 
			
		||||
    srs_error_t err = srs_success;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -122,6 +122,10 @@ private:
 | 
			
		|||
    static SrsStatistic *_instance;
 | 
			
		||||
    // The id to identify the sever.
 | 
			
		||||
    std::string server_id_;
 | 
			
		||||
    // The id to identify the service.
 | 
			
		||||
    std::string service_id_;
 | 
			
		||||
    // The pid to identify the service process.
 | 
			
		||||
    std::string service_pid_;
 | 
			
		||||
private:
 | 
			
		||||
    // The key: vhost id, value: vhost object.
 | 
			
		||||
    std::map<std::string, SrsStatisticVhost*> vhosts;
 | 
			
		||||
| 
						 | 
				
			
			@ -196,6 +200,10 @@ public:
 | 
			
		|||
    // Get the server id, used to identify the server.
 | 
			
		||||
    // For example, when restart, the server id must changed.
 | 
			
		||||
    virtual std::string server_id();
 | 
			
		||||
    // Get the service id, used to identify the restart of service.
 | 
			
		||||
    virtual std::string service_id();
 | 
			
		||||
    // Get the service pid, used to identify the service process.
 | 
			
		||||
    virtual std::string service_pid();
 | 
			
		||||
    // Dumps the vhosts to amf0 array.
 | 
			
		||||
    virtual srs_error_t dumps_vhosts(SrsJsonArray* arr);
 | 
			
		||||
    // Dumps the streams to amf0 array.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,6 @@
 | 
			
		|||
 | 
			
		||||
#define VERSION_MAJOR       5
 | 
			
		||||
#define VERSION_MINOR       0
 | 
			
		||||
#define VERSION_REVISION    134
 | 
			
		||||
#define VERSION_REVISION    135
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue