mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support show the summary of kafka metadata.
This commit is contained in:
parent
d013374871
commit
f0e39cc330
8 changed files with 111 additions and 20 deletions
|
@ -2128,6 +2128,8 @@ int SrsConfig::global_to_json(SrsJsonObject* obj)
|
|||
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
||||
} else if (sdir->name == "brokers") {
|
||||
sobj->set(sdir->name, sdir->dumps_args());
|
||||
} else if (sdir->name == "topic") {
|
||||
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
||||
}
|
||||
}
|
||||
obj->set(dir->name, sobj);
|
||||
|
@ -3546,7 +3548,7 @@ int SrsConfig::check_config()
|
|||
SrsConfDirective* conf = root->get("kafka");
|
||||
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
||||
string n = conf->at(i)->name;
|
||||
if (n != "enabled" && n != "brokers") {
|
||||
if (n != "enabled" && n != "brokers" && n != "topic") {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported kafka directive %s, ret=%d", n.c_str(), ret);
|
||||
return ret;
|
||||
|
|
|
@ -32,6 +32,7 @@ using namespace std;
|
|||
#include <srs_app_async_call.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_protocol_utility.hpp>
|
||||
#include <srs_kernel_balance.hpp>
|
||||
#include <srs_kafka_stack.hpp>
|
||||
#include <srs_core_autofree.hpp>
|
||||
|
@ -201,6 +202,48 @@ int SrsKafkaProducer::request_metadata()
|
|||
}
|
||||
SrsAutoFree(SrsKafkaTopicMetadataResponse, metadata);
|
||||
|
||||
// show kafka metadata.
|
||||
string summary;
|
||||
if (true) {
|
||||
vector<string> bs;
|
||||
for (int i = 0; i < metadata->brokers.size(); i++) {
|
||||
SrsKafkaBroker* broker = metadata->brokers.at(i);
|
||||
|
||||
string hostport = srs_int2str(broker->node_id) + "/" + broker->host.to_str();
|
||||
if (broker->port > 0) {
|
||||
hostport += ":" + srs_int2str(broker->port);
|
||||
}
|
||||
|
||||
bs.push_back(hostport);
|
||||
}
|
||||
|
||||
vector<string> ps;
|
||||
for (int i = 0; i < metadata->metadatas.size(); i++) {
|
||||
SrsKafkaTopicMetadata* topic = metadata->metadatas.at(i);
|
||||
|
||||
string desc = "topic=" + topic->name.to_str();
|
||||
|
||||
for (int j = 0; j < topic->metadatas.size(); j++) {
|
||||
SrsKafkaPartitionMetadata* partition = topic->metadatas.at(j);
|
||||
|
||||
desc += ", partition" + srs_int2str(partition->partition_id) +"=";
|
||||
desc += srs_int2str(partition->leader) + "/";
|
||||
|
||||
vector<string> replicas = srs_kafka_array2vector(&partition->replicas);
|
||||
desc += srs_join_vector_string(replicas, ",");
|
||||
}
|
||||
|
||||
ps.push_back(desc);
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "brokers=" << srs_join_vector_string(bs, ",");
|
||||
ss << ", " << srs_join_vector_string(ps, ",");
|
||||
|
||||
summary = ss.str();
|
||||
}
|
||||
srs_trace("kafka metadata: %s", summary.c_str());
|
||||
|
||||
meatadata_ok = true;
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -1467,17 +1467,3 @@ void srs_api_dump_summaries(SrsJsonObject* obj)
|
|||
sys->set("conn_srs", SrsJsonAny::integer(nrs->nb_conn_srs));
|
||||
}
|
||||
|
||||
string srs_join_vector_string(vector<string>& vs, string separator)
|
||||
{
|
||||
string str = "";
|
||||
|
||||
for (int i = 0; i < (int)vs.size(); i++) {
|
||||
str += vs.at(i);
|
||||
if (i != (int)vs.size() - 1) {
|
||||
str += separator;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
|
@ -677,8 +677,5 @@ extern bool srs_is_boolean(const std::string& str);
|
|||
// dump summaries for /api/v1/summaries.
|
||||
extern void srs_api_dump_summaries(SrsJsonObject* obj);
|
||||
|
||||
// join string in vector with indicated separator
|
||||
extern std::string srs_join_vector_string(std::vector<std::string>& vs, std::string separator);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue