#pragma once #include #include #include "envoy/buffer/buffer.h" #include "envoy/http/codes.h" #include "envoy/http/header_map.h" #include "envoy/server/admin.h" #include "envoy/server/instance.h" #include "common/stats/histogram_impl.h" #include "server/admin/handler_ctx.h" #include "absl/strings/string_view.h" namespace Envoy { namespace Server { class StatsHandler : public HandlerContextBase { public: StatsHandler(Server::Instance& server); Http::Code handlerResetCounters(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerStatsRecentLookups(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerStatsRecentLookupsClear(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerStatsRecentLookupsDisable(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerStatsRecentLookupsEnable(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerStats(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerPrometheusStats(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); Http::Code handlerContention(absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, AdminStream&); private: template static bool shouldShowMetric(const StatType& metric, const bool used_only, const absl::optional& regex) { return ((!used_only || metric.used()) && (!regex.has_value() || std::regex_search(metric.name(), regex.value()))); } friend class AdminStatsTest; static std::string statsAsJson(const std::map& all_stats, const std::map& text_readouts, const std::vector& all_histograms, bool used_only, const absl::optional regex = absl::nullopt, bool pretty_print = false); }; } // namespace Server } // namespace Envoy