mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
feat(server): add total_connections_received statistics (#757)
In addition: 1. improve logging of received commands 2. provide stable ordering of error stats and commandstats Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
cc74594c2f
commit
448508a23a
5 changed files with 35 additions and 16 deletions
|
@ -451,7 +451,8 @@ io::Result<bool> Connection::CheckForHttpProto(FiberSocketBase* peer) {
|
|||
void Connection::ConnectionFlow(FiberSocketBase* peer) {
|
||||
auto dispatch_fb = fibers::fiber(fibers::launch::dispatch, [&] { DispatchFiber(peer); });
|
||||
ConnectionStats* stats = service_->GetThreadLocalConnectionStats();
|
||||
stats->num_conns++;
|
||||
++stats->num_conns;
|
||||
++stats->conn_received_cnt;
|
||||
stats->read_buf_capacity += io_buf_.Capacity();
|
||||
|
||||
ParserStatus parse_status = OK;
|
||||
|
|
|
@ -21,7 +21,7 @@ constexpr size_t kSizeConnStats = sizeof(ConnectionStats);
|
|||
|
||||
ConnectionStats& ConnectionStats::operator+=(const ConnectionStats& o) {
|
||||
// To break this code deliberately if we add/remove a field to this struct.
|
||||
static_assert(kSizeConnStats == 168);
|
||||
static_assert(kSizeConnStats == 176);
|
||||
|
||||
ADD(read_buf_capacity);
|
||||
ADD(io_read_cnt);
|
||||
|
@ -32,7 +32,7 @@ ConnectionStats& ConnectionStats::operator+=(const ConnectionStats& o) {
|
|||
ADD(pipelined_cmd_cnt);
|
||||
ADD(parser_err_cnt);
|
||||
ADD(async_writes_cnt);
|
||||
|
||||
ADD(conn_received_cnt);
|
||||
ADD(num_conns);
|
||||
ADD(num_replicas);
|
||||
ADD(num_blocked_clients);
|
||||
|
|
|
@ -40,8 +40,9 @@ struct ConnectionStats {
|
|||
size_t pipelined_cmd_cnt = 0;
|
||||
size_t parser_err_cnt = 0;
|
||||
|
||||
// Writes count that happened via SendRawMessageAsync call.
|
||||
size_t async_writes_cnt = 0;
|
||||
// Writes count that happened via DispatchOperations call.
|
||||
uint64_t async_writes_cnt = 0;
|
||||
uint64_t conn_received_cnt = 0;
|
||||
|
||||
uint32_t num_conns = 0;
|
||||
uint32_t num_replicas = 0;
|
||||
|
|
|
@ -525,7 +525,13 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
|
|||
|
||||
ToUpper(&args[0]);
|
||||
|
||||
VLOG(2) << "Got: " << args;
|
||||
ConnectionContext* dfly_cntx = static_cast<ConnectionContext*>(cntx);
|
||||
bool under_script = dfly_cntx->conn_state.script_info.has_value();
|
||||
|
||||
if (VLOG_IS_ON(2)) {
|
||||
const char* lua = under_script ? "LUA " : "";
|
||||
LOG(INFO) << "Got (" << cntx->owner()->GetClientId() << "): " << lua << args;
|
||||
}
|
||||
|
||||
string_view cmd_str = ArgS(args, 0);
|
||||
bool is_trans_cmd = (cmd_str == "EXEC" || cmd_str == "MULTI" || cmd_str == "DISCARD");
|
||||
|
@ -534,7 +540,6 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
|
|||
|
||||
etl.RecordCmd();
|
||||
|
||||
ConnectionContext* dfly_cntx = static_cast<ConnectionContext*>(cntx);
|
||||
absl::Cleanup multi_error([dfly_cntx] { MultiSetError(dfly_cntx); });
|
||||
|
||||
if (cid == nullptr) {
|
||||
|
@ -567,8 +572,6 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
|
|||
return (*cntx)->SendError("Replica can't interact with the keyspace");
|
||||
}
|
||||
|
||||
bool under_script = dfly_cntx->conn_state.script_info.has_value();
|
||||
|
||||
if (under_script && (cid->opt_mask() & CO::NOSCRIPT)) {
|
||||
return (*cntx)->SendError("This Redis command is not allowed from script");
|
||||
}
|
||||
|
|
|
@ -676,6 +676,9 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) {
|
|||
}
|
||||
|
||||
// Stats metrics
|
||||
AppendMetricWithoutLabels("connections_received_total", "", m.conn_stats.conn_received_cnt,
|
||||
MetricType::COUNTER, &resp->body());
|
||||
|
||||
AppendMetricWithoutLabels("commands_processed_total", "", m.conn_stats.command_cnt,
|
||||
MetricType::COUNTER, &resp->body());
|
||||
AppendMetricWithoutLabels("keyspace_hits_total", "", m.events.hits, MetricType::COUNTER,
|
||||
|
@ -1308,8 +1311,9 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
|
|||
if (should_enter("STATS")) {
|
||||
ADD_HEADER("# Stats");
|
||||
|
||||
append("instantaneous_ops_per_sec", m.qps);
|
||||
append("total_connections_received", m.conn_stats.conn_received_cnt);
|
||||
append("total_commands_processed", m.conn_stats.command_cnt);
|
||||
append("instantaneous_ops_per_sec", m.qps);
|
||||
append("total_pipelined_commands", m.conn_stats.pipelined_cmd_cnt);
|
||||
append("total_net_input_bytes", m.conn_stats.io_read_bytes);
|
||||
append("total_net_output_bytes", m.conn_stats.io_write_bytes);
|
||||
|
@ -1403,13 +1407,23 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
|
|||
|
||||
auto unknown_cmd = service_.UknownCmdMap();
|
||||
|
||||
for (const auto& k_v : unknown_cmd) {
|
||||
append(StrCat("unknown_", k_v.first), k_v.second);
|
||||
}
|
||||
auto append_sorted = [&append](string_view prefix, const auto& map) {
|
||||
vector<pair<string_view, uint64_t>> display;
|
||||
display.reserve(map.size());
|
||||
|
||||
for (const auto& k_v : m.conn_stats.cmd_count_map) {
|
||||
append(StrCat("cmd_", k_v.first), k_v.second);
|
||||
}
|
||||
for (const auto& k_v : map) {
|
||||
display.push_back(k_v);
|
||||
};
|
||||
|
||||
sort(display.begin(), display.end());
|
||||
|
||||
for (const auto& k_v : display) {
|
||||
append(StrCat(prefix, k_v.first), k_v.second);
|
||||
}
|
||||
};
|
||||
|
||||
append_sorted("unknown_", unknown_cmd);
|
||||
append_sorted("cmd_", m.conn_stats.cmd_count_map);
|
||||
}
|
||||
|
||||
if (should_enter("ERRORSTATS", true)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue