本文整理汇总了Golang中github.com/prometheus/client_golang/prometheus.MustRegister函数的典型用法代码示例。如果您正苦于以下问题:Golang MustRegister函数的具体用法?Golang MustRegister怎么用?Golang MustRegister使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustRegister函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Metrics
// Metrics registers the DNS metrics to Prometheus, and starts the internal metrics
// server if the environment variable PROMETHEUS_PORT is set.
func Metrics() error {
// We do this in a function instead of using var + init(), because we want to
// able to set Namespace and/or Subsystem.
if Port == "" {
return nil
}
_, err := strconv.Atoi(Port)
if err != nil {
fmt.Errorf("bad port for prometheus: %s", Port)
}
defineMetrics()
prometheus.MustRegister(requestCount)
prometheus.MustRegister(requestDuration)
prometheus.MustRegister(responseSize)
prometheus.MustRegister(errorCount)
prometheus.MustRegister(cacheMiss)
http.Handle(Path, prometheus.Handler())
go func() {
fmt.Errorf("%s", http.ListenAndServe(":"+Port, nil))
}()
return nil
}
示例2: init
func init() {
prometheus.MustRegister(cpuUsage)
prometheus.MustRegister(memUsage)
prometheus.MustRegister(deviceCount)
prometheus.MustRegister(serverCount)
prometheus.MustRegister(threadCount)
}
示例3: New
func New(configFile string) (e exporter, err error) {
e = exporter{
configFile: configFile,
Metrics: map[string]*prometheus.GaugeVec{},
scrapeDuration: prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "scrape_duration_seconds",
Help: "gmond_exporter: Duration of a scrape job.",
},
[]string{"endpoint", "result"},
),
metricsUpdated: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "metrics_updated_count",
Help: "gmond_exporter: Number of metrics updated.",
},
[]string{"endpoint"},
),
metricsExported: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "metrics_exported_count",
Help: "gmond_exporter: Number of metrics exported.",
}),
configChan: make(chan config),
listeningAddress: ":8080",
gangliaScrapeInterval: 60 * time.Second,
}
conf, err := e.readConfig()
if err != nil {
return e, fmt.Errorf("Couldn't read config: %s", err)
}
e.conf = conf
if conf.ListeningAddress != "" {
e.listeningAddress = conf.ListeningAddress
}
if conf.GangliaScrapeInterval != 0 {
e.gangliaScrapeInterval = time.Duration(conf.GangliaScrapeInterval) * time.Second
}
prometheus.MustRegister(e.scrapeDuration)
prometheus.MustRegister(e.metricsUpdated)
prometheus.MustRegister(e.metricsExported)
debug("Registered internal metrics")
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP)
go func() {
for _ = range sig {
e.reloadConfig() // sends a new config to configChan
}
}()
go e.serveStatus()
return e, nil
}
示例4: Register
// Register registers all metrics to Prometheus with
// respect to the RequestLatency.
func Register() {
// Register the metrics.
registerMetrics.Do(func() {
prometheus.MustRegister(RequestLatency)
prometheus.MustRegister(RequestResult)
})
}
示例5: init
func init() {
prometheus.MustRegister(leaderGauge)
prometheus.MustRegister(engineTaskCount)
prometheus.MustRegister(engineTaskFailureCount)
prometheus.MustRegister(engineReconcileCount)
prometheus.MustRegister(engineReconcileFailureCount)
}
示例6: init
func init() {
prometheus.MustRegister(sentBytes)
prometheus.MustRegister(receivedBytes)
prometheus.MustRegister(sentFailures)
prometheus.MustRegister(recvFailures)
prometheus.MustRegister(rtts)
}
示例7: init
func init() {
prometheus.MustRegister(promErrorsTotal)
prometheus.MustRegister(promCacheHitsTotal)
prometheus.MustRegister(promCacheQueriesTotal)
prometheus.MustRegister(promQueryDurationMilliseconds)
prometheus.MustRegister(promConcurrentLockVAFV)
}
示例8: init
func init() {
prometheus.MustRegister(readCounter)
prometheus.MustRegister(writeCounter)
prometheus.MustRegister(expireCounter)
prometheus.MustRegister(watchRequests)
prometheus.MustRegister(watcherCount)
}
示例9: main
func main() {
flag.Parse()
if *consumeTime < 1 {
log.Fatal("consume time should be >0")
}
resp, err := http.Get(fmt.Sprintf("http://%s/varz", *natsaddr))
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != http.StatusOK {
log.Fatalf("expected statuscode 200 got %v", resp.StatusCode)
}
resp.Body.Close()
prometheus.MustRegister(bytesCounter)
prometheus.MustRegister(messageCounter)
prometheus.MustRegister(connections)
prometheus.MustRegister(slowConsumers)
go consume()
http.Handle("/metrics", prometheus.Handler())
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal(err)
}
}
示例10: init
func init() {
prometheus.MustRegister(targetIntervalLength)
prometheus.MustRegister(targetSkippedScrapes)
prometheus.MustRegister(targetReloadIntervalLength)
prometheus.MustRegister(targetSyncIntervalLength)
prometheus.MustRegister(targetScrapePoolSyncsCounter)
}
示例11: init
func init() {
prometheus.MustRegister(cmdCounter)
prometheus.MustRegister(cmdFailedCounter)
prometheus.MustRegister(cmdDuration)
prometheus.MustRegister(cmdFailedDuration)
prometheus.MustRegister(requestDuration)
}
示例12: init
func init() {
prometheus.MustRegister(failedLookfor)
prometheus.MustRegister(successfulLookfor)
prometheus.MustRegister(successfulGarbageCollect)
prometheus.MustRegister(successfulSanityFeed)
prometheus.MustRegister(lastSanityCheckStarted)
}
示例13: main
func main() {
flag.Parse()
handler := prometheus.Handler()
prometheus.MustRegister(watts)
prometheus.MustRegister(updatesPerPost)
prometheus.MustRegister(voltage)
http.Handle(*metricsPath, handler)
http.HandleFunc("/activate", activateHandler)
http.HandleFunc("/post", postHandler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>TED Exporter</title></head>
<body>
<h1>TED Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Infof("Starting ted_exporter v%s at %s", Version, *listenAddress)
err := http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}
示例14: registerProbes
func registerProbes() {
for _, probe := range config.Probes {
probeURL, _ := url.Parse(probe)
monitors := &probeMonitor{}
monitors.Expires = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "certcheck_expires",
Help: "Expiration date in unix timestamp (UTC)",
ConstLabels: prometheus.Labels{
"host": probeURL.Host,
},
})
monitors.IsValid = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "certcheck_valid",
Help: "Validity of the certificate (0/1)",
ConstLabels: prometheus.Labels{
"host": probeURL.Host,
},
})
prometheus.MustRegister(monitors.Expires)
prometheus.MustRegister(monitors.IsValid)
probeMonitors[probeURL.Host] = monitors
}
}
示例15: init
// Register metrics to Prometheus
func init() {
prometheus.MustRegister(channelsTotal)
prometheus.MustRegister(connectionsTotal)
prometheus.MustRegister(queuesTotal)
prometheus.MustRegister(exchangesTotal)
prometheus.MustRegister(consumersTotal)
}