mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 17:52:26 +02:00
send count of alive nodes to logstash from DS
This commit is contained in:
parent
64f3b55aaa
commit
08c1d54cf3
3 changed files with 17 additions and 2 deletions
|
@ -33,6 +33,8 @@
|
|||
const int DOMAIN_LISTEN_PORT = 40102;
|
||||
unsigned char packetData[MAX_PACKET_SIZE];
|
||||
|
||||
const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
|
||||
|
||||
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
|
||||
*currentPosition++ = agentToAdd->getType();
|
||||
|
||||
|
@ -80,6 +82,8 @@ int main(int argc, const char * argv[])
|
|||
|
||||
agentList->startSilentAgentRemovalThread();
|
||||
|
||||
timeval lastStatSendTime = {};
|
||||
|
||||
while (true) {
|
||||
if (agentList->getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) &&
|
||||
(packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) {
|
||||
|
@ -171,6 +175,17 @@ int main(int argc, const char * argv[])
|
|||
broadcastPacket,
|
||||
(currentBufferPos - startPointer) + 1);
|
||||
}
|
||||
|
||||
if (Logstash::shouldSendStats()) {
|
||||
if (usecTimestampNow() - usecTimestamp(&lastStatSendTime) >= (NODE_COUNT_STAT_INTERVAL_MSECS * 1000)) {
|
||||
// time to send our count of agents and servers to logstash
|
||||
const char NODE_COUNT_LOGSTASH_KEY[] = "ds-node-count";
|
||||
|
||||
Logstash::stashGaugeValue(NODE_COUNT_LOGSTASH_KEY, agentList->getNumAliveAgents());
|
||||
|
||||
gettimeofday(&lastStatSendTime, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -191,7 +191,7 @@ Agent* AgentList::agentWithID(uint16_t agentID) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int AgentList::numAliveAgents() const {
|
||||
int AgentList::getNumAliveAgents() const {
|
||||
int numAliveAgents = 0;
|
||||
|
||||
for (AgentList::iterator agent = begin(); agent != end(); agent++) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
void(*linkedDataCreateCallback)(Agent *);
|
||||
|
||||
int size() { return _numAgents; }
|
||||
int numAliveAgents() const;
|
||||
int getNumAliveAgents() const;
|
||||
|
||||
void lock() { pthread_mutex_lock(&mutex); }
|
||||
void unlock() { pthread_mutex_unlock(&mutex); }
|
||||
|
|
Loading…
Reference in a new issue