(redis cobra bots) update the cobra to redis bot to use the bot framework, and change it to report fps metrics into redis streams.
This commit is contained in:
@ -9,6 +9,7 @@ set (IXBOTS_SOURCES
|
||||
ixbots/IXCobraToStatsdBot.cpp
|
||||
ixbots/IXCobraToStdoutBot.cpp
|
||||
ixbots/IXCobraMetricsToStatsdBot.cpp
|
||||
ixbots/IXCobraMetricsToRedisBot.cpp
|
||||
ixbots/IXStatsdClient.cpp
|
||||
)
|
||||
|
||||
@ -19,6 +20,7 @@ set (IXBOTS_HEADERS
|
||||
ixbots/IXCobraToStatsdBot.h
|
||||
ixbots/IXCobraToStdoutBot.h
|
||||
ixbots/IXCobraMetricsToStatsdBot.h
|
||||
ixbots/IXCobraMetricsToRedisBot.h
|
||||
ixbots/IXStatsdClient.h
|
||||
)
|
||||
|
||||
@ -38,6 +40,7 @@ set(IXBOTS_INCLUDE_DIRS
|
||||
../ixcore
|
||||
../ixwebsocket
|
||||
../ixcobra
|
||||
../ixredis
|
||||
../ixsentry
|
||||
${JSONCPP_INCLUDE_DIRS}
|
||||
${SPDLOG_INCLUDE_DIRS})
|
||||
|
@ -292,4 +292,22 @@ namespace ix
|
||||
{
|
||||
_onBotMessageCallback = callback;
|
||||
}
|
||||
|
||||
std::string CobraBot::getDeviceIdentifier(const Json::Value& msg)
|
||||
{
|
||||
std::string deviceId("na");
|
||||
|
||||
auto osName = msg["device"]["os_name"];
|
||||
if (osName == "Android")
|
||||
{
|
||||
deviceId = msg["device"]["model"].asString();
|
||||
}
|
||||
else if (osName == "iOS")
|
||||
{
|
||||
deviceId = msg["device"]["hardware_model"].asString();
|
||||
}
|
||||
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
} // namespace ix
|
||||
|
@ -28,6 +28,8 @@ namespace ix
|
||||
int64_t run(const CobraBotConfig& botConfig);
|
||||
void setOnBotMessageCallback(const OnBotMessageCallback& callback);
|
||||
|
||||
std::string getDeviceIdentifier(const Json::Value& msg);
|
||||
|
||||
private:
|
||||
OnBotMessageCallback _onBotMessageCallback;
|
||||
};
|
||||
|
118
ixbots/ixbots/IXCobraMetricsToRedisBot.cpp
Normal file
118
ixbots/ixbots/IXCobraMetricsToRedisBot.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* IXCobraMetricsToRedisBot.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "IXCobraMetricsToRedisBot.h"
|
||||
|
||||
#include "IXCobraBot.h"
|
||||
#include "IXStatsdClient.h"
|
||||
#include <chrono>
|
||||
#include <ixcobra/IXCobraConnection.h>
|
||||
#include <ixcore/utils/IXCoreLogger.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string removeSpaces(const std::string& str)
|
||||
{
|
||||
std::string out(str);
|
||||
out.erase(
|
||||
std::remove_if(out.begin(), out.end(), [](unsigned char x) { return std::isspace(x); }),
|
||||
out.end());
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ix
|
||||
{
|
||||
bool processPerfMetricsEventSlowFrames(const Json::Value& msg,
|
||||
RedisClient& redisClient,
|
||||
const std::string& deviceId)
|
||||
{
|
||||
auto frameRateHistogramCounts = msg["data"]["FrameRateHistogramCounts"];
|
||||
|
||||
int slowFrames = 0;
|
||||
slowFrames += frameRateHistogramCounts[4].asInt();
|
||||
slowFrames += frameRateHistogramCounts[5].asInt();
|
||||
slowFrames += frameRateHistogramCounts[6].asInt();
|
||||
slowFrames += frameRateHistogramCounts[7].asInt();
|
||||
|
||||
std::stringstream ss;
|
||||
ss << msg["id"].asString() << "_slow_frames" << "."
|
||||
<< msg["device"]["game"].asString() << "."
|
||||
<< msg["device"]["os_name"].asString() << "."
|
||||
<< removeSpaces(msg["data"]["Tag"].asString());
|
||||
|
||||
std::string id = ss.str();
|
||||
std::string errMsg;
|
||||
if (redisClient.xadd(id, std::to_string(slowFrames), errMsg).empty())
|
||||
{
|
||||
CoreLogger::info(std::string("redis xadd error: ") + errMsg);
|
||||
}
|
||||
|
||||
if (deviceId == "N841AP" || deviceId == "SM-N960U")
|
||||
{
|
||||
ss.str(""); // reset the stringstream
|
||||
ss << msg["id"].asString() << "_slow_frames_by_device" << "."
|
||||
<< deviceId << "."
|
||||
<< msg["device"]["game"].asString() << "."
|
||||
<< msg["device"]["os_name"].asString() << "."
|
||||
<< removeSpaces(msg["data"]["Tag"].asString());
|
||||
|
||||
std::string id = ss.str();
|
||||
if (redisClient.xadd(id, std::to_string(slowFrames), errMsg).empty())
|
||||
{
|
||||
CoreLogger::info(std::string("redis xadd error: ") + errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t cobra_metrics_to_redis_bot(const ix::CobraBotConfig& config,
|
||||
RedisClient& redisClient,
|
||||
bool verbose)
|
||||
{
|
||||
CobraBot bot;
|
||||
|
||||
bot.setOnBotMessageCallback(
|
||||
[&redisClient, &verbose, &bot]
|
||||
(const Json::Value& msg,
|
||||
const std::string& /*position*/,
|
||||
std::atomic<bool>& /*throttled*/,
|
||||
std::atomic<bool>& /*fatalCobraError*/,
|
||||
std::atomic<uint64_t>& sentCount) -> void {
|
||||
if (msg["device"].isNull() || msg["id"].isNull())
|
||||
{
|
||||
CoreLogger::info("no device or id entry, skipping event");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Display full message with
|
||||
if (verbose)
|
||||
{
|
||||
CoreLogger::info(msg.toStyledString());
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
if (msg["id"].asString() == "engine_performance_metrics_id")
|
||||
{
|
||||
auto deviceId = bot.getDeviceIdentifier(msg);
|
||||
success = processPerfMetricsEventSlowFrames(msg, redisClient, deviceId);
|
||||
}
|
||||
|
||||
if (success) sentCount++;
|
||||
});
|
||||
|
||||
return bot.run(config);
|
||||
}
|
||||
} // namespace ix
|
20
ixbots/ixbots/IXCobraMetricsToRedisBot.h
Normal file
20
ixbots/ixbots/IXCobraMetricsToRedisBot.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* IXCobraMetricsToRedisBot.h
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <ixredis/IXRedisClient.h>
|
||||
#include "IXCobraBotConfig.h"
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
int64_t cobra_metrics_to_redis_bot(const ix::CobraBotConfig& config,
|
||||
RedisClient& redisClient,
|
||||
bool verbose);
|
||||
} // namespace ix
|
||||
|
Reference in New Issue
Block a user