Documentation
¶
Overview ¶
Example ¶
package main
import (
"context"
"log"
"net/http"
"time"
"github.com/orijtech/prometheus-go-metrics-exporter"
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
"github.com/golang/protobuf/ptypes/timestamp"
)
func main() {
pe, err := prometheus.New(prometheus.Options{})
if err != nil {
log.Fatalf("Failed to create new exporter: %v", err)
}
mux := http.NewServeMux()
// Expose the Prometheus Metrics exporter for scraping on route /metrics.
mux.Handle("/metrics", pe)
// Now run the server.
go func() {
http.ListenAndServe(":8888", mux)
}()
// And finally in your client application, use the
// OpenCensus-Go Metrics Prometheus exporter to record metrics.
for {
pe.ExportMetric(context.Background(), nil, nil, metric1)
// Introducing a fake pause/period.
<-time.After(350 * time.Millisecond)
}
}
var (
startTimestamp = ×tamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000090,
}
endTimestamp = ×tamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
}
)
var metric1 = &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "this/one/there(where)",
Description: "Extra ones",
Unit: "1",
LabelKeys: []*metricspb.LabelKey{
{Key: "os", Description: "Operating system"},
{Key: "arch", Description: "Architecture"},
},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: startTimestamp,
LabelValues: []*metricspb.LabelValue{
{Value: "windows"},
{Value: "x86"},
},
Points: []*metricspb.Point{
{
Timestamp: endTimestamp,
Value: &metricspb.Point_Int64Value{
Int64Value: 99,
},
},
},
},
{
StartTimestamp: startTimestamp,
LabelValues: []*metricspb.LabelValue{
{Value: "darwin"},
{Value: "386"},
},
Points: []*metricspb.Point{
{
Timestamp: endTimestamp,
Value: &metricspb.Point_DoubleValue{
DoubleValue: 49.5,
},
},
},
},
},
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
Exporter is the type that converts OpenCensus Proto-Metrics into Prometheus metrics.
type Options ¶
type Options struct {
Namespace string
OnError func(err error)
ConstLabels prometheus.Labels // ConstLabels will be set as labels on all views.
Registry *prometheus.Registry
SendTimestamps bool
}
Options customizes a created Prometheus Exporter.
Click to show internal directories.
Click to hide internal directories.