• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang prometheus.NewHistogramVec函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/prometheus/client_golang/prometheus.NewHistogramVec函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHistogramVec函数的具体用法?Golang NewHistogramVec怎么用?Golang NewHistogramVec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewHistogramVec函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewLabeledTimer

func (n *Namespace) NewLabeledTimer(name, help string, labels ...string) LabeledTimer {
	t := &labeledTimer{
		m: prometheus.NewHistogramVec(n.newTimerOpts(name, help), labels),
	}
	n.addMetric(t)
	return t
}
开发者ID:Mic92,项目名称:docker,代码行数:7,代码来源:namespace.go


示例2: NewMiddleware

// NewMiddleware returns a new prometheus Middleware handler.
func NewMiddleware(name string, buckets ...float64) *Middleware {
	var m Middleware
	m.reqs = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name:        reqsName,
			Help:        "How many HTTP requests processed, partitioned by status code, method and HTTP path.",
			ConstLabels: prometheus.Labels{"service": name},
		},
		[]string{"code", "method", "path"},
	)
	prometheus.MustRegister(m.reqs)

	if len(buckets) == 0 {
		buckets = dflBuckets
	}
	m.latency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:        latencyName,
		Help:        "How long it took to process the request, partitioned by status code, method and HTTP path.",
		ConstLabels: prometheus.Labels{"service": name},
		Buckets:     buckets,
	},
		[]string{"code", "method", "path"},
	)
	prometheus.MustRegister(m.latency)
	return &m
}
开发者ID:zbindenren,项目名称:negroni-prometheus,代码行数:27,代码来源:middleware.go


示例3: NewHistogram

// NewHistogram returns a new Histogram backed by a Prometheus Histogram. The
// histogram is automatically registered via prometheus.Register.
//
// For more information on Prometheus histograms and summaries, refer to
// http://prometheus.io/docs/practices/histograms.
func NewHistogram(opts prometheus.HistogramOpts, fieldKeys []string) metrics.Histogram {
	m := prometheus.NewHistogramVec(opts, fieldKeys)
	prometheus.MustRegister(m)
	return prometheusHistogram{
		HistogramVec: m,
		Pairs:        pairsFrom(fieldKeys),
	}
}
开发者ID:cnicolov,项目名称:kit,代码行数:13,代码来源:prometheus.go


示例4: defineMetrics

func defineMetrics(namespace, subsystem string) {
	requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: namespace,
		Subsystem: subsystem,
		Name:      "dns_request_count_total",
		Help:      "Counter of DNS requests made.",
	}, []string{"system"})

	requestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: namespace,
		Subsystem: subsystem,
		Name:      "dns_request_duration_seconds",
		Help:      "Histogram of the time (in seconds) each request took to resolve.",
		Buckets:   append([]float64{0.001, 0.003}, prometheus.DefBuckets...),
	}, []string{"system"})

	responseSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: namespace,
		Subsystem: subsystem,
		Name:      "dns_response_size_bytes",
		Help:      "Size of the returns response in bytes.",
		Buckets: []float64{0, 512, 1024, 1500, 2048, 4096,
			8192, 12288, 16384, 20480, 24576, 28672, 32768, 36864,
			40960, 45056, 49152, 53248, 57344, 61440, 65536,
		},
	}, []string{"system"})

	errorCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: namespace,
		Subsystem: subsystem,
		Name:      "dns_error_count_total",
		Help:      "Counter of DNS requests resulting in an error.",
	}, []string{"system", "cause"})

	cacheMiss = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: namespace,
		Subsystem: subsystem,
		Name:      "dns_cachemiss_count_total",
		Help:      "Counter of DNS requests that result in a cache miss.",
	}, []string{"cache"})
}
开发者ID:Xmagicer,项目名称:origin,代码行数:41,代码来源:metrics.go


示例5: TestWriteHistogram

