Skip to content

Commit

Permalink
fix go mod path
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Leavoy committed Apr 17, 2020
1 parent 906c95e commit 5ff0780
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 46 deletions.
7 changes: 4 additions & 3 deletions plugins/metrics/runtime/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/open-telemetry/opentelemetry-go-contrib/plugins/metrics/runtime
module go.opentelemetry.io/contrib/plugins/metrics/runtime

go 1.13

require (
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20200310182322-adf4263e074b
github.com/lightstep/lightstep-tracer-go v0.20.0 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/shirou/gopsutil v2.20.1+incompatible
go.opentelemetry.io/otel v0.4.2
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
)
51 changes: 9 additions & 42 deletions plugins/metrics/runtime/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,35 @@ github.com/benbjohnson/clock v1.0.0/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiU
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lightstep/lightstep-tracer-common v1.1.0 h1:k9/hpWZ6Co9qknZ6+LccAYYJclt8MkkZvkNYgk+vJRk=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20200305213919-a88bf8de3718/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20200310182322-adf4263e074b h1:VeihJ0q06gJMLWuhq8MZFVZf2qIX69sVAJOFZm0AooM=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20200310182322-adf4263e074b/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.20.0 h1:Kwc+Vt7N2mxTyEdLuARDfx1nUAwHILcg1s8jBAxqSIg=
github.com/lightstep/lightstep-tracer-go v0.20.0/go.mod h1:RnONwHKg89zYPmF+Uig5PpHMUcYCFgml8+r4SS53y7A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY=
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io v0.1.0 h1:EANZoRCOP+A3faIlw/iN6YEWoYb1vleZRKm1EvH8T48=
go.opentelemetry.io/otel v0.4.2 h1:nT+GOqqRR1cIY92xmo1DeiXLHtIlXH1KLRgnsnhuNrs=
go.opentelemetry.io/otel v0.4.2/go.mod h1:OgNpQOjrlt33Ew6Ds0mGjmcTQg/rhUctsbkRdk/g1fw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -61,59 +45,42 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd h1:r7DufRZuZbWB7j439YfAzP8RPDa9unLkpwQKUYbIMPI=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101 h1:wuGevabY6r+ivPNagjUXGGxF+GqgMd+dBhjsxW4q9u4=
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
243 changes: 243 additions & 0 deletions plugins/metrics/runtime/internal/procstats/procstats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package procstats

import (
"math"
"runtime"
"time"

// "github.com/segmentio/stats/v4"
)

func init() {
stats.Buckets.Set("go.memstats:gc_pause.seconds",
1*time.Microsecond,
10*time.Microsecond,
100*time.Microsecond,
1*time.Millisecond,
10*time.Millisecond,
100*time.Millisecond,
1*time.Second,
math.Inf(+1),
)
}

// GoMetrics is a metric collector that reports metrics from the Go runtime.
type GoMetrics struct {
engine *stats.Engine
version string `tag:"version"`

runtime struct {
// Runtime info.
numCPU int `metric:"cpu.num" type:"gauge"`
numGoroutine int `metric:"goroutine.num" type:"gauge"`
numCgoCall int `metric:"cgo.calls" type:"counter"`
lastNumCgoCall int
} `metric:"go.runtime"`

memstats struct {
// General statistics.
total struct {
alloc uint64 `metric:"alloc.bytes" type:"gauge"` // bytes allocated (even if freed)
totalAlloc uint64 `metric:"total_alloc.bytes" type:"counter"` // bytes allocated (even if freed)
lookups uint64 `metric:"lookups.count" type:"counter"` // number of pointer lookups
mallocs uint64 `metric:"mallocs.count" type:"counter"` // number of mallocs
frees uint64 `metric:"frees.count" type:"counter"` // number of frees
memtype string `tag:"type"`
}

// Main allocation heap statistics.
heap struct {
alloc uint64 `metric:"alloc.bytes" type:"gauge"` // bytes allocated and not yet freed
sys uint64 `metric:"sys.bytes" type:"gauge"` // bytes obtained from system
idle uint64 `metric:"idle.bytes" type:"gauge"` // bytes in idle spans
inuse uint64 `metric:"inuse.bytes" type:"gauge"` // bytes in non-idle span
released uint64 `metric:"released.bytes" type:"counter"` // bytes released to the OS
objects uint64 `metric:"objects.count" type:"gauge"` // total number of allocated objects
memtype string `tag:"type"`
}

// Low-level fixed-size structure allocator statistics.
stack struct {
inuse uint64 `metric:"inuse.bytes" type:"gauge"` // bytes used by stack allocator
sys uint64 `metric:"sys.bytes" type:"gauge"`
memtype string `tag:"type"`
}

mspan struct {
inuse uint64 `metric:"inuse.bytes" type:"gauge"` // mspan structures
sys uint64 `metric:"sys.bytes" type:"gauge"`
memtype string `tag:"type"`
}

mcache struct {
inuse uint64 `metric:"inuse.bytes" type:"gauge"` // mcache structures
sys uint64 `metric:"sys.bytes" type:"gauge"`
memtype string `tag:"type"`
}

buckhash struct {
sys uint64 `metric:"sys.bytes" type:"gauge"` // profiling bucket hash table
memtype string `tag:"type"`
}

gc struct {
sys uint64 `metric:"sys.bytes" type:"gauge"` // GC metadata
memtype string `tag:"type"`
}

other struct {
sys uint64 `metric:"sys.bytes" type:"gauge"` // other system allocations
memtype string `tag:"type"`
}

// Garbage collector statistics.
numGC uint32 `metric:"gc.count" type:"counter"` // number of garbage collections
nextGC uint64 `metric:"gc_next.bytes" type:"gauge"` // next collection will happen when HeapAlloc ≥ this amount
gcPauseAvg time.Duration `metric:"gc_pause.seconds.avg" type:"gauge"`
gcPauseMin time.Duration `metric:"gc_pause.seconds.min" type:"gauge"`
gcPauseMax time.Duration `metric:"gc_pause.seconds.max" type:"gauge"`
gcCPUFraction float64 `metric:"gc_cpu.fraction" type:"gauge"` // fraction of CPU time used by GC
} `metric:"go.memstats"`

// cache
ms runtime.MemStats
}

