当前位置: 首页>>代码示例>>Golang>>正文


Golang prometheus.Register函数代码示例

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


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

示例1: main

func main() {
	var (
		fsRoot      = flag.String("fs.root", "/tmp", "FileSystem root directory")
		httpAddress = flag.String("http.addr", ":5555", "HTTP listen address")
		providerDir = flag.String("provider.dir", "/tmp", "Provider directory with bucket policies")
	)
	flag.Parse()

	prometheus.Register("ent_requests_total", "Total number of requests made", prometheus.NilLabels, requestTotal)
	prometheus.Register("ent_requests_duration_nanoseconds_total", "Total amount of time ent has spent to answer requests in nanoseconds", prometheus.NilLabels, requestDuration)
	prometheus.Register("ent_requests_duration_nanoseconds", "Amounts of time ent has spent answering requests in nanoseconds", prometheus.NilLabels, requestDurations)
	prometheus.Register("ent_request_bytes_total", "Total volume of request payloads emitted in bytes", prometheus.NilLabels, requestBytes)
	prometheus.Register("ent_response_bytes_total", "Total volume of response payloads emitted in bytes", prometheus.NilLabels, responseBytes)

	p, err := NewDiskProvider(*providerDir)
	if err != nil {
		log.Fatal(err)
	}

	fs := NewDiskFS(*fsRoot)
	r := pat.New()
	r.Get(fileRoute, handleGet(p, fs))
	r.Post(fileRoute, handleCreate(p, fs))
	r.Handle("/metrics", prometheus.DefaultRegistry.Handler())
	r.Get("/", handleBucketList(p))

	log.Fatal(http.ListenAndServe(*httpAddress, http.Handler(r)))
}
开发者ID:queer1,项目名称:ent,代码行数:28,代码来源:ent.go

示例2: promPushRunningPending

// Reusable function for pushing metrics to prometheus.  Handles initialization and so on.
func promPushRunningPending(running, pending int) error {
	if TestContext.PrometheusPushGateway == "" {
		return nil
	} else {
		// Register metrics if necessary
		if !prom_registered && TestContext.PrometheusPushGateway != "" {
			prometheus.Register(runningMetric)
			prometheus.Register(pendingMetric)
			prom_registered = true
		}
		// Update metric values
		runningMetric.Set(float64(running))
		pendingMetric.Set(float64(pending))

		// Push them to the push gateway.  This will be scraped by prometheus
		// provided you launch it with the pushgateway as an endpoint.
		if err := prometheus.Push(
			"e2e",
			"none",
			TestContext.PrometheusPushGateway, //i.e. "127.0.0.1:9091"
		); err != nil {
			fmt.Println("failed at pushing to pushgateway ", err)
			return err
		}
	}
	return nil
}
开发者ID:40a,项目名称:bootkube,代码行数:28,代码来源:prompush.go

示例3: ExampleCounter

func ExampleCounter() {
	pushCounter := prometheus.NewCounter(prometheus.CounterOpts{
		Name: "repository_pushes", // Note: No help string...
	})
	err := prometheus.Register(pushCounter) // ... so this will return an error.
	if err != nil {
		fmt.Println("Push counter couldn't be registered, no counting will happen:", err)
		return
	}

	// Try it once more, this time with a help string.
	pushCounter = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "repository_pushes",
		Help: "Number of pushes to external repository.",
	})
	err = prometheus.Register(pushCounter)
	if err != nil {
		fmt.Println("Push counter couldn't be registered AGAIN, no counting will happen:", err)
		return
	}

	pushComplete := make(chan struct{})
	// TODO: Start a goroutine that performs repository pushes and reports
	// each completion via the channel.
	for _ = range pushComplete {
		pushCounter.Inc()
	}
	// Output:
	// Push counter couldn't be registered, no counting will happen: descriptor Desc{fqName: "repository_pushes", help: "", constLabels: {}, variableLabels: []} is invalid: empty help string
}
开发者ID:eghobo,项目名称:kubedash,代码行数:30,代码来源:examples_test.go

示例4: init

func init() {
	prometheus.Register(
		"esmc_requests",
		"A counter of the total number of requests to an ES cluster",
		prometheus.NilLabels,
		requestCount,
	)
	prometheus.Register(
		"esmc_request_total_duration_nanoseconds",
		"The total amount of time spent executing requests (nanoseconds)",
		prometheus.NilLabels,
		requestDuration,
	)
	prometheus.Register(
		"esmc_request_durations_nanoseconds",
		"The amounts of time spent executing requests (nanoseconds)",
		prometheus.NilLabels,
		requestDurations,
	)
	prometheus.Register(
		"esmc_reported_request_total_duration_nanoseconds",
		"The total amount of time spent executing requests as reported by elasticsearch (nanoseconds)",
		prometheus.NilLabels,
		reportedRequestDuration,
	)
	prometheus.Register(
		"esmc_reported_request_durations_nanoseconds",
		"The amounts of time spent executing requests as reported by elasticsearch (nanoseconds)",
		prometheus.NilLabels,
		reportedRequestDurations,
	)
}
开发者ID:bernerdschaefer,项目名称:esmc,代码行数:32,代码来源:metrics.go