func TestWriteHistogram(t *testing.T) {
	histVec := prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:        "name",
			Help:        "docstring",
			ConstLabels: prometheus.Labels{"constname": "constvalue"},
			Buckets:     []float64{0.01, 0.02, 0.05, 0.1},
		},
		[]string{"labelname"},
	)

	histVec.WithLabelValues("val1").Observe(float64(10))
	histVec.WithLabelValues("val1").Observe(float64(20))
	histVec.WithLabelValues("val1").Observe(float64(30))
	histVec.WithLabelValues("val2").Observe(float64(20))
	histVec.WithLabelValues("val2").Observe(float64(30))
	histVec.WithLabelValues("val2").Observe(float64(40))

	reg := prometheus.NewRegistry()
	reg.MustRegister(histVec)

	mfs, err := reg.Gather()
	if err != nil {
		t.Fatalf("error: %v", err)
	}

	now := model.Time(1477043083)
	var buf bytes.Buffer
	err = writeMetrics(&buf, mfs, "prefix", now)
	if err != nil {
		t.Fatalf("error: %v", err)
	}

	want := `prefix.name_bucket.constname.constvalue.labelname.val1.le.0_01 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val1.le.0_02 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val1.le.0_05 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val1.le.0_1 0 1477043
prefix.name_sum.constname.constvalue.labelname.val1 60 1477043
prefix.name_count.constname.constvalue.labelname.val1 3 1477043
prefix.name_bucket.constname.constvalue.labelname.val1.le._Inf 3 1477043
prefix.name_bucket.constname.constvalue.labelname.val2.le.0_01 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val2.le.0_02 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val2.le.0_05 0 1477043
prefix.name_bucket.constname.constvalue.labelname.val2.le.0_1 0 1477043
prefix.name_sum.constname.constvalue.labelname.val2 90 1477043
prefix.name_count.constname.constvalue.labelname.val2 3 1477043
prefix.name_bucket.constname.constvalue.labelname.val2.le._Inf 3 1477043
`
	if got := buf.String(); want != got {
		t.Fatalf("wanted \n%s\n, got \n%s\n", want, got)
	}
}
开发者ID:prometheus,项目名称:client_golang,代码行数:52,代码来源:bridge_test.go


示例6: EnableHandlingTimeHistogram

// EnableHandlingTimeHistogram turns on recording of handling time of RPCs for server-side interceptors.
// Histogram metrics can be very expensive for Prometheus to retain and query.
func EnableHandlingTimeHistogram(opts ...HistogramOption) {
	for _, o := range opts {
		o(&serverHandledHistogramOpts)
	}
	if !serverHandledHistogramEnabled {
		serverHandledHistogram = prom.NewHistogramVec(
			serverHandledHistogramOpts,
			[]string{"grpc_type", "grpc_service", "grpc_method"},
		)
		prom.Register(serverHandledHistogram)
	}
	serverHandledHistogramEnabled = true
}
开发者ID:pulcy,项目名称:vault-monkey,代码行数:15,代码来源:server_reporter.go


示例7: Histogram

// Histogram implements xstats.Sender interface
//
// Mark the tags as "key:value".
func (s sender) Histogram(stat string, value float64, tags ...string) {
	s.RLock()
	m, ok := s.histograms[stat]
	s.RUnlock()
	keys, values := splitTags(tags)
	if !ok {
		s.Lock()
		if m, ok = s.histograms[stat]; !ok {
			m = prometheus.NewHistogramVec(
				prometheus.HistogramOpts{Name: stat, Help: stat},
				keys)
			prometheus.MustRegister(m)
			s.histograms[stat] = m
		}
		s.Unlock()
	}
	m.WithLabelValues(values...).Observe(value)
}
开发者ID:patrickToca,项目名称:xstats,代码行数:21,代码来源:prometheus.go


示例8: newMeasurer