// NewGoMetrics creates a new collector for the Go runtime that produces metrics
// on the default stats engine.
func NewGoMetrics() *GoMetrics {
return NewGoMetricsWith(stats.DefaultEngine)
}

// NewGoMetricsWith creates a new collector for the Go unrtime that producers
// metrics on eng.
func NewGoMetricsWith(eng *stats.Engine) *GoMetrics {
g := &GoMetrics{
engine: eng,
version: runtime.Version(),
}

g.memstats.total.memtype = "total"
g.memstats.heap.memtype = "heap"
g.memstats.stack.memtype = "stack"
g.memstats.mspan.memtype = "mspan"
g.memstats.mcache.memtype = "mcache"
g.memstats.buckhash.memtype = "bucket_hash_table"
g.memstats.gc.memtype = "gc"
g.memstats.other.memtype = "other"
return g
}

// Collect satisfies the Collector interface.
func (g *GoMetrics) Collect() {
now := time.Now()

lastTotalAlloc := g.ms.TotalAlloc
lastLookups := g.ms.Lookups
lastMallocs := g.ms.Mallocs
lastFrees := g.ms.Frees
lastHeapRealeased := g.ms.HeapReleased
lastNumGC := g.ms.NumGC
lastNumCgoCall := g.runtime.lastNumCgoCall
g.runtime.lastNumCgoCall = int(runtime.NumCgoCall())

g.runtime.numCPU = runtime.NumCPU()
g.runtime.numGoroutine = runtime.NumGoroutine()
g.runtime.numCgoCall = g.runtime.lastNumCgoCall - lastNumCgoCall

pauses := collectMemoryStats(&g.ms, lastNumGC)

g.memstats.total.alloc = g.ms.Alloc
g.memstats.total.totalAlloc = g.ms.TotalAlloc - lastTotalAlloc
g.memstats.total.lookups = g.ms.Lookups - lastLookups
g.memstats.total.mallocs = g.ms.Mallocs - lastMallocs
g.memstats.total.frees = g.ms.Frees - lastFrees

g.memstats.heap.alloc = g.ms.HeapAlloc
g.memstats.heap.sys = g.ms.HeapSys
g.memstats.heap.idle = g.ms.HeapIdle
g.memstats.heap.inuse = g.ms.HeapInuse
g.memstats.heap.released = g.ms.HeapReleased - lastHeapRealeased
g.memstats.heap.objects = g.ms.HeapObjects

g.memstats.stack.inuse = g.ms.StackInuse
g.memstats.stack.sys = g.ms.StackSys
g.memstats.mspan.inuse = g.ms.MSpanInuse
g.memstats.mspan.sys = g.ms.MSpanSys
g.memstats.mcache.inuse = g.ms.MCacheInuse
g.memstats.mcache.sys = g.ms.MCacheSys
g.memstats.buckhash.sys = g.ms.BuckHashSys
g.memstats.gc.sys = g.ms.GCSys
g.memstats.other.sys = g.ms.OtherSys

g.memstats.numGC = g.ms.NumGC - lastNumGC
g.memstats.nextGC = g.ms.NextGC
g.memstats.gcCPUFraction = g.ms.GCCPUFraction

if len(pauses) == 0 {
g.memstats.gcPauseAvg = 0
g.memstats.gcPauseMin = 0
g.memstats.gcPauseMax = 0
} else {
g.memstats.gcPauseMin = pauses[0]
g.memstats.gcPauseMax = pauses[0]
g.memstats.gcPauseAvg = pauses[0]

for _, pause := range pauses[1:] {
g.memstats.gcPauseAvg += pause
switch {
case pause < g.memstats.gcPauseMin:
g.memstats.gcPauseMin = pause
case pause > g.memstats.gcPauseMax:
g.memstats.gcPauseMax = pause
}
}

g.memstats.gcPauseAvg /= time.Duration(len(pauses))
}

g.engine.ReportAt(now, g)
}

func collectMemoryStats(memstats *runtime.MemStats, lastNumGC uint32) (pauses []time.Duration) {
runtime.ReadMemStats(memstats)
return makeGCPauses(memstats, lastNumGC)
}

func makeGCPauses(memstats *runtime.MemStats, lastNumGC uint32) (pauses []time.Duration) {
delta := int(memstats.NumGC - lastNumGC)

if delta == 0 {
return nil
}

if delta >= len(memstats.PauseNs) {
return makePauses(memstats.PauseNs[:], nil)
}

length := uint32(len(memstats.PauseNs))
offset := length - 1

i := (lastNumGC + offset + 1) % length
j := (memstats.NumGC + offset + 1) % length

if j < i { // wrap around the circular buffer
return makePauses(memstats.PauseNs[i:], memstats.PauseNs[:j])
}

return makePauses(memstats.PauseNs[i:j], nil)
}

func makePauses(head []uint64, tail []uint64) (pauses []time.Duration) {
pauses = make([]time.Duration, 0, len(head)+len(tail))
pauses = appendPauses(pauses, head)
pauses = appendPauses(pauses, tail)
return
}

func appendPauses(pauses []time.Duration, values []uint64) []time.Duration {
for _, v := range values {
pauses = append(pauses, time.Duration(v))
}
return pauses
}
Loading

0 comments on commit 5ff0780

Please sign in to comment.