mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:57:58 +02:00
Merge pull request #609 from birarda/domain-stats
rework Logstash to handle various stat types, add domain server node count stat
This commit is contained in:
commit
bf4757663c
7 changed files with 41 additions and 23 deletions
|
@ -138,7 +138,7 @@ int main(int argc, const char* argv[]) {
|
||||||
const char MIXER_LOGSTASH_METRIC_NAME[] = "audio-mixer-frame-time-usage";
|
const char MIXER_LOGSTASH_METRIC_NAME[] = "audio-mixer-frame-time-usage";
|
||||||
|
|
||||||
float averageFrameTimePercentage = sumFrameTimePercentages / numStatCollections;
|
float averageFrameTimePercentage = sumFrameTimePercentages / numStatCollections;
|
||||||
Logstash::stashValue(MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage);
|
Logstash::stashValue(STAT_TYPE_GAUGE, MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage);
|
||||||
|
|
||||||
sumFrameTimePercentages = 0.0f;
|
sumFrameTimePercentages = 0.0f;
|
||||||
numStatCollections = 0;
|
numStatCollections = 0;
|
||||||
|
|
|
@ -17,35 +17,23 @@
|
||||||
// M - Audio Mixer
|
// M - Audio Mixer
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <fcntl.h>
|
||||||
|
#include <map>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <map>
|
|
||||||
#include "AgentList.h"
|
#include "AgentList.h"
|
||||||
#include "AgentTypes.h"
|
#include "AgentTypes.h"
|
||||||
#include <PacketHeaders.h>
|
#include "Logstash.h"
|
||||||
|
#include "PacketHeaders.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "Syssocket.h"
|
|
||||||
#include "Systime.h"
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
const int DOMAIN_LISTEN_PORT = 40102;
|
const int DOMAIN_LISTEN_PORT = 40102;
|
||||||
unsigned char packetData[MAX_PACKET_SIZE];
|
unsigned char packetData[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
const int LOGOFF_CHECK_INTERVAL = 5000;
|
const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
|
||||||
|
|
||||||
int lastActiveCount = 0;
|
|
||||||
|
|
||||||
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
|
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
|
||||||
*currentPosition++ = agentToAdd->getType();
|
*currentPosition++ = agentToAdd->getType();
|
||||||
|
@ -94,6 +82,8 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
agentList->startSilentAgentRemovalThread();
|
agentList->startSilentAgentRemovalThread();
|
||||||
|
|
||||||
|
timeval lastStatSendTime = {};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (agentList->getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) &&
|
if (agentList->getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) &&
|
||||||
(packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) {
|
(packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) {
|
||||||
|
@ -185,6 +175,17 @@ int main(int argc, const char * argv[])
|
||||||
broadcastPacket,
|
broadcastPacket,
|
||||||
(currentBufferPos - startPointer) + 1);
|
(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::stashValue(STAT_TYPE_GAUGE, NODE_COUNT_LOGSTASH_KEY, agentList->getNumAliveAgents());
|
||||||
|
|
||||||
|
gettimeofday(&lastStatSendTime, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -350,7 +350,7 @@ void Application::initializeGL() {
|
||||||
const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
|
const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
|
||||||
|
|
||||||
// ask the Logstash class to record the startup time
|
// ask the Logstash class to record the startup time
|
||||||
Logstash::stashValue(LOGSTASH_INTERFACE_START_TIME_KEY, startupTime);
|
Logstash::stashValue(STAT_TYPE_TIMER, LOGSTASH_INTERFACE_START_TIME_KEY, startupTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update before the first render
|
// update before the first render
|
||||||
|
|
|
@ -191,6 +191,18 @@ Agent* AgentList::agentWithID(uint16_t agentID) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgentList::getNumAliveAgents() const {
|
||||||
|
int numAliveAgents = 0;
|
||||||
|
|
||||||
|
for (AgentList::iterator agent = begin(); agent != end(); agent++) {
|
||||||
|
if (agent->isAlive()) {
|
||||||
|
++numAliveAgents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return numAliveAgents;
|
||||||
|
}
|
||||||
|
|
||||||
void AgentList::setAgentTypesOfInterest(const char* agentTypesOfInterest, int numAgentTypesOfInterest) {
|
void AgentList::setAgentTypesOfInterest(const char* agentTypesOfInterest, int numAgentTypesOfInterest) {
|
||||||
delete _agentTypesOfInterest;
|
delete _agentTypesOfInterest;
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
void(*linkedDataCreateCallback)(Agent *);
|
void(*linkedDataCreateCallback)(Agent *);
|
||||||
|
|
||||||
int size() { return _numAgents; }
|
int size() { return _numAgents; }
|
||||||
|
int getNumAliveAgents() const;
|
||||||
|
|
||||||
void lock() { pthread_mutex_lock(&mutex); }
|
void lock() { pthread_mutex_lock(&mutex); }
|
||||||
void unlock() { pthread_mutex_unlock(&mutex); }
|
void unlock() { pthread_mutex_unlock(&mutex); }
|
||||||
|
|
|
@ -45,12 +45,12 @@ bool Logstash::shouldSendStats() {
|
||||||
return shouldSendStats;
|
return shouldSendStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logstash::stashValue(const char* key, float value) {
|
void Logstash::stashValue(char valueType, const char* key, float value) {
|
||||||
static char logstashPacket[MAX_PACKET_SIZE];
|
static char logstashPacket[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
// load up the logstash packet with the key and the passed float value
|
// load up the logstash packet with the key and the passed float value
|
||||||
// send it to 4 decimal places
|
// send it to 4 decimal places
|
||||||
int numPacketBytes = sprintf(logstashPacket, "%s %.4f", key, value);
|
int numPacketBytes = sprintf(logstashPacket, "%c %s %.4f", valueType, key, value);
|
||||||
|
|
||||||
AgentList *agentList = AgentList::getInstance();
|
AgentList *agentList = AgentList::getInstance();
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,15 @@
|
||||||
const int LOGSTASH_UDP_PORT = 9500;
|
const int LOGSTASH_UDP_PORT = 9500;
|
||||||
const char LOGSTASH_HOSTNAME[] = "graphite.highfidelity.io";
|
const char LOGSTASH_HOSTNAME[] = "graphite.highfidelity.io";
|
||||||
|
|
||||||
|
const char STAT_TYPE_TIMER = 't';
|
||||||
|
const char STAT_TYPE_COUNTER = 'c';
|
||||||
|
const char STAT_TYPE_GAUGE = 'g';
|
||||||
|
|
||||||
class Logstash {
|
class Logstash {
|
||||||
public:
|
public:
|
||||||
static sockaddr* socket();
|
static sockaddr* socket();
|
||||||
static bool shouldSendStats();
|
static bool shouldSendStats();
|
||||||
static void stashValue(const char* key, float value);
|
static void stashValue(char statType, const char* key, float value);
|
||||||
private:
|
private:
|
||||||
static sockaddr_in logstashSocket;
|
static sockaddr_in logstashSocket;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue