Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
210 lines (193 sloc) 7.68 KB
---
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
title: "Container Metrics"
---
<p>Vespa reports a certain number of standard metrics. You can also set up
Vespa to report your own custom metrics.</p>
<h2 id="metrics-from-custom-components">Metrics from custom components</h2>
<ol>
<li>Add a <em>MetricReceiver</em>
(<a href="http://javadoc.io/page/com.yahoo.vespa/simplemetrics/latest/com/yahoo/metrics/simple/MetricReceiver.html">
com.yahoo.metrics.simple.MetricReceiver</a>)
instance to the constructor of the component in question - it is injected by the container</li>
<li>Declare the <em>gauges</em> and <em>counters</em> using the <em>declare</em>
methods on the metric receiver. Optionally set arbitrary metric
dimensions to default values at declaration time -
refer to the javadoc for details</li>
<li>Each time there is some data to measure, invoke the <em>sample</em> method on
gauges or the <em>add</em> method on counters. When sampling data, any dimensions
can optionally be set</li>
</ol>
<p>
The gauges and counters declared are inherently thread safe. Example:
<pre>
package com.yahoo.example;
import java.util.Optional;
import com.yahoo.metrics.simple.Gauge;
import com.yahoo.metrics.simple.MetricSettings;
import com.yahoo.metrics.simple.MetricReceiver;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.search.searchchain.Execution;
public class HitCountSearcher extends Searcher {
private static final String LANGUAGE_DIMENSION_NAME = "query_language";
private static final String EXAMPLE_METRIC_NAME = "example_hitcounts";
private final Gauge hitCountMetric;
public HitCountSearcher(MetricReceiver receiver) {
this.hitCountMetric = receiver.declareGauge(EXAMPLE_METRIC_NAME, Optional.empty(),
new MetricSettings.Builder().histogram(true).build());
}
@Override
public Result search(Query query, Execution execution) {
Result result = execution.search(query);
hitCountMetric
.sample(result.getTotalHitCount(),
hitCountMetric.builder()
.set(LANGUAGE_DIMENSION_NAME, query.getModel().getParsingLanguage().languageCode())
.build());
return result;
}
}
</pre>
Then look at the <a href="../reference/metrics-health-format.html#metrics-api">Metrics API</a>
where the new event <em>example_hitcounts</em> is available in the list of metrics.
The histograms for the last five minutes of logged data are available as CSV per
dimension at <em>http://host:port/state/v1/metrics/histograms</em>.
In the example, that would include the estimated total hit counts for queries, grouped
by language. The underlying implementation of the histograms is
<a href="http://hdrhistogram.org/">HdrHistogram</a>, and the CSV is simply what
that library generates itself.
</p>
<h2 id="http-server-metrics">Http Server metrics</h2>
<p>
The metrics from the built-in HTTP server are available in JSON using the
<a href="../reference/metrics-health-format.html">metrics API</a>.
</p><p>
The Container HTTP server is based on Jetty.
Some of the metrics are gathered from the Jetty <code>StatisticsHandler</code>
or <code>ConnectorStatistics</code>, with names familiar to those used to working with Jetty.
Other metrics are JDisc specific.
Some of the metrics are emitted with two separate names,
for compatibility with different metrics frameworks.
</p><p>
In <em>services.xml</em>-terminology, a <code>server</code> means a Jetty connector,
while there is always only one Jetty server per node in a JDisc cluster.
</p>
<h3 id="server-wide-metrics">Server-wide Metrics</h3>
<p>
These metrics are output for the server as a whole, across all connectors,
as opposed to the per-connector metrics listed in the next section.
</p>
<table class="table">
<thead>
<tr>
<th>Metric name</th><th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>serverStartedMillis</td>
<td>Time since server started</td>
</tr><tr>
<td>mem.heap.total</td>
<td>Total heap size</td>
</tr><tr>
<td>mem.heap.free</td>
<td>Free heap size</td>
</tr><tr>
<td>mem.heap.used</td>
<td>Used heap size</td>
</tr><tr>
<td>serverThreadPoolSize</td>
<td>Size of the thread pool for request processing</td>
</tr><tr>
<td>serverActiveThreads</td>
<td>Number of threads that are active processing requests</td>
</tr><tr>
<td>serverRejectedRequests</td>
<td>Number of requests rejected by the thread pool</td>
</tr><tr>
<td>jdisc.http.requests.status</td>
<td>Number of requests to the built-in status handler</td>
</tr><tr>
<td>http.status.1xx</td>
<td>Number of responses with a 1xx status</td>
</tr><tr>
<td>http.status.2xx</td>
<td>Number of responses with a 2xx status</td>
</tr><tr>
<td>http.status.3xx</td>
<td>Number of responses with a 3xx status</td>
</tr><tr>
<td>http.status.4xx</td>
<td>Number of responses with a 4xx status</td>
</tr><tr>
<td>http.status.5xx</td>
<td>Number of responses with a 5xx status</td>
</tr>
</tbody>
</table>
<h3 id="per-connector-metrics">Per-connector Metrics</h3>
<p>
These metrics are output for each connector in the Jetty server.
</p>
<table class="table">
<thead>
<tr>
<th>Metric name</th><th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>serverNumConnections</td>
<td>See Jetty <a
href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ConnectorStatistics.html">ConnectorStatistics
</a></td>
</tr><tr>
<td>serverNumOpenConnections</td>
<td>See Jetty <a
href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ConnectorStatistics.html">ConnectorStatistics
</a></td>
</tr><tr>
<td>serverConnectionsOpenMax</td>
<td>See Jetty <a
href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ConnectorStatistics.html">ConnectorStatistics
</a></td>
</tr><tr>
<td>serverConnectionDurationMean, -Max, -StdDev</td>
<td>See Jetty <a
href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ConnectorStatistics.html">ConnectorStatistics
</a></td>
</tr><tr>
<td>serverNumRequests, jdisc.http.requests</td>
<td>Number of requests received by the connector</td>
</tr><tr>
<td>serverNumSuccessfulResponses</td>
<td>Number of successful responses sent by the connector</td>
</tr><tr>
<td>serverNumFailedResponses</td>
<td>Number of error responses sent by the connector</td>
</tr><tr>
<td>serverNumSuccessfulResponseWrites</td>
<td>Number of HTTP response chunks that have been successfully written to the network.</td>
</tr><tr>
<td>serverNumFailedResponseWrites</td>
<td>Number of HTTP response chunks that have not been successfully written to the network,
due to some kind of I/O error.</td>
</tr><tr>
<td>serverBytesReceived</td>
<td>Number of bytes the connector has received</td>
</tr><tr>
<td>serverBytesSent</td>
<td>Number of bytes the connector has sent</td>
</tr><tr>
<td>serverTimeToFirstByte</td>
<td>Time to first byte of response body is sent</td>
</tr><tr>
<td>serverTotalSuccessfulResponseLatency</td>
<td>Time to complete successful responses</td>
</tr><tr>
<td>serverTotalFailedResponseLatency</td>
<td>Time to complete failed responses</td>
</tr>
</tbody>
</table>