示例5: Init

func (m *measurer) Init() error {
	if err := prometheus.Register(m.registry.total); err != nil {
		return err
	}
	if err := prometheus.Register(m.registry.errors); err != nil {
		return err
	}
	if err := prometheus.Register(m.registry.duration); err != nil {
		return err
	}
	return nil
}
开发者ID:kazegusuri,项目名称:grpcinstrument,代码行数:12,代码来源:measurer.go

示例6: registerMetrics

func registerMetrics() (err error) {
	items, err := muninList()
	if err != nil {
		return
	}

	for _, name := range items {
		graphs = append(graphs, name)
		configs, graphConfig, err := muninConfig(name)
		if err != nil {
			return err
		}

		for metric, config := range configs {
			metricName := strings.Replace(name+"_"+metric, "-", "_", -1)
			desc := graphConfig["graph_title"] + ": " + config["label"]
			if config["info"] != "" {
				desc = desc + ", " + config["info"]
			}
			muninType := strings.ToLower(config["type"])
			// muninType can be empty and defaults to gauge
			if muninType == "counter" || muninType == "derive" {
				gv := prometheus.NewCounterVec(
					prometheus.CounterOpts{
						Name:        metricName,
						Help:        desc,
						ConstLabels: prometheus.Labels{"type": muninType},
					},
					[]string{"hostname", "graphname", "muninlabel"},
				)
				//log.Printf("Registered counter %s: %s", metricName, desc)
				counterPerMetric[metricName] = gv
				prometheus.Register(gv)

			} else {
				gv := prometheus.NewGaugeVec(
					prometheus.GaugeOpts{
						Name:        metricName,
						Help:        desc,
						ConstLabels: prometheus.Labels{"type": "gauge"},
					},
					[]string{"hostname", "graphname", "muninlabel"},
				)
				//log.Printf("Registered gauge %s: %s", metricName, desc)
				gaugePerMetric[metricName] = gv
				prometheus.Register(gv)
			}
		}
	}
	return nil
}
开发者ID:jacksoncage,项目名称:munin_exporter,代码行数:51,代码来源:munin_exporter.go

示例7: setMetric

func (e *exporter) setMetric(name string, labels map[string]string, metric Metric) {
	debug("%s{%s} = %f", name, labels, metric.Value)
	e.Lock()
	defer e.Unlock()
	if _, ok := e.Metrics[name]; !ok {
		var desc string
		var title string
		for _, element := range metric.ExtraData.ExtraElements {
			switch element.Name {
			case "DESC":
				desc = element.Val
			case "TITLE":
				title = element.Val
			}
			if title != "" && desc != "" {
				break
			}
		}
		debug("New metric: %s (%s)", name, desc)
		gv := prometheus.NewGaugeVec(
			prometheus.GaugeOpts{
				Name: name,
				Help: desc,
			},
			prometheusLabels,
		)
		e.Metrics[name] = gv
		prometheus.Register(gv) // One GaugeVec per metric!
	}
	e.Metrics[name].With(labels).Set(metric.Value)
}
开发者ID:prometheus-junkyard,项目名称:gmond_exporter,代码行数:31,代码来源:exporter.go

示例8: metricsInit

func metricsInit(servicename string) *syndicateMetrics {
	m := syndicateMetrics{}
	m.managedNodes = prometheus.NewGauge(prometheus.GaugeOpts{
		Name:        "ManagedNodes",
		Help:        "Current number of nodes managed.",
		ConstLabels: prometheus.Labels{"servicename": servicename},
	})
	m.subscriberNodes = prometheus.NewGauge(prometheus.GaugeOpts{
		Name:        "SubscriberNodes",
		Help:        "Current number of unmanaged nodes subscribed for ring changes.",
		ConstLabels: prometheus.Labels{"servicename": servicename},
	})
	prometheus.Register(m.managedNodes)
	prometheus.Register(m.subscriberNodes)
	return &m
}
开发者ID:wreese,项目名称:cfs-binary-release,代码行数:16,代码来源:syndicate.go

示例9: registerMetrics

func registerMetrics() (err error) {
	items, err := muninList()
	if err != nil {
		return
	}

	for _, name := range items {
		graphs = append(graphs, name)
		configs, graphConfig, err := muninConfig(name)
		if err != nil {
			return err
		}

		for metric, config := range configs {
			metricName := name + "-" + metric
			desc := graphConfig["graph_title"] + ": " + config["label"]
			if config["info"] != "" {
				desc = desc + ", " + config["info"]
			}
			gv := prometheus.NewGaugeVec(
				prometheus.GaugeOpts{
					Name: metricName,
					Help: desc,
				},
				[]string{"hostname"},
			)
			log.Printf("Registered %s: %s", metricName, desc)
			gaugePerMetric[metricName] = gv
			prometheus.Register(gv)
		}
	}
	return nil
}
开发者ID:prometheus-junkyard,项目名称:munin_exporter,代码行数:33,代码来源:munin_exporter.go

