Commit d77937f1 authored by Michael Ott's avatar Michael Ott
Browse files

Add more statistics

parent 37847aaf
......@@ -51,7 +51,8 @@ CARestAPI::CARestAPI(serverSettings_t settings,
_sensorConfig(sensorConfig),
_analyticsController(analyticsController),
_mqttServer(mqttServer) {
_influxCounter = 0;
addEndpoint("/help", {http::verb::get, stdBind(GET_help)});
addEndpoint("/version", {http::verb::get, stdBind(GET_version)});
addEndpoint("/hosts", {http::verb::get, stdBind(GET_hosts)});
......@@ -218,6 +219,7 @@ void CARestAPI::POST_write(endpointArgs) {
if (sid.mqttTopicConvert(mqttTopic)) {
_sensorCache->storeSensor(sid, ts.getRaw(), value);
_sensorDataStore->insert(&sid, ts.getRaw(), value);
_influxCounter++;
if (_influxSettings->publish && (_influxSensors.find(sid.getId()) == _influxSensors.end())) {
_influxSensors.insert(sid.getId());
......
......@@ -70,6 +70,8 @@ public:
" return code.\n"
"\n";
uint64_t getInfluxCounter() { uint64_t ctr=_influxCounter; _influxCounter=0; return ctr; };
private:
/**
......@@ -208,6 +210,7 @@ private:
AnalyticsController* _analyticsController;
SimpleMQTTServer* _mqttServer;
std::set<std::string> _influxSensors;
uint64_t _influxCounter;
};
#endif /* COLLECTAGENT_CARESTAPI_H_ */
......@@ -88,8 +88,8 @@ using namespace std;
int keepRunning;
int retCode = EXIT_SUCCESS;
uint64_t msgCtr;
uint64_t pmsgCtr;
uint64_t readingCtr;
uint64_t queryCtr;
SensorCache mySensorCache;
AnalyticsController* analyticsController;
DCDB::Connection* dcdbConn;
......@@ -190,6 +190,7 @@ bool sensorGroupQueryCallback(const std::vector<string>& names, const uint64_t s
if (!results.empty()) {
successCtr++;
reading_t reading;
queryCtr+= results.size();
for (const auto &r : results) {
reading.value = r.value;
reading.timestamp = r.timeStamp.getRaw();
......@@ -276,11 +277,9 @@ void abrtHandler(int sig)
int mqttCallback(SimpleMQTTMessage *msg)
{
/*
* Increment the msgCtr/vmsgCtr for statistics.
* Increment the msgCtr for statistics.
*/
msgCtr++;
if (msg->isPublish())
pmsgCtr++;
#ifndef BENCHMARK_MODE
......@@ -872,8 +871,8 @@ int main(int argc, char* const argv[]) {
uint64_t start, end;
double elapsed;
msgCtr = 0;
pmsgCtr = 0;
readingCtr = 0;
queryCtr = 0;
start = getTimestamp();
uint64_t lastCleanup = start;
......@@ -895,9 +894,12 @@ int main(int argc, char* const argv[]) {
/* not really thread safe but will do the job */
end = getTimestamp();
elapsed = NS_TO_S(((double) end - (double) start));
float publish = msgCtr?(pmsgCtr*100.0)/msgCtr:0;
LOG(info) << "Performance: " << (readingCtr/elapsed) << " inserts/s, " << (msgCtr/elapsed) << " messages/s (" << publish << "% PUBLISH)";
LOG(info) << "Analytics Performance: " << (analyticsController->getReadingCtr()/elapsed) << " inserts/s ";
float aIns = ceil((float) analyticsController->getReadingCtr() / elapsed);
float aReq = ceil((float) queryCtr / elapsed);
float rIns = ceil((float) httpsServer->getInfluxCounter() / elapsed);
float mIns = ceil((float) readingCtr / elapsed);
float mMsg = ceil((float) msgCtr / elapsed);
LOG(info) << "Performance: MQTT [" << std::fixed << std::setprecision(0) << mIns << " ins/s|" << mMsg << " msg/s] REST [" << rIns << " ins/s] Analytics [" << aIns << " ins/s|" << aReq << " req/s]";
std::map<std::string, hostInfo_t> lastSeen = ms.collectLastSeen();
uint64_t connectedHosts = 0;
for (auto h: lastSeen) {
......@@ -907,7 +909,7 @@ int main(int argc, char* const argv[]) {
}
LOG(info) << "Connected hosts: " << connectedHosts;
msgCtr = 0;
pmsgCtr = 0;
queryCtr = 0;
readingCtr = 0;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment