Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: convert ws-auth to produce numerical stats. #4915

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdns/rec_channel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private:
static bool s_init;
};

std::map<std::string, std::string> getAllStatsMap();
std::map<std::string, int> getAllStatsMap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mismatched type between decl here and impl below.

extern pthread_mutex_t g_carbon_config_lock;
void sortPublicSuffixList();
std::vector<std::pair<DNSName, uint16_t> >* pleaseGetQueryRing();
Expand Down
16 changes: 8 additions & 8 deletions pdns/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,34 @@ optional<uint64_t> get(const string& name)
return ret;
}

map<string,string> getAllStatsMap()
map<string,uint64_t> getAllStatsMap()
{
map<string,string> ret;
map<string,uint64_t> ret;

for(const auto& the32bits : d_get32bitpointers) {
ret.insert(make_pair(the32bits.first, std::to_string(*the32bits.second)));
ret.insert(make_pair(the32bits.first, *the32bits.second));
}
for(const auto& the64bits : d_get64bitpointers) {
ret.insert(make_pair(the64bits.first, std::to_string(*the64bits.second)));
ret.insert(make_pair(the64bits.first, *the64bits.second));
}
for(const auto& atomic : d_getatomics) {
ret.insert(make_pair(atomic.first, std::to_string(atomic.second->load())));
ret.insert(make_pair(atomic.first, atomic.second->load()));
}

for(const auto& the64bitmembers : d_get64bitmembers) {
if(the64bitmembers.first == "cache-bytes" || the64bitmembers.first=="packetcache-bytes")
continue; // too slow for 'get-all'
ret.insert(make_pair(the64bitmembers.first, std::to_string(the64bitmembers.second())));
ret.insert(make_pair(the64bitmembers.first, the64bitmembers.second()));
}
Lock l(&d_dynmetricslock);
for(const auto& a : d_dynmetrics)
ret.insert({a.first, std::to_string(*a.second)});
ret.insert({a.first, *a.second});
return ret;
}

string getAllStats()
{
typedef map<string, string> varmap_t;
typedef map<string, uint64_t> varmap_t;
varmap_t varmap = getAllStatsMap();
string ret;
for(varmap_t::value_type& tup : varmap) {
Expand Down
6 changes: 3 additions & 3 deletions pdns/ws-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
if(req->method != "GET")
throw HttpMethodNotAllowedException();

map<string,int> items;
map<string,uint64_t> items;
productServerStatisticsFetch(items);

Json::array doc;
typedef map<string, int> items_t;
typedef map<string, uint64_t> items_t;
for(const items_t::value_type& item : items) {
doc.push_back(Json::object {
{ "type", "StatisticItem" },
{ "name", item.first },
{ "value", item.second },
{ "value", static_cast<double>(item.second) },
});
}

Expand Down
2 changes: 1 addition & 1 deletion pdns/ws-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ void apiCheckQNameAllowedCharacters(const string& name);
DNSName apiNameToDNSName(const string& name);

// To be provided by product code.
void productServerStatisticsFetch(std::map<string,int>& out);
void productServerStatisticsFetch(std::map<string,uint64_t>& out);

#endif /* PDNS_WSAPI_HH */
4 changes: 2 additions & 2 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ static void fillZone(const DNSName& zonename, HttpResponse* resp) {
resp->setBody(doc);
}

void productServerStatisticsFetch(map<string,int>& out)
void productServerStatisticsFetch(map<string,uint64_t>& out)
{
vector<string> items = S.getEntries();
for(const string& item : items) {
out[item] = std::stoi(std::to_string(S.read(item)));
out[item] = S.read(item);
}

// add uptime
Expand Down
4 changes: 2 additions & 2 deletions pdns/ws-recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ extern __thread FDMultiplexer* t_fdm;

using json11::Json;

void productServerStatisticsFetch(map<string,int>& out)
void productServerStatisticsFetch(map<string,uint64_t>& out)
{
//map<string,string> stats = getAllStatsMap();
map<string,uint64_t> stats = getAllStatsMap();
out.swap(stats);
}

Expand Down