|
|
@ -1062,3 +1062,96 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SrsGoApiMetrics::SrsGoApiMetrics()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
enabled_ = _srs_config->get_exporter_enabled();
|
|
|
|
|
|
|
|
label_ = _srs_config->get_exporter_label();
|
|
|
|
|
|
|
|
tag_ = _srs_config->get_exporter_tag();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SrsGoApiMetrics::~SrsGoApiMetrics()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// whether enabled the HTTP Metrics API.
|
|
|
|
|
|
|
|
if (!enabled_) {
|
|
|
|
|
|
|
|
return srs_api_response_code(w, r, ERROR_EXPORTER_DISABLED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* build_info gauge
|
|
|
|
|
|
|
|
* send_bytes_total counter
|
|
|
|
|
|
|
|
* receive_bytes_total counter
|
|
|
|
|
|
|
|
* streams gauge
|
|
|
|
|
|
|
|
* clients gauge
|
|
|
|
|
|
|
|
* clients_total counter
|
|
|
|
|
|
|
|
* error counter
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build info from Config.
|
|
|
|
|
|
|
|
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{"
|
|
|
|
|
|
|
|
<< "build_date=\"" << SRS_BUILD_DATE << "\","
|
|
|
|
|
|
|
|
<< "major=\"" << VERSION_MAJOR << "\","
|
|
|
|
|
|
|
|
<< "version=\"" << RTMP_SIG_SRS_VERSION << "\","
|
|
|
|
|
|
|
|
<< "code=\"" << RTMP_SIG_SRS_CODE<< "\"";
|
|
|
|
|
|
|
|
if (!label_.empty()) ss << ",label=\"" << label_ << "\"";
|
|
|
|
|
|
|
|
if (!tag_.empty()) ss << ",tag=\"" << tag_ << "\"";
|
|
|
|
|
|
|
|
ss << "} 1\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dump metrics by statistic.
|
|
|
|
|
|
|
|
int64_t send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs;
|
|
|
|
|
|
|
|
stat->dumps_metrics(send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The total of bytes sent.
|
|
|
|
|
|
|
|
ss << "# HELP srs_send_bytes_total SRS total sent bytes.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_send_bytes_total counter\n"
|
|
|
|
|
|
|
|
<< "srs_send_bytes_total "
|
|
|
|
|
|
|
|
<< send_bytes
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The total of bytes received.
|
|
|
|
|
|
|
|
ss << "# HELP srs_receive_bytes_total SRS total received bytes.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_receive_bytes_total counter\n"
|
|
|
|
|
|
|
|
<< "srs_receive_bytes_total "
|
|
|
|
|
|
|
|
<< recv_bytes
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Current number of online streams.
|
|
|
|
|
|
|
|
ss << "# HELP srs_streams The number of SRS concurrent streams.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_streams gauge\n"
|
|
|
|
|
|
|
|
<< "srs_streams "
|
|
|
|
|
|
|
|
<< nstreams
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Current number of online clients.
|
|
|
|
|
|
|
|
ss << "# HELP srs_clients The number of SRS concurrent clients.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_clients gauge\n"
|
|
|
|
|
|
|
|
<< "srs_clients "
|
|
|
|
|
|
|
|
<< nclients
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The total of clients connections.
|
|
|
|
|
|
|
|
ss << "# HELP srs_clients_total The total counts of SRS clients.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_clients_total counter\n"
|
|
|
|
|
|
|
|
<< "srs_clients_total "
|
|
|
|
|
|
|
|
<< total_nclients
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The total of clients errors.
|
|
|
|
|
|
|
|
ss << "# HELP srs_clients_errs_total The total errors of SRS clients.\n"
|
|
|
|
|
|
|
|
<< "# TYPE srs_clients_errs_total counter\n"
|
|
|
|
|
|
|
|
<< "srs_clients_errs_total "
|
|
|
|
|
|
|
|
<< nerrs
|
|
|
|
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return srs_api_response(w, r, ss.str());
|
|
|
|
|
|
|
|
}
|
|
|
|