diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index c19aba0a9c..5f9b79264c 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -137,15 +137,8 @@ int main(int argc, const char* argv[]) { // if we should be sending stats to Logstash send the appropriate average now const char MIXER_LOGSTASH_METRIC_NAME[] = "audio-mixer-frame-time-usage"; - // we're sending a floating point percentage with two mandatory numbers after decimal point - // that could be up to 6 bytes - const int MIXER_LOGSTASH_PACKET_BYTES = strlen(MIXER_LOGSTASH_METRIC_NAME) + 7; - char logstashPacket[MIXER_LOGSTASH_PACKET_BYTES]; - float averageFrameTimePercentage = sumFrameTimePercentages / numStatCollections; - int packetBytes = sprintf(logstashPacket, "%s %.2f", MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage); - - agentList->getAgentSocket()->send(Logstash::socket(), logstashPacket, packetBytes); + Logstash::stashValue(MIXER_LOGSTASH_METRIC_NAME, averageFrameTimePercentage); sumFrameTimePercentages = 0.0f; numStatCollections = 0; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 06974743f0..6c491f8e06 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -44,14 +44,15 @@ #include #include #include -#include #include -#include -#include #include #include +#include #include +#include +#include +#include #include "Application.h" #include "InterfaceConfig.h" @@ -286,12 +287,17 @@ void Application::initializeGL() { idleTimer->start(0); if (_justStarted) { - float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime))/1000000.0; + float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0; _justStarted = false; char title[50]; sprintf(title, "Interface: %4.2f seconds\n", startupTime); printLog("%s", title); _window->setWindowTitle(title); + + 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); } // update before the first render diff --git a/libraries/shared/src/Logstash.cpp b/libraries/shared/src/Logstash.cpp index dbbf7f8ec3..94279fdd4a 100644 --- a/libraries/shared/src/Logstash.cpp +++ b/libraries/shared/src/Logstash.cpp @@ -11,6 +11,7 @@ #include #include "SharedUtil.h" +#include "AgentList.h" #include "Logstash.h" @@ -42,4 +43,18 @@ sockaddr* Logstash::socket() { bool Logstash::shouldSendStats() { static bool shouldSendStats = isInEnvironment("production"); return shouldSendStats; +} + +void Logstash::stashValue(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); + + AgentList *agentList = AgentList::getInstance(); + + if (agentList) { + agentList->getAgentSocket()->send(socket(), logstashPacket, numPacketBytes); + } } \ No newline at end of file diff --git a/libraries/shared/src/Logstash.h b/libraries/shared/src/Logstash.h index 20f58b8057..5f2d247218 100644 --- a/libraries/shared/src/Logstash.h +++ b/libraries/shared/src/Logstash.h @@ -18,6 +18,7 @@ class Logstash { public: static sockaddr* socket(); static bool shouldSendStats(); + static void stashValue(const char* key, float value); private: static sockaddr_in logstashSocket; };