Skip to content

Commit

Permalink
Exporter: Support server/pid/service.(#3378)
Browse files Browse the repository at this point in the history
  • Loading branch information
chundonglinlin committed Jan 17, 2023
1 parent 9bf45be commit 9350a2d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,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 << "\","
Expand Down
18 changes: 18 additions & 0 deletions trunk/src/app/srs_app_statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,24 @@ std::string SrsStatistic::server_id()
return server_id_;
}

std::string SrsStatistic::service_id()
{
if (service_id_.empty()) {
service_id_ = srs_int2str(getpid());
}

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;
Expand Down
8 changes: 8 additions & 0 deletions trunk/src/app/srs_app_statistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class SrsStatistic
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;
Expand Down Expand Up @@ -196,6 +200,10 @@ class SrsStatistic
// 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.
Expand Down

0 comments on commit 9350a2d

Please sign in to comment.