Refresh live-state TTLs every 30s; expose Redis metrics in /status
This commit is contained in:
1 parent
97467a4f70
commit
d0b8a44dc7
3 files changed
+30
-1
No files matched your search
@@ -29,6 +29,7 @@ void onAsyncDisconnectThunk(const redisAsyncContext* ac, int status) {
|
|||||||
|
|
||||||
RedisStore::RedisStore(const Config& cfg) : m_cfg(cfg) {}
|
RedisStore::RedisStore(const Config& cfg) : m_cfg(cfg) {}
|
||||||
RedisStore::~RedisStore() {
|
RedisStore::~RedisStore() {
|
||||||
|
delete m_heartbeat_timer; m_heartbeat_timer = nullptr;
|
||||||
delete m_drain_timer; m_drain_timer = nullptr;
|
delete m_drain_timer; m_drain_timer = nullptr;
|
||||||
delete m_live_queue; m_live_queue = nullptr;
|
delete m_live_queue; m_live_queue = nullptr;
|
||||||
if (m_async) { redisAsyncFree(m_async); m_async = nullptr; }
|
if (m_async) { redisAsyncFree(m_async); m_async = nullptr; }
|
||||||
@@ -81,6 +82,10 @@ bool RedisStore::connect(void) {
|
|||||||
m_drain_timer->expired.connect(
|
m_drain_timer->expired.connect(
|
||||||
sigc::mem_fun(*this, &RedisStore::drainLiveQueue));
|
sigc::mem_fun(*this, &RedisStore::drainLiveQueue));
|
||||||
|
|
||||||
|
m_heartbeat_timer = new Async::Timer(30000, Async::Timer::TYPE_PERIODIC);
|
||||||
|
m_heartbeat_timer->expired.connect(
|
||||||
|
sigc::mem_fun(*this, &RedisStore::refreshLiveExpire));
|
||||||
|
|
||||||
std::cout << "RedisStore: connected sync+async, subscribed to "
|
std::cout << "RedisStore: connected sync+async, subscribed to "
|
||||||
<< channelName() << std::endl;
|
<< channelName() << std::endl;
|
||||||
return true;
|
return true;
|
||||||
@@ -226,6 +231,7 @@ void RedisStore::pushLiveTalker(uint32_t tg, const std::string& callsign,
|
|||||||
RedisLiveQueue::Op op;
|
RedisLiveQueue::Op op;
|
||||||
op.op = RedisLiveQueue::OpType::HSET;
|
op.op = RedisLiveQueue::OpType::HSET;
|
||||||
op.key = keyFor("live:talker:" + std::to_string(tg));
|
op.key = keyFor("live:talker:" + std::to_string(tg));
|
||||||
|
m_live_keys.insert(op.key);
|
||||||
op.fields = {
|
op.fields = {
|
||||||
{"callsign", callsign},
|
{"callsign", callsign},
|
||||||
{"started_at", std::to_string(std::time(nullptr))},
|
{"started_at", std::to_string(std::time(nullptr))},
|
||||||
@@ -240,6 +246,7 @@ void RedisStore::clearLiveTalker(uint32_t tg) {
|
|||||||
RedisLiveQueue::Op op;
|
RedisLiveQueue::Op op;
|
||||||
op.op = RedisLiveQueue::OpType::DEL;
|
op.op = RedisLiveQueue::OpType::DEL;
|
||||||
op.key = keyFor("live:talker:" + std::to_string(tg));
|
op.key = keyFor("live:talker:" + std::to_string(tg));
|
||||||
|
m_live_keys.erase(op.key);
|
||||||
m_live_queue->push(std::move(op));
|
m_live_queue->push(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +258,7 @@ void RedisStore::pushLiveClient(const std::string& callsign,
|
|||||||
RedisLiveQueue::Op op;
|
RedisLiveQueue::Op op;
|
||||||
op.op = RedisLiveQueue::OpType::HSET;
|
op.op = RedisLiveQueue::OpType::HSET;
|
||||||
op.key = keyFor("live:client:" + callsign);
|
op.key = keyFor("live:client:" + callsign);
|
||||||
|
m_live_keys.insert(op.key);
|
||||||
op.fields = {
|
op.fields = {
|
||||||
{"connected_at", std::to_string(std::time(nullptr))},
|
{"connected_at", std::to_string(std::time(nullptr))},
|
||||||
{"ip", ip},
|
{"ip", ip},
|
||||||
@@ -266,6 +274,7 @@ void RedisStore::clearLiveClient(const std::string& callsign) {
|
|||||||
RedisLiveQueue::Op op;
|
RedisLiveQueue::Op op;
|
||||||
op.op = RedisLiveQueue::OpType::DEL;
|
op.op = RedisLiveQueue::OpType::DEL;
|
||||||
op.key = keyFor("live:client:" + callsign);
|
op.key = keyFor("live:client:" + callsign);
|
||||||
|
m_live_keys.erase(op.key);
|
||||||
m_live_queue->push(std::move(op));
|
m_live_queue->push(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +285,7 @@ void RedisStore::pushLiveTrunk(const std::string& section,
|
|||||||
RedisLiveQueue::Op op;
|
RedisLiveQueue::Op op;
|
||||||
op.op = RedisLiveQueue::OpType::HSET;
|
op.op = RedisLiveQueue::OpType::HSET;
|
||||||
op.key = keyFor("live:trunk:" + section);
|
op.key = keyFor("live:trunk:" + section);
|
||||||
|
m_live_keys.insert(op.key);
|
||||||
op.fields = {
|
op.fields = {
|
||||||
{"state", state},
|
{"state", state},
|
||||||
{"peer_id", peer_id},
|
{"peer_id", peer_id},
|
||||||
@@ -368,7 +378,16 @@ void RedisStore::drainLiveQueue(Async::Timer*) {
|
|||||||
redisAsyncCommand(m_async, nullptr, nullptr,
|
redisAsyncCommand(m_async, nullptr, nullptr,
|
||||||
"PUBLISH %s tick", ch.c_str());
|
"PUBLISH %s tick", ch.c_str());
|
||||||
}
|
}
|
||||||
void RedisStore::refreshLiveExpire(Async::Timer*) {}
|
void RedisStore::refreshLiveExpire(Async::Timer*) {
|
||||||
|
if (!m_live_queue) return;
|
||||||
|
for (const std::string& k : m_live_keys) {
|
||||||
|
RedisLiveQueue::Op op;
|
||||||
|
op.op = RedisLiveQueue::OpType::EXPIRE;
|
||||||
|
op.key = k;
|
||||||
|
op.ttl_s = 60;
|
||||||
|
m_live_queue->push(std::move(op));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string RedisStore::keyFor(const std::string& suffix) const {
|
std::string RedisStore::keyFor(const std::string& suffix) const {
|
||||||
if (m_cfg.key_prefix.empty()) return suffix;
|
if (m_cfg.key_prefix.empty()) return suffix;
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ class RedisStore : public sigc::trackable
|
|||||||
Async::Timer* m_heartbeat_timer = nullptr;
|
Async::Timer* m_heartbeat_timer = nullptr;
|
||||||
int m_reconnect_backoff_s = 1;
|
int m_reconnect_backoff_s = 1;
|
||||||
uint64_t m_dropped_live_writes = 0;
|
uint64_t m_dropped_live_writes = 0;
|
||||||
|
std::set<std::string> m_live_keys;
|
||||||
|
|
||||||
bool connectSync(void);
|
bool connectSync(void);
|
||||||
bool connectAsync(void);
|
bool connectAsync(void);
|
||||||
|
|||||||
@@ -1763,6 +1763,15 @@ void Reflector::refreshStatus(void)
|
|||||||
m_status["satellite_server"] = sat_srv;
|
m_status["satellite_server"] = sat_srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (m_redis != nullptr)
|
||||||
|
{
|
||||||
|
Json::Value redis_status(Json::objectValue);
|
||||||
|
redis_status["live_queue_size"] =
|
||||||
|
static_cast<Json::UInt>(m_redis->liveQueueSize());
|
||||||
|
redis_status["dropped_live_writes"] =
|
||||||
|
static_cast<Json::UInt64>(m_redis->droppedLiveWrites());
|
||||||
|
m_status["redis"] = redis_status;
|
||||||
|
}
|
||||||
} /* Reflector::refreshStatus */
|
} /* Reflector::refreshStatus */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user