Merge branch 'master' of github.com:hanzz/libtransport
This commit is contained in:
commit
2814db5bd6
3 changed files with 65 additions and 0 deletions
|
@ -49,6 +49,7 @@ class AddressedRosterRequest : public Swift::GenericRequest<Swift::RosterPayload
|
|||
/// Manages roster of one XMPP user.
|
||||
class RosterManager {
|
||||
public:
|
||||
typedef std::map<std::string, Buddy *, std::less<std::string>, boost::pool_allocator< std::pair<std::string, Buddy *> > > BuddiesMap;
|
||||
/// Creates new RosterManager.
|
||||
/// \param user User associated with this RosterManager.
|
||||
/// \param component Transport instance associated with this roster.
|
||||
|
@ -80,6 +81,10 @@ class RosterManager {
|
|||
/// \return User
|
||||
User *getUser() { return m_user; }
|
||||
|
||||
const BuddiesMap &getBuddies() {
|
||||
return m_buddies;
|
||||
}
|
||||
|
||||
bool isRemoteRosterSupported() {
|
||||
return m_supportRemoteRoster;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ class StatsResponder : public Swift::Responder<Swift::StatsPayload> {
|
|||
virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::StatsPayload> payload);
|
||||
virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::StatsPayload> payload);
|
||||
|
||||
unsigned long usedMemory();
|
||||
|
||||
Component *m_component;
|
||||
UserManager *m_userManager;
|
||||
NetworkPluginServer *m_server;
|
||||
|
|
|
@ -29,6 +29,11 @@
|
|||
#include "transport/user.h"
|
||||
#include "transport/buddy.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/conversationmanager.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/networkpluginserver.h"
|
||||
#include "log4cxx/logger.h"
|
||||
|
||||
using namespace log4cxx;
|
||||
|
@ -52,17 +57,70 @@ StatsResponder::~StatsResponder() {
|
|||
|
||||
}
|
||||
|
||||
unsigned long StatsResponder::usedMemory() {
|
||||
double shared = 0;
|
||||
double rss = 0;
|
||||
#ifndef WIN32
|
||||
process_mem_usage(shared, rss);
|
||||
#endif
|
||||
rss -= shared;
|
||||
|
||||
const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
|
||||
BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
|
||||
rss += backend->res - backend->shared;
|
||||
}
|
||||
|
||||
return (unsigned long) rss;
|
||||
}
|
||||
|
||||
bool StatsResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<StatsPayload> stats) {
|
||||
boost::shared_ptr<StatsPayload> response(new StatsPayload());
|
||||
|
||||
if (stats->getItems().empty()) {
|
||||
response->addItem(StatsPayload::Item("uptime"));
|
||||
response->addItem(StatsPayload::Item("users/online"));
|
||||
response->addItem(StatsPayload::Item("contacts/online"));
|
||||
response->addItem(StatsPayload::Item("contacts/total"));
|
||||
response->addItem(StatsPayload::Item("backends"));
|
||||
response->addItem(StatsPayload::Item("memory-usage"));
|
||||
}
|
||||
else {
|
||||
unsigned long contactsOnline = 0;
|
||||
unsigned long contactsTotal = 0;
|
||||
|
||||
Swift::StatusShow s;
|
||||
std::string statusMessage;
|
||||
for (std::map<std::string, User *>::const_iterator it = m_userManager->getUsers().begin(); it != m_userManager->getUsers().end(); it++) {
|
||||
const RosterManager::BuddiesMap &buddies = (*it).second->getRosterManager()->getBuddies();
|
||||
contactsTotal += buddies.size();
|
||||
for(RosterManager::BuddiesMap::const_iterator it = buddies.begin(); it != buddies.end(); it++) {
|
||||
if (!(*it).second->getStatus(s, statusMessage))
|
||||
continue;
|
||||
if (s.getType() != Swift::StatusShow::None) {
|
||||
contactsOnline++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const StatsPayload::Item &item, stats->getItems()) {
|
||||
if (item.getName() == "uptime") {
|
||||
response->addItem(StatsPayload::Item("uptime", "seconds", boost::lexical_cast<std::string>(time(0) - m_start)));
|
||||
}
|
||||
else if (item.getName() == "users/online") {
|
||||
response->addItem(StatsPayload::Item("users/online", "users", boost::lexical_cast<std::string>(m_userManager->getUserCount())));
|
||||
}
|
||||
else if (item.getName() == "backends") {
|
||||
response->addItem(StatsPayload::Item("backends", "backends", boost::lexical_cast<std::string>(m_server->getBackendCount())));
|
||||
}
|
||||
else if (item.getName() == "memory-usage") {
|
||||
response->addItem(StatsPayload::Item("memory-usage", "KB", boost::lexical_cast<std::string>(usedMemory())));
|
||||
}
|
||||
else if (item.getName() == "contacts/online") {
|
||||
response->addItem(StatsPayload::Item("contacts/online", "contacts", boost::lexical_cast<std::string>(contactsOnline)));
|
||||
}
|
||||
else if (item.getName() == "contacts/total") {
|
||||
response->addItem(StatsPayload::Item("contacts/total", "contacts", boost::lexical_cast<std::string>(contactsTotal)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue