return ret;
}
+static RemoteLoggerStats_t* pleaseGetRemoteLoggerStats()
+{
+ auto ret = new RemoteLoggerStats_t;
+
+ if (t_protobufServers) {
+ for (const auto& s : *t_protobufServers) {
+ ret->emplace(std::make_pair(s->address(), s->getStats()));
+ }
+ }
+ return ret;
+}
+
static string doGetProxyMappingStats()
{
ostringstream ret;
return ret.str();
}
+static RemoteLoggerStats_t* pleaseGetOutgoingRemoteLoggerStats()
+{
+ auto ret = new RemoteLoggerStats_t;
+
+ if (t_outgoingProtobufServers) {
+ for (const auto& s : *t_outgoingProtobufServers) {
+ ret->emplace(std::make_pair(s->address(), s->getStats()));
+ }
+ }
+ return ret;
+}
+
+static RemoteLoggerStats_t* pleaseGetFramestreamLoggerStats()
+{
+ auto ret = new RemoteLoggerStats_t;
+
+ if (t_frameStreamServersInfo.servers) {
+ for (const auto& s : *t_frameStreamServersInfo.servers) {
+ ret->emplace(std::make_pair(s->address(), s->getStats()));
+ }
+ }
+ return ret;
+}
+
+static void remoteLoggerStats(const string& name, const RemoteLoggerStats_t& stats, ostringstream& os)
+{
+ if (stats.size() > 0) {
+ std::string filler(name.size(), ' ');
+ os << name << "\tQueued\tPipe-\tToo-\tOther-\tAddress" << endl;
+ os << filler << "\t\tFull\tLarge\terror" << endl;
+ for (const auto& [key, entry]: stats) {
+ os << filler<< '\t' << entry.d_queued << '\t' << entry.d_pipeFull << '\t' << entry.d_tooLarge << '\t' << entry.d_otherError << '\t' << key << endl;
+ }
+ }
+}
+
+static string getRemoteLoggerStats()
+{
+ ostringstream os;
+ auto stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetRemoteLoggerStats);
+ remoteLoggerStats("Protobuf ", stats, os);
+ stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetOutgoingRemoteLoggerStats);
+ remoteLoggerStats("OutProtobuf", stats, os);
+ stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetFramestreamLoggerStats);
+ remoteLoggerStats("Framestream", stats, os);
+ return os.str();
+}
+
static uint64_t calculateUptime()
{
return time(nullptr) - g_stats.startupTime;
"get-parameter [key1] [key2] .. get configuration parameters\n"
"get-proxymapping-stats get proxy mapping statistics\n"
"get-qtypelist get QType statistics\n"
+ "get-remotelogger-stats get remote logger statistics\n"
" notice: queries from cache aren't being counted yet\n"
"hash-password [work-factor] ask for a password then return the hashed version\n"
"help get this list\n"
if (cmd == "get-proxymapping-stats") {
return {0, doGetProxyMappingStats()};
}
+ if (cmd == "get-remotelogger-stats") {
+ return {0, getRemoteLoggerStats() };
+ }
return {1, "Unknown command '" + cmd + "', try 'help'\n"};
}
return a;
}
+static RemoteLoggerStats_t& operator+=(RemoteLoggerStats_t &a, const RemoteLoggerStats_t& b)
+{
+ for (const auto& [key, entry] : b) {
+ a[key] += entry;
+ }
+ return a;
+}
+
// This function should only be called by the handler to gather
// metrics, wipe the cache, reload the Lua script (not the Lua config)
// or change the current trace regex, and by the SNMP thread to gather
template vector<pair<DNSName, uint16_t>> broadcastAccFunction(const std::function<vector<pair<DNSName, uint16_t>>*()>& fun); // explicit instantiation
template ThreadTimes broadcastAccFunction(const std::function<ThreadTimes*()>& fun);
template ProxyMappingStats_t broadcastAccFunction(const std::function<ProxyMappingStats_t*()>& fun);
+template RemoteLoggerStats_t broadcastAccFunction(const std::function<RemoteLoggerStats_t*()>& fun);
static int serviceMain(int argc, char* argv[], Logr::log_t log)
{
virtual ~RemoteLoggerInterface() {};
virtual Result queueData(const std::string& data) = 0;
+ virtual std::string address() const = 0;
virtual std::string toString() const = 0;
virtual const std::string name() const = 0;
bool logQueries(void) const { return d_logQueries; }
uint64_t d_pipeFull{};
uint64_t d_tooLarge{};
uint64_t d_otherError{};
+
+ Stats& operator += (const Stats& rhs)
+ {
+ d_queued += rhs.d_queued;
+ d_pipeFull += rhs.d_pipeFull;
+ d_tooLarge += rhs.d_tooLarge;
+ d_otherError += rhs.d_otherError;
+ return *this;
+ }
};
virtual Stats getStats() const = 0;
bool asyncConnect=false);
~RemoteLogger();
+ std::string address() const override
+ {
+ return d_remote.toStringWithPort();
+ }
+
[[nodiscard]] Result queueData(const std::string& data) override;
const std::string name() const override
{