fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

add metrics for memory maps to zoekt-webserver (#426)

+90 -4
+84
cmd/zoekt-webserver/main.go
··· 27 27 "net/http" 28 28 "os" 29 29 "os/signal" 30 + "path" 30 31 "path/filepath" 32 + "runtime" 31 33 "strconv" 32 34 "strings" 33 35 "syscall" ··· 46 48 "github.com/opentracing/opentracing-go" 47 49 "github.com/prometheus/client_golang/prometheus" 48 50 "github.com/prometheus/client_golang/prometheus/promauto" 51 + "github.com/prometheus/procfs" 49 52 sglog "github.com/sourcegraph/log" 50 53 "github.com/uber/jaeger-client-go" 51 54 oteltrace "go.opentelemetry.io/otel/trace" ··· 176 179 } 177 180 178 181 mustRegisterDiskMonitor(*index) 182 + 183 + mmapLogger := sglog.Scoped("zoekt_webserver_proc_metrics_memory_map", "") 184 + mustRegisterMemoryMapMetrics(mmapLogger) 179 185 180 186 // Do not block on loading shards so we can become partially available 181 187 // sooner. Otherwise on large instances zoekt can be unavailable on the ··· 504 510 Help: "The total number of errors from zoekt watchdog.", 505 511 }) 506 512 ) 513 + 514 + func mustRegisterMemoryMapMetrics(logger sglog.Logger) { 515 + // The memory map metrics are collected via /proc, which 516 + // is only available on linux-based operating systems. 517 + 518 + if runtime.GOOS != "linux" { 519 + return 520 + } 521 + 522 + // Instantiate shared FS objects for accessing /proc and /proc/self, 523 + // and skip metrics registration if we're aren't able to instantiate them 524 + // for whatever reason. 525 + 526 + fs, err := procfs.NewDefaultFS() 527 + if err != nil { 528 + logger.Debug( 529 + "skipping registration", 530 + sglog.String("reason", "failed to initialize proc FS"), 531 + sglog.String("error", err.Error()), 532 + ) 533 + 534 + return 535 + } 536 + 537 + info, err := fs.Self() 538 + if err != nil { 539 + logger.Debug( 540 + "skipping registration", 541 + sglog.String("path", path.Join(procfs.DefaultMountPoint, "self")), 542 + sglog.String("reason", "failed to initialize process info object for current process"), 543 + sglog.String("error", err.Error()), 544 + ) 545 + 546 + return 547 + } 548 + 549 + // Register Prometheus memory map metrics 550 + 551 + prometheus.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{ 552 + Name: "proc_metrics_memory_map_max_limit", 553 + Help: "Upper limit on amount of memory mapped regions a process may have.", 554 + }, func() float64 { 555 + vm, err := fs.VM() 556 + if err != nil { 557 + logger.Debug( 558 + "failed to read virtual memory statistics for the current process", 559 + sglog.String("path", path.Join(procfs.DefaultMountPoint, "sys", "vm")), 560 + sglog.String("error", err.Error()), 561 + ) 562 + 563 + return 0 564 + } 565 + 566 + if vm.MaxMapCount == nil { 567 + return 0 568 + } 569 + 570 + return float64(*vm.MaxMapCount) 571 + })) 572 + 573 + prometheus.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{ 574 + Name: "proc_metrics_memory_map_current_count", 575 + Help: "Amount of memory mapped regions this process is currently using.", 576 + }, func() float64 { 577 + procMaps, err := info.ProcMaps() 578 + if err != nil { 579 + logger.Debug( 580 + "failed to read memory mappings for current process", 581 + sglog.String("path", path.Join(procfs.DefaultMountPoint, "self", "maps")), 582 + sglog.String("error", err.Error()), 583 + ) 584 + 585 + return 0 586 + } 587 + 588 + return float64(len(procMaps)) 589 + })) 590 + }
+2 -2
go.mod
··· 23 23 github.com/peterbourgon/ff/v3 v3.1.2 24 24 github.com/pkg/errors v0.9.1 25 25 github.com/prometheus/client_golang v1.12.1 26 + github.com/prometheus/procfs v0.8.0 26 27 github.com/rs/xid v1.4.0 27 28 github.com/sourcegraph/go-ctags v0.0.0-20220611154803-db463692f037 28 29 github.com/sourcegraph/log v0.0.0-20220901143117-fc0516a694c9 ··· 42 43 go.uber.org/automaxprocs v1.5.1 43 44 golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 44 45 golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 45 - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c 46 + golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f 46 47 gopkg.in/natefinch/lumberjack.v2 v2.0.0 47 48 ) 48 49 ··· 91 92 github.com/mschoch/smat v0.2.0 // indirect 92 93 github.com/prometheus/client_model v0.2.0 // indirect 93 94 github.com/prometheus/common v0.32.1 // indirect 94 - github.com/prometheus/procfs v0.7.3 // indirect 95 95 github.com/rogpeppe/go-internal v1.9.0 // indirect 96 96 github.com/sergi/go-diff v1.2.0 // indirect 97 97 github.com/stretchr/objx v0.2.0 // indirect
+4 -2
go.sum
··· 528 528 github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 529 529 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= 530 530 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= 531 - github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= 532 531 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= 532 + github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= 533 + github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= 533 534 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= 534 535 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 535 536 github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= ··· 786 787 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 787 788 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 788 789 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 789 - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= 790 790 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 791 + golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8= 792 + golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 791 793 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 792 794 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 793 795 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=