userver: server::handlers::ServerMonitor Class Reference
Loading...
Searching...
No Matches
server::handlers::ServerMonitor Class Referencefinal

#include <userver/server/handlers/server_monitor.hpp>

Detailed Description

Handler that returns statistics data.

Additionally to the common handler options the component has 'common-labels' option that should be a map of label name to label value. Items of the map are added to each metric.

Default format can be set via 'format' option. Supported formats are: "prometheus", "prometheus-untyped", "graphite", "json", "solomon", "pretty" and "internal". For more info see the documentation for utils::statistics::ToPrometheusFormat, utils::statistics::ToPrometheusFormatUntyped, utils::statistics::ToGraphiteFormat, utils::statistics::ToJsonFormat, utils::statistics::ToSolomonFormat, utils::statistics::ToPrettyFormat.

Static configuration example:

# yaml
handler-server-monitor:
path: /statistics
method: GET
task_processor: monitor-task-processor
common-labels:
application: sample application
zone: some
format: json

Scheme

Accepts a path arguments 'format', 'labels', 'path' and 'prefix':

  • format - overrides default format option if it's present. Make sure that you provide at least one of two formats.
  • labels - filter out metrics without the provided labels. Parameter should be a JSON dictionary in the form '{"label1":"value1", "label2":"value2"}'.
  • path - return metrics on for the following path
  • prefix - return metrics whose path starts from the specified prefix.
Examples
samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp.

Definition at line 48 of file server_monitor.hpp.

+ Inheritance diagram for server::handlers::ServerMonitor:
+ Collaboration diagram for server::handlers::ServerMonitor:

Public Member Functions

 ServerMonitor (const components::ComponentConfig &config, const components::ComponentContext &component_context)
 
std::string HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &) const override
 
- Public Member Functions inherited from server::handlers::HttpHandlerBase
 HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
void HandleRequest (request::RequestBase &request, request::RequestContext &context) const override
 
void ReportMalformedRequest (request::RequestBase &request) const final
 
virtual const std::string & HandlerName () const
 
const std::vector< http::HttpMethod > & GetAllowedMethods () const
 
virtual logging::Level GetLogLevelForResponseStatus (http::HttpStatus status) const
 
virtual FormattedErrorData GetFormattedExternalErrorBody (const CustomHandlerException &exc) const
 
std::string GetResponseDataForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const
 
void HandleCustomHandlerException (const http::HttpRequest &request, const CustomHandlerException &ex) const
 
void HandleUnknownException (const http::HttpRequest &request, const std::exception &ex) const
 
void LogUnknownException (const std::exception &ex) const
 Helper function to log an unknown exception.
 
const std::optional< logging::Level > & GetLogLevel () const
 Returns the default log level for the handler.
 
- Public Member Functions inherited from server::handlers::HandlerBase
 HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
bool IsMonitor () const
 Returns whether this is a monitoring handler.
 
const HandlerConfigGetConfig () const
 Returns handler config.
 
- Public Member Functions inherited from components::LoggableComponentBase
 LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
 
 LoggableComponentBase (LoggableComponentBase &&)=delete
 
 LoggableComponentBase (const LoggableComponentBase &)=delete
 
 ~LoggableComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HttpHandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr std::string_view kName = "handler-server-monitor"
 The default name of server::handlers::ServerMonitor.
 

Additional Inherited Members

- Protected Types inherited from server::handlers::HandlerBase
using HandlerErrorCode = handlers::HandlerErrorCode
 
using InternalMessage = handlers::InternalMessage
 
using ExternalBody = handlers::ExternalBody
 
using ClientError = handlers::ClientError
 
using InternalServerError = handlers::InternalServerError
 
- Protected Member Functions inherited from server::handlers::HttpHandlerBase
void ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const
 
virtual void OnRequestCompleteThrow (const http::HttpRequest &, request::RequestContext &) const
 
virtual void HandleStreamRequest (const server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const
 
virtual bool IsStreamed () const
 
virtual bool IsMethodStatisticIncluded () const
 
virtual bool NeedCheckAuth () const
 
virtual std::string GetRequestBodyForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &request_body) const
 Override it if you need a custom request body logging.
 
virtual void ParseRequestData (const http::HttpRequest &, request::RequestContext &) const
 
virtual std::string GetMetaType (const http::HttpRequest &) const
 

Member Function Documentation

◆ HandleRequestThrow()

std::string server::handlers::ServerMonitor::HandleRequestThrow ( const http::HttpRequest & request,
request::RequestContext & context ) const
overridevirtual

The core method for HTTP request handling. request arg contains HTTP headers, full body, etc. The method should return response body.

Note
It is used only if IsStreamed() returned false.

Reimplemented from server::handlers::HttpHandlerBase.


The documentation for this class was generated from the following file: