项目作者: memprofiler

项目描述 :
Service that helps to track heap allocations in Go applications
高级语言: Go
项目地址: git://github.com/memprofiler/memprofiler.git
创建时间: 2018-07-18T18:25:22Z
项目社区:https://github.com/memprofiler/memprofiler

开源协议:

下载


memprofiler

Build Status
codecov

Memprofiler helps to track memory allocations of your Go applications on
large time intervals. Go runtime implements multiple memory management
optimizations in order to achieve good performance, low heap allocation
cost and high degree of memory reuse. Therefore, sometimes it may be
tricky to distinguish “normal” runtime behaviour from real memory leak.
If you have doubts whether your Go service is leaking, you’re on the right
track. Memprofiler aims to be an open source equivalent of
stackimpact.com.

Warning: The project is under active development and not ready for usage yet.

Getting started

Memprofiler is a client-server application. Memprofiler client is embedded
into your Go service and streams memory usage reports to the Memprofiler server.
Memprofiler server stores reports and performs some computations on the
data stream to turn it in a small set of aggregated metrics.
User will be able to interact with Memprofiler server via simple Web UI.

Components

Client

To use Memprofiler in your application, run client in your main function:

  1. package example
  2. import (
  3. "time"
  4. "github.com/sirupsen/logrus"
  5. "github.com/memprofiler/memprofiler/client"
  6. "github.com/memprofiler/memprofiler/schema"
  7. "github.com/memprofiler/memprofiler/utils"
  8. )
  9. func main() {
  10. // prepare client configuration
  11. cfg := &client.Config{
  12. // server address
  13. ServerEndpoint: "localhost:46219",
  14. // description of your application instance
  15. ServiceDescription: &schema.ServiceDescription{
  16. ServiceType: "test_application",
  17. ServiceInstance: "node_1",
  18. },
  19. // granularity
  20. Periodicity: &utils.Duration{Duration: time.Second},
  21. // logging setting
  22. Verbose: false,
  23. }
  24. // you can implement your own logger
  25. log := client.LoggerFromLogrus(logrus.New())
  26. // run profiler and stop it explicitly on exit
  27. profiler, err := client.NewProfiler(log, cfg)
  28. if err != nil {
  29. panic(err)
  30. }
  31. profiler.Start()
  32. defer profiler.Quit()
  33. // ...
  34. }

Server

To run Memprofiler server, just install it and prepare server config
(you can refer to config example).

  1. GO111MODULE=on go get github.com/memprofiler/memprofiler
  2. memprofiler -c config.yml
  3. DEBU[0000] Starting storage
  4. DEBU[0000] Starting metrics computer
  5. INFO[0000] HTTP Frontend server resource URL=/schema.MemprofilerFrontend/GetSessions subsystem=frontend
  6. INFO[0000] HTTP Frontend server resource URL=/schema.MemprofilerFrontend/GetServices subsystem=frontend
  7. INFO[0000] HTTP Frontend server resource URL=/schema.MemprofilerFrontend/GetInstances subsystem=frontend
  8. INFO[0000] HTTP Frontend server resource URL=/schema.MemprofilerFrontend/SubscribeForSession subsystem=frontend
  9. INFO[0000] Starting service service=backend
  10. INFO[0000] Starting service service=frontend