You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

597 lines
19 KiB

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">
<title>expfmt - The Go Programming Language</title>
<link type="text/css" rel="stylesheet" href="../../../../../lib/godoc/style.css">
<link rel="stylesheet" href="../../../../../lib/godoc/jquery.treeview.css">
<script type="text/javascript">window.initFuncs = [];</script>
</head>
<body>
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->
<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="http://localhost:6060/search">
<div id="menu">
<a href="http://localhost:6060/doc/">Documents</a>
<a href="http://localhost:6060/pkg/">Packages</a>
<a href="http://localhost:6060/project/">The Project</a>
<a href="http://localhost:6060/help/">Help</a>
<a href="http://localhost:6060/blog/">Blog</a>
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
</div>
</form>
</div></div>
<div id="page" class="wide">
<div class="container">
<h1>Package expfmt</h1>
<div id="nav"></div>
<!--
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
Note: Static (i.e., not template-generated) href and id
attributes start with "pkg-" to make it impossible for
them to conflict with generated attributes (some of which
correspond to Go identifiers).
-->
<script type='text/javascript'>
document.ANALYSIS_DATA = null;
document.CALLGRAPH = null;
</script>
<div id="short-nav">
<dl>
<dd><code>import "github.com/prometheus/common/expfmt"</code></dd>
</dl>
<dl>
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
</dl>
</div>
<!-- The package's Name is printed as title by the top-level template -->
<div id="pkg-overview" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
<p>
A package for reading and writing Prometheus metrics.
</p>
</div>
</div>
<div id="pkg-index" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
<div id="manual-nav">
<dl>
<dd><a href="index.html#pkg-constants">Constants</a></dd>
<dd><a href="index.html#ExtractSamples">func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) model.Vector</a></dd>
<dd><a href="index.html#MetricFamilyToText">func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (int, error)</a></dd>
<dd><a href="index.html#DecodeOptions">type DecodeOptions</a></dd>
<dd><a href="index.html#Decoder">type Decoder</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NewDecoder">func NewDecoder(r io.Reader, format Format) Decoder</a></dd>
<dd><a href="index.html#Encoder">type Encoder</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NewEncoder">func NewEncoder(w io.Writer, format Format) Encoder</a></dd>
<dd><a href="index.html#Format">type Format</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Negotiate">func Negotiate(h http.Header) Format</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#ResponseFormat">func ResponseFormat(h http.Header) Format</a></dd>
<dd><a href="index.html#ParseError">type ParseError</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#ParseError.Error">func (e ParseError) Error() string</a></dd>
<dd><a href="index.html#SampleDecoder">type SampleDecoder</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#SampleDecoder.Decode">func (sd *SampleDecoder) Decode(s *model.Vector) error</a></dd>
<dd><a href="index.html#TextParser">type TextParser</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#TextParser.TextToMetricFamilies">func (p *TextParser) TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error)</a></dd>
<dd><a href="index.html#pkg-note-BUG">Bugs</a></dd>
</dl>
</div><!-- #manual-nav -->
<h4>Package files</h4>
<p>
<span style="font-size:90%">
<a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go">decode.go</a>
<a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/encode.go">encode.go</a>
<a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/expfmt.go">expfmt.go</a>
<a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_create.go">text_create.go</a>
<a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_parse.go">text_parse.go</a>
</span>
</p>
</div><!-- .expanded -->
</div><!-- #pkg-index -->
<div id="pkg-callgraph" class="toggle" style="display: none">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
</div> <!-- .expanded -->
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
<p>
In the call graph viewer below, each node
is a function belonging to this package
and its children are the functions it
calls&mdash;perhaps dynamically.
</p>
<p>
The root nodes are the entry points of the
package: functions that may be called from
outside the package.
There may be non-exported or anonymous
functions among them if they are called
dynamically from another package.
</p>
<p>
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring <code>func</code>
token.
</p>
<p>
Functions may be omitted if they were
determined to be unreachable in the
particular programs or tests that were
analyzed.
</p>
<!-- Zero means show all package entry points. -->
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
</div>
</div> <!-- #pkg-callgraph -->
<h2 id="pkg-constants">Constants</h2>
<pre>const (
<span id="TextVersion">TextVersion</span> = &#34;0.0.4&#34;
<span id="ProtoType">ProtoType</span> = `application/vnd.google.protobuf`
<span id="ProtoProtocol">ProtoProtocol</span> = `io.prometheus.client.MetricFamily`
<span id="ProtoFmt">ProtoFmt</span> = <a href="index.html#ProtoType">ProtoType</a> + &#34;; proto=&#34; + <a href="index.html#ProtoProtocol">ProtoProtocol</a> + &#34;;&#34;
<span class="comment">// The Content-Type values for the different wire protocols.</span>
<span id="FmtUnknown">FmtUnknown</span> <a href="index.html#Format">Format</a> = `&lt;unknown&gt;`
<span id="FmtText">FmtText</span> <a href="index.html#Format">Format</a> = `text/plain; version=` + <a href="index.html#TextVersion">TextVersion</a>
<span id="FmtProtoDelim">FmtProtoDelim</span> <a href="index.html#Format">Format</a> = <a href="index.html#ProtoFmt">ProtoFmt</a> + ` encoding=delimited`
<span id="FmtProtoText">FmtProtoText</span> <a href="index.html#Format">Format</a> = <a href="index.html#ProtoFmt">ProtoFmt</a> + ` encoding=text`
<span id="FmtProtoCompact">FmtProtoCompact</span> <a href="index.html#Format">Format</a> = <a href="index.html#ProtoFmt">ProtoFmt</a> + ` encoding=compact-text`
)</pre>
<h2 id="ExtractSamples">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=3941:4018#L151">ExtractSamples</a></h2>
<pre>func ExtractSamples(o *<a href="index.html#DecodeOptions">DecodeOptions</a>, fams ...*<a href="../../client_model/go/index.html">dto</a>.<a href="../../client_model/go/index.html#MetricFamily">MetricFamily</a>) <a href="../model/index.html">model</a>.<a href="../model/index.html#Vector">Vector</a></pre>
<p>
Extract samples builds a slice of samples from the provided metric families.
</p>
<h2 id="MetricFamilyToText">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_create.go?s=1318:1391#L25">MetricFamilyToText</a></h2>
<pre>func MetricFamilyToText(out <a href="../../../../io/index.html">io</a>.<a href="../../../../io/index.html#Writer">Writer</a>, in *<a href="../../client_model/go/index.html">dto</a>.<a href="../../client_model/go/index.html#MetricFamily">MetricFamily</a>) (<a href="../../../../builtin/index.html#int">int</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
<p>
MetricFamilyToText converts a MetricFamily proto message into text format and
writes the resulting lines to &#39;out&#39;. It returns the number of bytes written
and any error encountered. The output will have the same order as the input,
no further sorting is performed. Furthermore, this function assumes the input
is already sanitized and does not perform any sanity checks. If the input
contains duplicate metrics or invalid metric or label names, the conversion
will result in invalid text format output.
</p>
<p>
This method fulfills the type &#39;prometheus.encoder&#39;.
</p>
<h2 id="DecodeOptions">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=929:1069#L24">DecodeOptions</a></h2>
<pre>type DecodeOptions struct {
<span class="comment">// Timestamp is added to each value from the stream that has no explicit timestamp set.</span>
Timestamp <a href="../model/index.html">model</a>.<a href="../model/index.html#Time">Time</a>
}</pre>
<h2 id="Decoder">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=868:927#L20">Decoder</a></h2>
<pre>type Decoder interface {
Decode(*<a href="../../client_model/go/index.html">dto</a>.<a href="../../client_model/go/index.html#MetricFamily">MetricFamily</a>) <a href="../../../../builtin/index.html#error">error</a>
}</pre>
<p>
Decoder types decode an input stream into metric families.
</p>
<h3 id="NewDecoder">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=1932:1983#L63">NewDecoder</a></h3>
<pre>func NewDecoder(r <a href="../../../../io/index.html">io</a>.<a href="../../../../io/index.html#Reader">Reader</a>, format <a href="index.html#Format">Format</a>) <a href="index.html#Decoder">Decoder</a></pre>
<p>
NewDecoder returns a new decoder based on the given input format.
If the input format does not imply otherwise, a text format decoder is returned.
</p>
<h2 id="Encoder">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/encode.go?s=930:989#L19">Encoder</a></h2>
<pre>type Encoder interface {
Encode(*<a href="../../client_model/go/index.html">dto</a>.<a href="../../client_model/go/index.html#MetricFamily">MetricFamily</a>) <a href="../../../../builtin/index.html#error">error</a>
}</pre>
<p>
Encoder types encode metric families into an underlying wire protocol.
</p>
<h3 id="NewEncoder">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/encode.go?s=1896:1947#L54">NewEncoder</a></h3>
<pre>func NewEncoder(w <a href="../../../../io/index.html">io</a>.<a href="../../../../io/index.html#Writer">Writer</a>, format <a href="index.html#Format">Format</a>) <a href="index.html#Encoder">Encoder</a></pre>
<p>
NewEncoder returns a new encoder based on content type negotiation.
</p>
<h2 id="Format">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/expfmt.go?s=666:684#L7">Format</a></h2>
<pre>type Format <a href="../../../../builtin/index.html#string">string</a></pre>
<h3 id="Negotiate">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/encode.go?s=1242:1278#L31">Negotiate</a></h3>
<pre>func Negotiate(h <a href="../../../../net/http/index.html">http</a>.<a href="../../../../net/http/index.html#Header">Header</a>) <a href="index.html#Format">Format</a></pre>
<p>
Negotiate returns the Content-Type based on the given Accept header.
If no appropriate accepted type is found, FmtText is returned.
</p>
<h3 id="ResponseFormat">func <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=1211:1252#L31">ResponseFormat</a></h3>
<pre>func ResponseFormat(h <a href="../../../../net/http/index.html">http</a>.<a href="../../../../net/http/index.html#Header">Header</a>) <a href="index.html#Format">Format</a></pre>
<p>
ResponseFormat extracts the correct format from a HTTP response header.
If no matching format can be found FormatUnknown is returned.
</p>
<h2 id="ParseError">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_parse.go?s=1172:1221#L29">ParseError</a></h2>
<pre>type ParseError struct {
Line <a href="../../../../builtin/index.html#int">int</a>
Msg <a href="../../../../builtin/index.html#string">string</a>
}</pre>
<p>
ParseError signals errors while parsing the simple and flat text-based
exchange format.
</p>
<h3 id="ParseError.Error">func (ParseError) <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_parse.go?s=1264:1298#L35">Error</a></h3>
<pre>func (e <a href="index.html#ParseError">ParseError</a>) Error() <a href="../../../../builtin/index.html#string">string</a></pre>
<p>
Error implements the error interface.
</p>
<h2 id="SampleDecoder">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=3603:3688#L135">SampleDecoder</a></h2>
<pre>type SampleDecoder struct {
Dec <a href="index.html#Decoder">Decoder</a>
Opts *<a href="index.html#DecodeOptions">DecodeOptions</a>
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<h3 id="SampleDecoder.Decode">func (*SampleDecoder) <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=3690:3744#L142">Decode</a></h3>
<pre>func (sd *<a href="index.html#SampleDecoder">SampleDecoder</a>) Decode(s *<a href="../model/index.html">model</a>.<a href="../model/index.html#Vector">Vector</a>) <a href="../../../../builtin/index.html#error">error</a></pre>
<h2 id="TextParser">type <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_parse.go?s=1497:2808#L41">TextParser</a></h2>
<pre>type TextParser struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
TextParser is used to parse the simple and flat text-based exchange format. Its
zero value is ready to use.
</p>
<h3 id="TextParser.TextToMetricFamilies">func (*TextParser) <a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/text_parse.go?s=4246:4339#L90">TextToMetricFamilies</a></h3>
<pre>func (p *<a href="index.html#TextParser">TextParser</a>) TextToMetricFamilies(in <a href="../../../../io/index.html">io</a>.<a href="../../../../io/index.html#Reader">Reader</a>) (map[<a href="../../../../builtin/index.html#string">string</a>]*<a href="../../client_model/go/index.html">dto</a>.<a href="../../client_model/go/index.html#MetricFamily">MetricFamily</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
<p>
TextToMetricFamilies reads &#39;in&#39; as the simple and flat text-based exchange
format and creates MetricFamily proto messages. It returns the MetricFamily
proto messages in a map where the metric names are the keys, along with any
error encountered.
</p>
<p>
If the input contains duplicate metrics (i.e. lines with the same metric name
and exactly the same label set), the resulting MetricFamily will contain
duplicate Metric proto messages. Similar is true for duplicate label
names. Checks for duplicates have to be performed separately, if required.
Also note that neither the metrics within each MetricFamily are sorted nor
the label pairs within each Metric. Sorting is not required for the most
frequent use of this method, which is sample ingestion in the Prometheus
server. However, for presentation purposes, you might want to sort the
metrics, and in some cases, you must sort the labels, e.g. for consumption by
the metric family injection hook of the Prometheus registry.
</p>
<p>
Summaries and histograms are rather special beasts. You would probably not
use them in the simple text format anyway. This method can deal with
summaries and histograms if they are presented in exactly the way the
text.Create function creates them.
</p>
<p>
This method must not be called concurrently. If you want to parse different
input concurrently, instantiate a separate Parser for each goroutine.
</p>
<h2 id="pkg-note-BUG">Bugs</h2>
<ul style="list-style: none; padding: 0;">
<li><a href="http://localhost:6060/src/github.com/prometheus/common/expfmt/decode.go?s=7282:7329#L286">&#x261e;</a> Update other names to &#34;quantile&#34;.
</li>
</ul>
<div id="footer">
Build version go1.6.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>
</div><!-- .container -->
</div><!-- #page -->
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
<script type="text/javascript" src="../../../../../lib/godoc/jquery.js"></script>
<script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.js"></script>
<script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.edit.js"></script>
<script type="text/javascript" src="../../../../../lib/godoc/godocs.js"></script>
</body>
</html>