MCPcopy
hub / github.com/dgraph-io/dgraph / init

Function init

x/metrics.go:444–484  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

442)
443
444func init() {
445 Conf = expvar.NewMap("dgraph_config")
446
447 ctx := MetricsContext()
448 go func() {
449 var v string
450 ticker := time.Tick(5 * time.Second)
451
452 for range ticker {
453 v = TagValueStatusOK
454 if err := HealthCheck(); err != nil {
455 v = TagValueStatusError
456 }
457 cctx, _ := tag.New(ctx, tag.Upsert(KeyStatus, v))
458 // TODO: Do we need to set health to zero, or would this tag be sufficient to
459 // indicate if Alpha is up but HealthCheck is failing.
460 ostats.Record(cctx, AlphaHealth.M(1))
461 }
462 }()
463
464 CheckfNoTrace(view.Register(allViews...))
465
466 promRegistry := prometheus.NewRegistry()
467 promRegistry.MustRegister(NewBadgerCollector())
468 promRegistry.MustRegister(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(
469 collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")})))
470 promRegistry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
471
472 pe, err := oc_prom.NewExporter(oc_prom.Options{
473 // includes a process_* metrics, a GoCollector for go_* metrics, and the badger_* metrics.
474 Registry: promRegistry,
475 Namespace: "dgraph",
476 OnError: func(err error) { glog.Errorf("%v", err) },
477 })
478 Checkf(err, "Failed to create OpenCensus Prometheus exporter: %v", err)
479 view.RegisterExporter(pe)
480
481 // Exposing metrics at /metrics, which is the usual standard, as well as at the old endpoint
482 http.Handle("/metrics", pe)
483 http.Handle("/debug/prometheus_metrics", pe)
484}
485
486// NewBadgerCollector returns a prometheus Collector for Badger metrics from expvar.
487func NewBadgerCollector() prometheus.Collector {

Callers

nothing calls this directly

Calls 8

MetricsContextFunction · 0.85
HealthCheckFunction · 0.85
CheckfNoTraceFunction · 0.85
NewBadgerCollectorFunction · 0.85
CheckfFunction · 0.85
UpsertMethod · 0.80
RecordMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected