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:
Andrzej Kapolka 2013-07-02 14:52:08 -07:00
commit bf4757663c
7 changed files with 41 additions and 23 deletions

View file

@ -138,7 +138,7 @@ int main(int argc, const char* argv[]) {
const char MIXER_LOGSTASH_METRIC_NAME[] = "audio-mixer-frame-time-usage";
float averageFrameTimePercentage = sumFrameTimePercentages / numStatCollections;
Logstash::stashValue(MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage);
Logstash::stashValue(STAT_TYPE_GAUGE, MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage);
sumFrameTimePercentages = 0.0f;
numStatCollections = 0;

View file

@ -17,35 +17,23 @@
// M - Audio Mixer
//
#include <iostream>
#include <fcntl.h>
#include <map>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <map>
#include "AgentList.h"
#include "AgentTypes.h"
#include <PacketHeaders.h>
#include "Logstash.h"
#include "PacketHeaders.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;
unsigned char packetData[MAX_PACKET_SIZE];
const int LOGOFF_CHECK_INTERVAL = 5000;
int lastActiveCount = 0;
const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
*currentPosition++ = agentToAdd->getType();
@ -94,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)) {
@ -185,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::stashValue(STAT_TYPE_GAUGE, NODE_COUNT_LOGSTASH_KEY, agentList->getNumAliveAgents());
gettimeofday(&lastStatSendTime, NULL);
}
}
}
return 0;

View file

@ -350,7 +350,7 @@ void Application::initializeGL() {
const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-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

View file

@ -191,6 +191,18 @@ Agent* AgentList::agentWithID(uint16_t agentID) {
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) {
delete _agentTypesOfInterest;

View file

@ -63,6 +63,7 @@ public:
void(*linkedDataCreateCallback)(Agent *);
int size() { return _numAgents; }
int getNumAliveAgents() const;
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }

View file

@ -45,12 +45,12 @@ bool Logstash::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];
// load up the logstash packet with the key and the passed float value
// 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();

View file

@ -14,11 +14,15 @@
const int LOGSTASH_UDP_PORT = 9500;
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 {
public:
static sockaddr* socket();
static bool shouldSendStats();
static void stashValue(const char* key, float value);
static void stashValue(char statType, const char* key, float value);
private:
static sockaddr_in logstashSocket;
};