mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-30 09:48:59 -04:00
add stats to libresapi
This commit is contained in:
parent
a899c98d88
commit
51c98fdf50
4 changed files with 74 additions and 3 deletions
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "ApiPluginHandler.h"
|
#include "ApiPluginHandler.h"
|
||||||
#include "ChannelsHandler.h"
|
#include "ChannelsHandler.h"
|
||||||
|
#include "StatsHandler.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
data types in json http://json.org/
|
data types in json http://json.org/
|
||||||
|
@ -234,7 +235,8 @@ public:
|
||||||
mTransfersHandler(sts, ifaces.mFiles),
|
mTransfersHandler(sts, ifaces.mFiles),
|
||||||
mChatHandler(sts, ifaces.mNotify, ifaces.mMsgs, ifaces.mPeers, ifaces.mIdentity, &mPeersHandler),
|
mChatHandler(sts, ifaces.mNotify, ifaces.mMsgs, ifaces.mPeers, ifaces.mIdentity, &mPeersHandler),
|
||||||
mApiPluginHandler(sts, ifaces),
|
mApiPluginHandler(sts, ifaces),
|
||||||
mChannelsHandler(ifaces.mGxsChannels)
|
mChannelsHandler(ifaces.mGxsChannels),
|
||||||
|
mStatsHandler()
|
||||||
{
|
{
|
||||||
// the dynamic cast is to not confuse the addResourceHandler template like this:
|
// the dynamic cast is to not confuse the addResourceHandler template like this:
|
||||||
// addResourceHandler(derived class, parent class)
|
// addResourceHandler(derived class, parent class)
|
||||||
|
@ -258,6 +260,8 @@ public:
|
||||||
&ChatHandler::handleRequest);
|
&ChatHandler::handleRequest);
|
||||||
router.addResourceHandler("channels", dynamic_cast<ResourceRouter*>(&mChannelsHandler),
|
router.addResourceHandler("channels", dynamic_cast<ResourceRouter*>(&mChannelsHandler),
|
||||||
&ChannelsHandler::handleRequest);
|
&ChannelsHandler::handleRequest);
|
||||||
|
router.addResourceHandler("stats", dynamic_cast<ResourceRouter*>(&mStatsHandler),
|
||||||
|
&StatsHandler::handleRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeersHandler mPeersHandler;
|
PeersHandler mPeersHandler;
|
||||||
|
@ -269,6 +273,7 @@ public:
|
||||||
ChatHandler mChatHandler;
|
ChatHandler mChatHandler;
|
||||||
ApiPluginHandler mApiPluginHandler;
|
ApiPluginHandler mApiPluginHandler;
|
||||||
ChannelsHandler mChannelsHandler;
|
ChannelsHandler mChannelsHandler;
|
||||||
|
StatsHandler mStatsHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiServer::ApiServer():
|
ApiServer::ApiServer():
|
||||||
|
|
39
libresapi/src/api/StatsHandler.cpp
Normal file
39
libresapi/src/api/StatsHandler.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "StatsHandler.h"
|
||||||
|
#include "Operators.h"
|
||||||
|
|
||||||
|
#include <retroshare/rspeers.h>
|
||||||
|
#include <retroshare/rsconfig.h>
|
||||||
|
#include <pqi/authssl.h>
|
||||||
|
|
||||||
|
namespace resource_api
|
||||||
|
{
|
||||||
|
|
||||||
|
StatsHandler::StatsHandler()
|
||||||
|
{
|
||||||
|
addResourceHandler("*", this, &StatsHandler::handleStatsRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatsHandler::handleStatsRequest(Request &/*req*/, Response &resp)
|
||||||
|
{
|
||||||
|
StreamBase& itemStream = resp.mDataStream.getStreamToMember();
|
||||||
|
|
||||||
|
// location info
|
||||||
|
itemStream << makeKeyValue("name", rsPeers->getGPGName(rsPeers->getGPGOwnId()));
|
||||||
|
itemStream << makeKeyValue("location", AuthSSL::getAuthSSL()->getOwnLocation());
|
||||||
|
|
||||||
|
// peer info
|
||||||
|
unsigned int all, online;
|
||||||
|
rsPeers->getPeerCount(&all, &online, false);
|
||||||
|
itemStream << makeKeyValue("peers_all", all);
|
||||||
|
itemStream << makeKeyValue("peers_connected", online);
|
||||||
|
|
||||||
|
// bandwidth info
|
||||||
|
float downKb, upKb;
|
||||||
|
rsConfig->GetCurrentDataRates(downKb, upKb);
|
||||||
|
itemStream << makeKeyValue("bandwidth_up_kb", (double)upKb);
|
||||||
|
itemStream << makeKeyValue("bandwidth_down_kb", (double)downKb);
|
||||||
|
|
||||||
|
resp.setOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace resource_api
|
25
libresapi/src/api/StatsHandler.h
Normal file
25
libresapi/src/api/StatsHandler.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef STATSHANDLER_H
|
||||||
|
#define STATSHANDLER_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* simple class to output some basic stats about RS
|
||||||
|
* like bandwidth, connected peers, ...
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ResourceRouter.h"
|
||||||
|
|
||||||
|
namespace resource_api
|
||||||
|
{
|
||||||
|
|
||||||
|
class StatsHandler : public ResourceRouter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StatsHandler();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void handleStatsRequest(Request& req, Response& resp);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace resource_api
|
||||||
|
|
||||||
|
#endif // STATSHANDLER_H
|
|
@ -146,7 +146,8 @@ SOURCES += \
|
||||||
api/TmpBlobStore.cpp \
|
api/TmpBlobStore.cpp \
|
||||||
util/ContentTypes.cpp \
|
util/ContentTypes.cpp \
|
||||||
api/ApiPluginHandler.cpp \
|
api/ApiPluginHandler.cpp \
|
||||||
api/ChannelsHandler.cpp
|
api/ChannelsHandler.cpp \
|
||||||
|
api/StatsHandler.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
api/ApiServer.h \
|
api/ApiServer.h \
|
||||||
|
@ -172,7 +173,8 @@ HEADERS += \
|
||||||
api/TmpBlobStore.h \
|
api/TmpBlobStore.h \
|
||||||
util/ContentTypes.h \
|
util/ContentTypes.h \
|
||||||
api/ApiPluginHandler.h \
|
api/ApiPluginHandler.h \
|
||||||
api/ChannelsHandler.h
|
api/ChannelsHandler.h \
|
||||||
|
api/StatsHandler.h
|
||||||
|
|
||||||
libresapilocalserver {
|
libresapilocalserver {
|
||||||
CONFIG *= qt
|
CONFIG *= qt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue