{"id":13707155,"url":"https://github.com/e-dard/netbug","last_synced_at":"2025-03-17T08:37:05.090Z","repository":{"id":28227355,"uuid":"31731877","full_name":"e-dard/netbug","owner":"e-dard","description":"Package netbug provides a handler for registering profilers on your own ServeMux.","archived":false,"fork":false,"pushed_at":"2015-10-29T17:28:38.000Z","size":178,"stargazers_count":72,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T21:33:18.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e-dard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-05T19:27:29.000Z","updated_at":"2024-10-25T15:51:00.000Z","dependencies_parsed_at":"2022-09-04T17:00:37.291Z","dependency_job_id":null,"html_url":"https://github.com/e-dard/netbug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-dard%2Fnetbug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-dard%2Fnetbug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-dard%2Fnetbug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-dard%2Fnetbug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-dard","download_url":"https://codeload.github.com/e-dard/netbug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852484,"owners_count":20358271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T22:01:22.059Z","updated_at":"2025-03-17T08:37:04.746Z","avatar_url":"https://github.com/e-dard.png","language":"Go","readme":"# netbug\n\n[![GoDoc](https://godoc.org/github.com/e-dard/netbug?status.svg)](https://godoc.org/github.com/e-dard/netbug)\n\nPackage `netbug` provides access to an `http.Handler` that accesses the profiling and debug tools available in the `/net/http/pprof` and `/runtime/pprof` packages.\n\nThe advantages of using `netbug` over the existing `/net/http/pprof` handlers are:\n\n 1. You can register the handler under an arbitrary route-prefix. A use-case might be to have a secret endpoint for keeping this information hidden from prying eyes, rather than `/debug/pprof`;\n 2. It pulls together all the handlers from `/net/http/pprof` *and* `/runtime/pprof` into a single index page, for when you can't quite remember the URL for the profile you want;\n 3. You can register the handlers onto `http.ServeMux`'s that aren't `http.DefaultServeMux`;\n 4. It provides an optional handler that requires a token URL parameter. This is useful if you want that little bit of extra security (use this over HTTPS connections only).\n\n**Note**:\nIt still imports `/net/http/pprof`, which means the `/debug/pprof` routes in that package *still* get registered on `http.DefaultServeMux`.\nIf you're using this package to avoid those routes being registered, you should use it with your *own* `http.ServeMux`.\n\n`netbug` is trying to cater for the situation where you want all profiling tools available remotely on your running services, but you don't want to expose the `/debug/pprof` routes that `net/http/pprof` forces you to expose.\n\n## How do I use it?\nIn the simplest case give `netbug` the `http.ServeMux` you want to register the handlers on, as well as where you want to register the handler and you're away.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/e-dard/netbug\"\n)\n\nfunc main() {\n\tr := http.NewServeMux()\n\tnetbug.RegisterHandler(\"/myroute/\", r)\n\tif err := http.ListenAndServe(\":8080\", r); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\nVisiting [http://localhost:8080/myroute/](http://localhost:8080/myroute/) will then return:\n\n![](https://photos-3.dropbox.com/t/2/AABdAn1yRTBvqXeDJygtCRsMu1HMqTohoIJdWAQ7vH_j_g/12/5033766/png/32x32/1/1446145200/0/2/Screen%20Shot%202015-10-29%20at%2017.01.45.png/CKaeswIgASACIAMgBSAHKAEoAigH/vaSYDZEeuTA-8biklDyYORywwvL9SbVYH41Jff_CuBk?size_mode=5)\n\n`netbug` also provides a simple way of adding some authentication:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/e-dard/netbug\"\n)\n\nfunc main() {\n\tr := http.NewServeMux()\n\tnetbug.RegisterAuthHandler(\"password\", \"/myroute/\", r)\n\tif err := http.ListenAndServe(\":8080\", r); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\nAnd visit [http://localhost:8080/myroute/?token=password](http://localhost:8080/myroute/?token=password).\n\n**Obviously** this form of authentication is pointless if you're not accessing the routes over an HTTPS connection.\nIf you want to use a different form of authentication, e.g., HTTP Basic Authentication, then you can use the handler returned by `netbug.Handler()`, and wrap it with handlers provided by packages like [github.com/abbot/go-http-auth](https://github.com/abbot/go-http-auth/).\n\n### What can you do with it?\n\nIt just wraps the behaviour of the [/net/http/pprof](http://golang.org/pkg/net/http/pprof/) and [/runtime/pprof](http://golang.org/pkg/runtime/pprof/) packages.\nCheck out their documentation to see what's available.\nAs an example though, if you want to run a 30-second CPU profile on your running service it's really simple:\n\n```\n$ go tool pprof https://example.com/myroute/profile\n```\n\n##### New in Go 1.5\nYou can now produce [execution traces](https://golang.org/pkg/runtime/trace/) of your remotely running program using netbug.\n\nTo do this run one of the trace profiles, which will result in a file being downloaded. Then use the Go `trace` tool to generate a trace, which will open up in your browser.\n\n```\n$ go tool trace binary-being-profiled /path/to/downloaded/trace\n```\n\nWhen compiling `binary-being-profiled`, you will need to have targeted the same architecture as the binary that generated the profile.\n\n## Background\nThe [net/http/pprof](http://golang.org/pkg/net/http/pprof/) package is great.\nIt let's you access profiling and debug information about your running services, via `HTTP`, and even plugs straight into `go tool pprof`.\nYou can find out more about using the `net/http/pprof` package at the bottom of [this blog post](http://blog.golang.org/profiling-go-programs).\n\nHowever, there are a couple of problems with the `net/http/pprof` package.\n\n 1. It assumes you're cool about the relevant handlers being registered under the `/debug/pprof` route.\n 2. It assumes you're cool about handlers being registered on `http.DefaultServeMux`.\n 3. You can't wrap the handlers in any way, say to add authentication or other logic.\n\nYou can sort of fix (1) and (2) by digging around the `net/http/pprof` package and registering all all the exported handlers under different paths on your own `http.ServeMux`, but you still have the problem of the index page—which is useful to visit if you don't profile much—using hard-coded paths.\nIt doesn't really work well.\nAlso, the index page doesn't provide you with easy links to the debug information that the `net/http/pprof` package has handlers for.\n\n`netbug` is just a small package to fix these issues.\n\n","funding_links":[],"categories":["Utilities","工具库","公用事业公司","实用工具","工具库`可以提升效率的通用代码库和工具`","Go","實用工具","Utility"],"sub_categories":["Utility/Miscellaneous","交流","实用程序/Miscellaneous","HTTP Clients","查询语","Advanced Console UIs","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Fail injection","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-dard%2Fnetbug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe-dard%2Fnetbug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-dard%2Fnetbug/lists"}