Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goroutines #17

Open
ardan-bkennedy opened this issue Mar 29, 2016 · 8 comments
Open

Goroutines #17

ardan-bkennedy opened this issue Mar 29, 2016 · 8 comments

Comments

@ardan-bkennedy
Copy link

I can't seem to have it report the number of goroutines in my running process? I am using the vars="Goroutines". I do see memory stats

expvarmon -ports="4000" -vars="Goroutines,mem:memstats.HeapInuse"

@divan
Copy link
Owner

divan commented Mar 29, 2016

Hi,

Does "Goroutines" field is present in /debug/vars JSON?

Whit is the output of the following command?
curl -s http://localhost:4000/debug/vars | grep Goroutines

@maded2
Copy link

maded2 commented Apr 9, 2016

Using Go 1.5.4 - Goroutines is not exported in the /debug/vars JSON

here's json for memstat:

"memstats": {"Alloc":5499512,"TotalAlloc":504807448,"Sys":18983224,"Lookups":420,"Mallocs":8856735,"Frees":8798054,"HeapAlloc":5499512,"HeapSys":9928704,"HeapIdle":2220032,"HeapInuse":7708672,"HeapReleased":0,"HeapObjects":58681,"StackInuse":1605632,"StackSys":1605632,"MSpanInuse":95424,"MSpanSys":114688,"MCacheInuse":9664,"MCacheSys":16384,"BuckHashSys":1514836,"GCSys":375808,"OtherSys":5427172,"NextGC":7305090,"LastGC":1460213329874430150,"PauseTotalNs":41081667,"PauseNs":[424640,360910,183002,308915,185596,272903,340900,308836,285361,248796,362968,254382,182209,317215,503425,254707,255963,244918,357311,259579,268391,435154,262704,235397,248977,228154,300874,203720,253363,233115,212842,349334,276849,226944,244197,183586,263154,236516,327651,255430,185573,216214,197735,213513,358075,252029,279676,275459,256201,257779,263048,197512,290664,259778,253963,251716,519012,262333,329473,259796,234458,252393,211881,280516,210608,272262,257206,249624,256743,268125,239731,277310,265276,297404,258137,184806,188294,195857,288548,373749,430788,264243,199819,201113,196004,208040,297842,189894,197500,333817,283296,255623,321814,231649,295664,313473,231542,316965,366752,318756,255302,256307,258630,259000,264199,331680,263610,209958,268625,244055,327139,258554,282879,286830,328837,326887,558210,215492,297057,220980,262948,306264,355643,286714,325603,228056,376459,203576,575990,320769,252729,204286,270356,275685,215305,338613,411549,259255,221400,236319,335821,227790,198892,337678,321432,398179,353953,210213,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"PauseEnd":[1460212419950871012,1460212419964380563,1460212420220828563,1460212420228441950,1460212421195328267,1460212425887929770,1460212436317007080,1460212440698388367,1460212444372459685,1460212451700262166,1460212460698138060,1460212465556566933,1460212474262065841,1460212479806197906,1460212480750406760,1460212484719613564,1460212491451765323,1460212498859512834,1460212501032495329,1460212507505496596,1460212516561580170,1460212520706652823,1460212526998940122,1460212533638297809,1460212539488789265,1460212540702478322,1460212543942313749,1460212550390991767,1460212555305970794,1460212560100522604,1460212561948004665,1460212567536676955,1460212573649531225,1460212579845034405,1460212581723236203,1460212587221023191,1460212592875304274,1460212598911932278,1460212600722742043,1460212603099921119,1460212608241035156,1460212613340041163,1460212618367189794,1460212620713124886,1460212626555847635,1460212633978161092,1460212640016505856,1460212642551013442,1460212648060348511,1460212655564274446,1460212660254460493,1460212661236503560,1460212665191745302,1460212670926605167,1460212675599805215,1460212680449961491,1460212683339336899,1460212688971212377,1460212695132309267,1460212700384061148,1460212703246259344,1460212708975488953,1460212714612301782,1460212719783090499,1460212720882960408,1460212724257283836,1460212729833241739,1460212735020197142,1460212739961165527,1460212742796185881,1460212747850461143,1460212755314818636,1460212760947416073,1460212764715222523,1460212770562845973,1460212777509808380,1460212780732122663,1460212782491587660,1460212790988688864,1460212799279629287,1460212802180938522,1460212809175243055,1460212817745878549,1460212821181578317,1460212828567023009,1460212836511786719,1460212840625146596,1460212842339605136,1460212848859731749,1460212852634971087,1460212859516327363,1460212861882887719,1460212865396459920,1460212875724584455,1460212880993620814,1460212892053011352,1460212899799978150,1460212901548388177,1460212910988913695,1460212919833307051,1460212922619606550,1460212934426757594,1460212940632855274,1460212949486876000,1460212960081794732,1460212961672009262,1460212971005375427,1460212980600987938,1460212991671877178,1460213000605815386,1460213017012923605,1460213020825394431,1460213028419920207,1460213040042018782,1460213045661490982,1460213059496912728,1460213064128832155,1460213076108555505,1460213080634739154,1460213084638866806,1460213100085900271,1460213107534675249,1460213119816205453,1460213125013746401,1460213139782691091,1460213141123717813,1460213151056503519,1460213160103944807,1460213163459158051,1460213177568909007,1460213184350937079,1460213193225009242,1460213200762737302,1460213206479336667,1460213213695758997,1460213220659560776,1460213228222632480,1460213239980965312,1460213247123212412,1460213259801080752,1460213261157386234,1460213271021219625,1460213280606571893,1460213292471086938,1460213300616709759,1460213314414704408,1460213320632255120,1460213329874430150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"NumGC":148,"GCCPUFraction":7.02748399173599e-05,"EnableGC":true,"DebugGC":false,"BySize":[{"Size":0,"Mallocs":0,"Frees":0},{"Size":8,"Mallocs":9419,"Frees":9270},{"Size":16,"Mallocs":6131414,"Frees":6100067},{"Size":32,"Mallocs":1157872,"Frees":1144694},{"Size":48,"Mallocs":751985,"Frees":747895},{"Size":64,"Mallocs":222323,"Frees":219503},{"Size":80,"Mallocs":22543,"Frees":22038},{"Size":96,"Mallocs":46979,"Frees":46302},{"Size":112,"Mallocs":58241,"Frees":57577},{"Size":128,"Mallocs":34371,"Frees":34130},{"Size":144,"Mallocs":15784,"Frees":15701},{"Size":160,"Mallocs":35943,"Frees":35310},{"Size":176,"Mallocs":28585,"Frees":28328},{"Size":192,"Mallocs":9938,"Frees":9836},{"Size":208,"Mallocs":2185,"Frees":2111},{"Size":224,"Mallocs":32695,"Frees":32276},{"Size":240,"Mallocs":80109,"Frees":79288},{"Size":256,"Mallocs":10838,"Frees":10682},{"Size":288,"Mallocs":32367,"Frees":32105},{"Size":320,"Mallocs":6447,"Frees":6090},{"Size":352,"Mallocs":2229,"Frees":2198},{"Size":384,"Mallocs":446,"Frees":157},{"Size":416,"Mallocs":497,"Frees":459},{"Size":448,"Mallocs":1148,"Frees":1070},{"Size":480,"Mallocs":497,"Frees":489},{"Size":512,"Mallocs":74329,"Frees":74067},{"Size":576,"Mallocs":2917,"Frees":2829},{"Size":640,"Mallocs":145,"Frees":137},{"Size":704,"Mallocs":1905,"Frees":1867},{"Size":768,"Mallocs":525,"Frees":521},{"Size":896,"Mallocs":968,"Frees":899},{"Size":1024,"Mallocs":786,"Frees":711},{"Size":1152,"Mallocs":818,"Frees":504},{"Size":1280,"Mallocs":77,"Frees":64},{"Size":1408,"Mallocs":2482,"Frees":2449},{"Size":1536,"Mallocs":68292,"Frees":68046},{"Size":1664,"Mallocs":58,"Frees":46},{"Size":2048,"Mallocs":417,"Frees":396},{"Size":2304,"Mallocs":214,"Frees":206},{"Size":2560,"Mallocs":1084,"Frees":1082},{"Size":2816,"Mallocs":77,"Frees":75},{"Size":3072,"Mallocs":18,"Frees":15},{"Size":3328,"Mallocs":303,"Frees":297},{"Size":4096,"Mallocs":2147,"Frees":2090},{"Size":4608,"Mallocs":1393,"Frees":1378},{"Size":5376,"Mallocs":180,"Frees":165},{"Size":6144,"Mallocs":275,"Frees":268},{"Size":6400,"Mallocs":33,"Frees":33},{"Size":6656,"Mallocs":30,"Frees":28},{"Size":6912,"Mallocs":16,"Frees":16},{"Size":8192,"Mallocs":612,"Frees":566},{"Size":8448,"Mallocs":302,"Frees":302},{"Size":8704,"Mallocs":32,"Frees":31},{"Size":9472,"Mallocs":115,"Frees":113},{"Size":10496,"Mallocs":0,"Frees":0},{"Size":12288,"Mallocs":4,"Frees":2},{"Size":13568,"Mallocs":0,"Frees":0},{"Size":14080,"Mallocs":0,"Frees":0},{"Size":16384,"Mallocs":81,"Frees":78},{"Size":16640,"Mallocs":40,"Frees":0},{"Size":17664,"Mallocs":5,"Frees":3}]},

@divan
Copy link
Owner

divan commented Apr 9, 2016

Oh right, expvar package doesn't export goroutines number. It should be done via expvar.Func, something like this:

func goroutines() interface{} {
    return runtime.NumGoroutine()
}
...
expvar.Publish("Goroutines", expvar.Func(goroutines))

I guess README misleads people to think that Goroutines is exported, but it's not. Any suggestions how to improve?

@maded2
Copy link

maded2 commented Apr 9, 2016

gr:= expvar.NewInt("Goroutines")
go func() {
for _ = range time.Tick(d) {
gr.Set(int64(runtime.NumGoroutine()))
}

@dgryski
Copy link

dgryski commented Apr 9, 2016

@maded2 The solution from @divan only calls NumGoroutine() when requested and doesn't spawn an extra goroutine just to set this one constant.

@ardan-bkennedy
Copy link
Author

Goroutines are working now. I didn't realize you can add your own metrics. This is cool.

@ardan-bkennedy
Copy link
Author

is there a published list of default variables?

@divan
Copy link
Owner

divan commented Jan 17, 2017

is there a published list of default variables?

Sorry for delay (half a year one) with response :) The list is available as part of the expvarmon --help output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants