2021-11-18 20:17:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-03-03 06:30:22 +00:00
|
|
|
#include <atomic>
|
2021-11-18 20:17:22 +00:00
|
|
|
#include <base/types.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Request statistics for connection or dispatcher
|
|
|
|
class KeeperConnectionStats
|
|
|
|
{
|
|
|
|
public:
|
2022-03-03 06:30:22 +00:00
|
|
|
KeeperConnectionStats()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
2021-11-18 20:17:22 +00:00
|
|
|
|
|
|
|
uint64_t getMinLatency() const;
|
|
|
|
uint64_t getMaxLatency() const;
|
|
|
|
|
|
|
|
uint64_t getAvgLatency() const;
|
|
|
|
uint64_t getLastLatency() const;
|
|
|
|
|
|
|
|
uint64_t getPacketsReceived() const;
|
|
|
|
uint64_t getPacketsSent() const;
|
|
|
|
|
|
|
|
void incrementPacketsReceived();
|
|
|
|
void incrementPacketsSent();
|
|
|
|
|
|
|
|
void updateLatency(uint64_t latency_ms);
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void resetLatency();
|
|
|
|
void resetRequestCounters();
|
|
|
|
|
|
|
|
/// all response with watch response included
|
2022-03-03 06:30:22 +00:00
|
|
|
std::atomic_uint64_t packets_sent;
|
2021-11-18 20:17:22 +00:00
|
|
|
/// All user requests
|
2022-03-03 06:30:22 +00:00
|
|
|
std::atomic_uint64_t packets_received;
|
2021-11-18 20:17:22 +00:00
|
|
|
|
|
|
|
/// For consistent with zookeeper measured by millisecond,
|
|
|
|
/// otherwise maybe microsecond is better
|
2022-03-03 06:30:22 +00:00
|
|
|
std::atomic_uint64_t total_latency;
|
|
|
|
std::atomic_uint64_t max_latency;
|
|
|
|
std::atomic_uint64_t min_latency;
|
2021-11-18 20:17:22 +00:00
|
|
|
|
|
|
|
/// last operation latency
|
2022-03-03 06:30:22 +00:00
|
|
|
std::atomic_uint64_t last_latency;
|
2021-11-18 20:17:22 +00:00
|
|
|
|
2022-03-03 06:30:22 +00:00
|
|
|
std::atomic_uint64_t count;
|
2021-11-18 20:17:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|