func newMeasurer() grpcinstrument.Measurer {
	return &measurer{
		registry: &registry{
			total: prometheus.NewCounterVec(prometheus.CounterOpts{
				Name: "grpc_calls_total",
				Help: "Number of gRPC calls received by the server being instrumented.",
			}, []string{"service", "method"}),
			errors: prometheus.NewCounterVec(prometheus.CounterOpts{
				Name: "grpc_calls_errors",
				Help: "Number of gRPC calls that returned an error.",
			}, []string{"service", "method"}),
			duration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
				Name: "grpc_calls_durations",
				Help: "Duration of gRPC calls.",
			}, []string{"service", "method"}),
		},
	}
}
开发者ID:kazegusuri,项目名称:grpcinstrument,代码行数:18,代码来源:measurer.go


示例9: main

func main() {
	var (
		listen  = flag.String("listen", ":7800", "Server listen address.")
		name    = flag.String("test.name", "unknown", "Name of the test to run.")
		rate    = flag.Uint64("test.rate", defaultRate, "Number of requests to send during test duration.")
		timeout = flag.Duration("test.timeout", defaultTimeout, "Time until a request is discarded")

		ts = targets{}
	)
	flag.Var(&ts, "test.target", `Target to hit by the test with the following format: -test.target="NAME:address/url"`)
	flag.Parse()

	if *listen == "" || len(ts) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	latencies := prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace:   "eagle",
			Name:        "request_duration_seconds",
			Help:        "The total duration of HTTP requests (seconds).",
			ConstLabels: prometheus.Labels{"test": *name},
			Buckets:     []float64{.001, .002, .003, .004, .005, .0075, .01, .015},
		},
		[]string{"target", "endpoint", "code"},
	)
	prometheus.MustRegister(latencies)

	resultc := make(chan result)
	go func() {
		for r := range resultc {
			latencies.
				WithLabelValues(r.target, r.endpoint, strconv.Itoa(int(r.Code))).
				Observe(r.Latency.Seconds())
		}
	}()
	newTest(*name, *rate, *timeout, ts).run(resultc)

	http.Handle("/metrics", prometheus.Handler())
	log.Printf("Starting server on %s", *listen)
	log.Fatal(http.ListenAndServe(*listen, nil))
}
开发者ID:soundcloud,项目名称:eagle,代码行数:43,代码来源:eagle.go


示例10: Histogram

func (p *prometheus) Histogram(id string) metrics.Histogram {
	var fields []string
	for k, _ := range p.opts.Fields {
		fields = append(fields, k)
	}

	hv := pr.NewHistogramVec(pr.HistogramOpts{
		Namespace: format(p.opts.Namespace),
		Name:      format(id),
		Help:      "histogram",
	}, fields)

	p.buf <- hv

	return &histogram{
		id: id,
		hv: hv,
		f:  p.opts.Fields,
	}
}
开发者ID:micro,项目名称:go-plugins,代码行数:20,代码来源:prometheus.go


示例11: emitHistogram

func (s *Sink) emitHistogram(job string, event string, nanos int64, kvs map[string]string) {
	var counter *prometheus.HistogramVec
	if c, ok := s.Config.HistogramVecs[job]; ok {
		counter = c
	} else {
		labels := labelsFromMap(kvs)

		counter = prometheus.NewHistogramVec(prometheus.HistogramOpts{
			Namespace: s.Config.Job,
			Subsystem: "duration",
			Name:      job,
			Help:      "Automaticaly created event",
		}, labels)

		s.Config.HistogramVecs[job] = counter
		prometheus.Register(counter)
	}

	kvs["event"] = event

	if m, err := counter.GetMetricWith(kvs); err == nil {
		m.Observe(float64(nanos))
	}
}
开发者ID:grepory,项目名称:awsthingy,代码行数:24,代码来源:sink.go