示例10: New

// New returns a new unconfigured server. parentAddr is the address of
// a parent, pass the empty string to create a root server. This
// function should be called only once, as it registers metrics.
func New(ctx context.Context, id string, parentAddr string, leader election.Election, opts ...connection.Option) (*Server, error) {
	s, err := NewIntermediate(ctx, id, parentAddr, leader, opts...)
	if err != nil {
		return nil, err
	}

	return s, prometheus.Register(s)
}
开发者ID:youtube,项目名称:doorman,代码行数:11,代码来源:server.go

示例11: init

func init() {
	prometheus.Register("prometheus_metric_disk_operations_total", "Total number of metric-related disk operations.", prometheus.NilLabels, storageOperations)
	prometheus.Register("prometheus_metric_disk_latency_microseconds", "Latency for metric disk operations in microseconds.", prometheus.NilLabels, storageLatency)
	prometheus.Register("prometheus_storage_operation_time_total_microseconds", "The total time spent performing a given storage operation.", prometheus.NilLabels, storageOperationDurations)
	prometheus.Register("prometheus_storage_queue_sizes_total", "The various sizes and capacities of the storage queues.", prometheus.NilLabels, queueSizes)
	prometheus.Register("prometheus_curation_filter_operations_total", "The number of curation filter operations completed.", prometheus.NilLabels, curationFilterOperations)
	prometheus.Register("prometheus_curation_duration_ms_total", "The total time spent in curation (ms).", prometheus.NilLabels, curationDuration)
	prometheus.Register("prometheus_curation_durations_ms", "Histogram of time spent in curation (ms).", prometheus.NilLabels, curationDurations)
	prometheus.Register("prometheus_stored_samples_total", "The number of samples that have been stored.", prometheus.NilLabels, storedSamplesCount)
}
开发者ID:pjjw,项目名称:prometheus,代码行数:10,代码来源:instrumentation.go

示例12: NewSensors

// NewSensors creates new sensors from a raw config
func NewSensors(raw []interface{}) ([]*Sensor, error) {
	var sensors []*Sensor
	if err := utils.DecodeRaw(raw, &sensors); err != nil {
		return nil, fmt.Errorf("Sensor configuration error: %v", err)
	}
	for _, s := range sensors {
		check, err := commands.NewCommand(s.CheckExec, s.Timeout)
		if err != nil {
			return nil, fmt.Errorf("could not parse check in sensor %s: %s", s.Name, err)
		}
		check.Name = fmt.Sprintf("%s.sensor", s.Name)
		s.checkCmd = check

		// the prometheus client lib's API here is baffling... they don't expose
		// an interface or embed their Opts type in each of the Opts "subtypes",
		// so we can't share the initialization.
		switch {
		case s.Type == "counter":
			s.collector = prometheus.NewCounter(prometheus.CounterOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "gauge":
			s.collector = prometheus.NewGauge(prometheus.GaugeOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "histogram":
			s.collector = prometheus.NewHistogram(prometheus.HistogramOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "summary":
			s.collector = prometheus.NewSummary(prometheus.SummaryOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		default:
			return nil, fmt.Errorf("invalid sensor type: %s", s.Type)
		}
		// we're going to unregister before every attempt to register
		// so that we can reload config
		prometheus.Unregister(s.collector)
		if err := prometheus.Register(s.collector); err != nil {
			return nil, err
		}
	}
	return sensors, nil
}
开发者ID:joyent,项目名称:containerpilot,代码行数:58,代码来源:sensors.go

示例13: NewAddsMetric

func (_ prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
	adds := prometheus.NewCounter(prometheus.CounterOpts{
		Subsystem: name,
		Name:      "adds",
		Help:      "Total number of adds handled by workqueue: " + name,
	})
	prometheus.Register(adds)
	return adds
}
开发者ID:humblec,项目名称:kubernetes,代码行数:9,代码来源:prometheus.go

示例14: NewRetriesMetric

func (_ prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
	retries := prometheus.NewCounter(prometheus.CounterOpts{
		Subsystem: name,
		Name:      "retries",
		Help:      "Total number of retries handled by workqueue: " + name,
	})
	prometheus.Register(retries)
	return retries
}
开发者ID:humblec,项目名称:kubernetes,代码行数:9,代码来源:prometheus.go

示例15: NewLatencyMetric

func (_ prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.SummaryMetric {
	latency := prometheus.NewSummary(prometheus.SummaryOpts{
		Subsystem: name,
		Name:      "queue_latency",
		Help:      "How long an item stays in workqueue" + name + " before being requested.",
	})
	prometheus.Register(latency)
	return latency
}
开发者ID:humblec,项目名称:kubernetes,代码行数:9,代码来源:prometheus.go


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