From a9f7d037d1cddc3575f71592a4896de2d7bf9716 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 20 Jun 2013 15:33:54 -0700 Subject: [PATCH 1/3] add a helper to the logstash class to stash a value --- libraries/shared/src/Logstash.cpp | 15 +++++++++++++++ libraries/shared/src/Logstash.h | 1 + 2 files changed, 16 insertions(+) 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; }; From 8b7b0d542ae94dfa876ac87b0afb6d33cc807a1e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 20 Jun 2013 15:34:17 -0700 Subject: [PATCH 2/3] send the interface startup time to log stash --- interface/src/Application.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6954339cee..dc1e95aaeb 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 From 72f7db2ec7919cceebf13447226c7e1a3e9c310f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 20 Jun 2013 15:35:39 -0700 Subject: [PATCH 3/3] use the stashValue helper to send the audio-mixer stat --- audio-mixer/src/main.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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;