示例12: init

		prometheus.CounterOpts{
			Namespace: "etcd",
			Subsystem: "grpc",
			Name:      "requests_total",
			Help:      "Counter of received requests.",
		}, []string{"grpc_service", "grpc_method"})

	failedCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "etcd",
			Subsystem: "grpc",
			Name:      "requests_failed_total",
			Help:      "Counter of failed requests.",
		}, []string{"grpc_service", "grpc_method", "grpc_code"})

	handlingDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace: "etcd",
			Subsystem: "grpc",
			Name:      "unary_requests_duration_seconds",
			Help:      "Bucketed histogram of processing time (s) of handled unary (non-stream) requests.",
			Buckets:   prometheus.ExponentialBuckets(0.0005, 2, 13),
		}, []string{"grpc_service", "grpc_method"})
)

func init() {
	prometheus.MustRegister(receivedCounter)
	prometheus.MustRegister(failedCounter)
	prometheus.MustRegister(handlingDuration)
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:30,代码来源:metrics.go


示例13:

			Name:      "cmds_total",
			Help:      "Counter of cmds.",
		}, []string{"type"})

	cmdFailedCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "pd_client",
			Subsystem: "cmd",
			Name:      "cmds_failed_total",
			Help:      "Counter of failed cmds.",
		}, []string{"type"})

	cmdDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace: "pd_client",
			Subsystem: "cmd",
			Name:      "handle_cmds_duration_seconds",
			Help:      "Bucketed histogram of processing time (s) of handled success cmds.",
			Buckets:   prometheus.ExponentialBuckets(0.0005, 2, 13),
		}, []string{"type"})

	cmdFailedDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace: "pd_client",
			Subsystem: "cmd",
			Name:      "handle_failed_cmds_duration_seconds",
			Help:      "Bucketed histogram of processing time (s) of failed handled cmds.",
			Buckets:   prometheus.ExponentialBuckets(0.0005, 2, 13),
		}, []string{"type"})

	requestDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
开发者ID:jmptrader,项目名称:tidb,代码行数:32,代码来源:metrics.go


示例14: init

		Namespace: "doorman",
		Subsystem: "client",
		Name:      "requests",
		Help:      "Requests sent to a Doorman service.",
	}, requestLabels)

	requestErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "doorman",
		Subsystem: "client",
		Name:      "request_errors",
		Help:      "Requests sent to a Doorman service that returned an error.",
	}, requestLabels)

	requestDurations = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "doorman",
		Subsystem: "client",
		Name:      "request_durations",
		Help:      "Duration of different requests in seconds.",
	}, requestLabels)
)

func init() {
	prometheus.MustRegister(requests)
	prometheus.MustRegister(requestErrors)
	prometheus.MustRegister(requestDurations)
}

// NOTE: We're wrapping connection package's functions and types here in the client,
// because we do not want our users to be aware of the internal connection package.

// Option configures the client's connection parameters.
type Option connection.Option
开发者ID:youtube,项目名称:doorman,代码行数:32,代码来源:client.go


示例15:

	"github.com/coreos/etcd/pkg/types"
	"github.com/coreos/etcd/raft/raftpb"
	"github.com/prometheus/client_golang/prometheus"
)

var (
	// TODO: create a separate histogram for recording
	// snapshot sending metric. snapshot can be large and
	// take a long time to send. So it needs a different
	// time range than other type of messages.
	msgSentDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace: "etcd_debugging",
			Subsystem: "rafthttp",
			Name:      "message_sent_latency_seconds",
			Help:      "message sent latency distributions.",
			Buckets:   prometheus.ExponentialBuckets(0.0005, 2, 13),
		},
		[]string{"sendingType", "remoteID", "msgType"},
	)

	msgSentFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "etcd_debugging",
		Subsystem: "rafthttp",
		Name:      "message_sent_failed_total",
		Help:      "The total number of failed messages sent.",
	},
		[]string{"sendingType", "remoteID", "msgType"},
	)
)
开发者ID:achanda,项目名称:etcd,代码行数:30,代码来源:metrics.go


示例16: init

package lucky

import (
	"github.com/prometheus/client_golang/prometheus"
)

