go.opencensus.io: go.opencensus.io/exporter/prometheus Index | Examples | Files | Directories

package prometheus

import "go.opencensus.io/exporter/prometheus"

Package prometheus contains a Prometheus exporter that supports exporting OpenCensus views as Prometheus metrics.


exporter, err := prometheus.NewExporter(prometheus.Options{})
if err != nil {

// Serve the scrape endpoint on port 9999.
http.Handle("/metrics", exporter)
log.Fatal(http.ListenAndServe(":9999", nil))



Package Files


type Exporter Uses

type Exporter struct {
    // contains filtered or unexported fields

Exporter exports stats to Prometheus, users need to register the exporter as an http.Handler to be able to export.

func NewExporter Uses

func NewExporter(o Options) (*Exporter, error)

NewExporter returns an exporter that exports stats to Prometheus.

func (*Exporter) ExportView Uses

func (e *Exporter) ExportView(vd *view.Data)

ExportView exports to the Prometheus if view data has one or more rows. Each OpenCensus AggregationData will be converted to corresponding Prometheus Metric: SumData will be converted to Untyped Metric, CountData will be a Counter Metric, DistributionData will be a Histogram Metric.

func (*Exporter) ServeHTTP Uses

func (e *Exporter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the Prometheus endpoint.

type Options Uses

type Options struct {
    Namespace   string
    Registry    *prometheus.Registry
    OnError     func(err error)
    ConstLabels prometheus.Labels // ConstLabels will be set as labels on all views.

Options contains options for configuring the exporter.


exampleCommand prometheus is an example program that collects data for video size.

Package prometheus imports 10 packages (graph) and is imported by 37 packages. Updated 2019-04-15. Refresh now. Tools for package owners.