关注 spark技术分享,
撸spark源码 玩spark最佳实践

MetricsServlet JSON Metrics Sink

MetricsServlet JSON Metrics Sink

MetricsServlet is a metrics sink that gives metrics snapshots in JSON format.

MetricsServlet is a “special” sink as it is only available to the metrics instances with a web UI:

  • Driver of a Spark application

  • Spark Standalone’s Master and Worker

You can access the metrics from MetricsServlet at /metrics/json URI by default. The entire URL depends on a metrics instance, e.g. http://localhost:4040/metrics/json/ for a running Spark application.

MetricsServlet is created exclusively when MetricsSystem is started (and requested to register metrics sinks).

MetricsServlet can be configured using configuration properties with sink.servlet prefix (in metrics configuration). That is not required since MetricsConfig makes sure that MetricsServlet is always configured.

MetricsServlet uses jackson-databind, the general data-binding package for Jackson (as ObjectMapper) with Dropwizard Metrics library (i.e. registering a Coda Hale MetricsModule).

Table 1. MetricsServlet’s Configuration Properties
Name Default Description

path

/metrics/json/

Path URI prefix to bind to

sample

false

Whether to show entire set of samples for histograms

Table 2. MetricsServlet’s Internal Properties (e.g. Registries, Counters and Flags)
Name Description

mapper

Jaxson’s com.fasterxml.jackson.databind.ObjectMapper that “provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions.”

When created, mapper is requested to register a Coda Hale com.codahale.metrics.json.MetricsModule.

Used exclusively when MetricsServlet is requested to getMetricsSnapshot.

servletPath

Value of path configuration property

servletShowSample

Flag to control whether to show samples (true) or not (false).

servletShowSample is the value of sample configuration property (if defined) or false.

Used when ObjectMapper is requested to register a Coda Hale com.codahale.metrics.json.MetricsModule.

Creating MetricsServlet Instance

MetricsServlet takes the following when created:

  • Configuration Properties (as Java Properties)

  • Dropwizard Metrics’ MetricRegistry

  • SecurityManager

MetricsServlet initializes the internal registries and counters.

Requesting Metrics Snapshot — getMetricsSnapshot Method

getMetricsSnapshot simply requests the Jackson ObjectMapper to serialize the MetricRegistry to a JSON string (using ObjectMapper.writeValueAsString).

Note
getMetricsSnapshot is used exclusively when MetricsServlet is requested to getHandlers.

Requesting JSON Servlet Handler — getHandlers Method

getHandlers returns just a single ServletContextHandler (in a collection) that gives metrics snapshot in JSON format at every request at servletPath URI path.

Note
getHandlers is used exclusively when MetricsSystem is requested for metrics ServletContextHandlers.
赞(0) 打赏
未经允许不得转载:spark技术分享 » MetricsServlet JSON Metrics Sink
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