var (
	RequestsHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "lucky_requests_ms",
		Help:    "Lucky requests",
		Buckets: prometheus.ExponentialBuckets(1, 5, 6),
	},
		[]string{"backend", "method"})
	BackendsGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Name: "lucky_backends",
		Help: "Lucky backends",
	},
		[]string{"backend"})

	FrontendsGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Name: "lucky_frontends",
		Help: "Lucky frontends",
	},
		[]string{"frontend", "type"})
)

func init() {
	prometheus.MustRegister(RequestsHistogram)
	prometheus.MustRegister(BackendsGauge)
	prometheus.MustRegister(FrontendsGauge)
}
开发者ID:prepor,项目名称:lucky,代码行数:31,代码来源:metrics.go


示例17: NewHistogramVec

func (mc *MetricCollection) NewHistogramVec(opts promm.HistogramOpts, labelNames []string) *promm.HistogramVec {
	c := promm.NewHistogramVec(opts, labelNames)
	mc.Add(c)
	return c
}
开发者ID:huin,项目名称:warren,代码行数:5,代码来源:metric.go


示例18:

var (
	storeLabels = []string{"error", "operation"}
	countLabels = []string{
		"service",
		"job",
		"env",
		"product",
		"zone",
		"operation",
	}

	dnsDurations = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace: namespace,
			Subsystem: "dns",
			Name:      "request_duration_seconds",
			Help:      "DNS request latencies in seconds.",
			Buckets:   []float64{0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1},
		},
		[]string{"protocol", "qtype", "rcode"},
	)
	storeCounts = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "consul",
			Name:      "responses",
			Help:      "Consul API responses.",
		},
		countLabels,
	)
	storeDurations = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
开发者ID:rugby110,项目名称:glimpse,代码行数:32,代码来源:instrumentation.go


示例19: init

		Help:      "The total number of bytes sent to peers.",
	},
		[]string{"To"},
	)

	receivedBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "etcd",
		Subsystem: "network",
		Name:      "peer_received_bytes_total",
		Help:      "The total number of bytes received from peers.",
	},
		[]string{"From"},
	)

	rtts = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "etcd",
		Subsystem: "network",
		Name:      "peer_round_trip_time_seconds",
		Help:      "Round-Trip-Time histogram between peers.",
		Buckets:   prometheus.ExponentialBuckets(0.0001, 2, 14),
	},
		[]string{"To"},
	)
)

func init() {
	prometheus.MustRegister(sentBytes)
	prometheus.MustRegister(receivedBytes)
	prometheus.MustRegister(rtts)
}
开发者ID:CliffYuan,项目名称:etcd,代码行数:30,代码来源:metrics.go


示例20: Register

var (
	// TODO(a-robinson): Add unit tests for the handling of these metrics once
	// the upstream library supports it.
	requestCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "apiserver_request_count",
			Help: "Counter of apiserver requests broken out for each verb, API resource, client, and HTTP response code.",
		},
		[]string{"verb", "resource", "client", "code"},
	)
	requestLatencies = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "apiserver_request_latencies",
			Help: "Response latency distribution in microseconds for each verb, resource and client.",
			// Use buckets ranging from 125 ms to 8 seconds.
			Buckets: prometheus.ExponentialBuckets(125000, 2.0, 7),
		},
		[]string{"verb", "resource"},
	)
	requestLatenciesSummary = prometheus.NewSummaryVec(
		prometheus.SummaryOpts{
			Name: "apiserver_request_latencies_summary",
			Help: "Response latency summary in microseconds for each verb and resource.",
		},
		[]string{"verb", "resource"},
	)
)

// Register all metrics.
func Register() {
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:30,代码来源:metrics.go



注:本文中的github.com/prometheus/client_golang/prometheus.NewHistogramVec函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang prometheus.NewSummary函数代码示例发布时间:2022-05-28
下一篇:
Golang prometheus.NewHistogram函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap