-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
921 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"go.lintTool":"golangci-lint", | ||
"go.lintFlags": [ | ||
"--fast" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Contribution | ||
|
||
All contributions and comments welcome! Open an issue or create a Pull Request whenever you find a bug or have an idea to imporve the library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
# roumon | ||
Universal goroutine monitor using pprof and termui | ||
|
||
 | ||
[![Go Report Card][go-report-image]][go-report-url] | ||
[![PRs Welcome][pr-welcome-image]][pr-welcome-url] | ||
|
||
[go-report-image]: https://goreportcard.com/badge/github.com/becheran/roumon | ||
[go-report-url]: https://goreportcard.com/report/github.com/becheran/roumon | ||
[pr-welcome-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg | ||
[pr-welcome-url]: https://github.com/becheran/roumon/blob/master/CONTRIBUTING.md | ||
|
||
A go**rou**tine **mon**itor to keep track of active routines from within your favorite shell. | ||
|
||
 | ||
|
||
## Features | ||
|
||
TODO | ||
|
||
## Installation | ||
|
||
TODO | ||
|
||
## Usage | ||
|
||
TODO | ||
|
||
## Contributing | ||
|
||
Pull requests and issues [are welcome](./CONTRIBUTING.md)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
// TODO: Remove for production | ||
"net/http" | ||
_ "net/http/pprof" | ||
"os" | ||
|
||
"github.com/becheran/roumon/internal/client" | ||
"github.com/becheran/roumon/internal/model" | ||
"github.com/becheran/roumon/internal/ui" | ||
) | ||
|
||
func main() { | ||
// TODO: Remove for production | ||
go func() { | ||
log.Println(http.ListenAndServe("localhost:6061", nil)) | ||
}() | ||
|
||
var logFile string | ||
var host string | ||
var port int | ||
flag.StringVar(&logFile, "log", "", "Path to logfile") | ||
flag.StringVar(&host, "host", "localhost", "The pprof server IP or hostname. Default is 'localhost'") | ||
flag.IntVar(&port, "port", 6060, "The pprof server port. Default is 6060") | ||
flag.Parse() | ||
|
||
if len(logFile) > 0 { | ||
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Fatalf("error opening file: %v", err) | ||
} | ||
defer f.Close() | ||
log.SetOutput(f) | ||
} | ||
|
||
log.Print("Start") | ||
|
||
c := client.NewClient(host, port) | ||
ui := ui.NewUI() | ||
defer ui.Stop() | ||
terminate := make(chan error) | ||
|
||
routinesUpdate := make(chan []model.Goroutine) | ||
go c.Run(terminate, routinesUpdate) | ||
go ui.Run(terminate, routinesUpdate) | ||
|
||
err := <-terminate | ||
|
||
if err != nil { | ||
log.Printf("Error: %s\n", err.Error()) | ||
} | ||
|
||
log.Print("Stopped") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/becheran/roumon | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/gizak/termui/v3 v3.1.0 | ||
github.com/stretchr/testify v1.7.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= | ||
github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= | ||
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o= | ||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= | ||
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= | ||
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= | ||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/becheran/roumon/internal/model" | ||
) | ||
|
||
type Client struct { | ||
c *http.Client | ||
server string | ||
} | ||
|
||
func NewClient(ip string, port int) *Client { | ||
server := fmt.Sprintf("http://%s:%d/debug/pprof/goroutine?debug=2", ip, port) | ||
log.Printf("Attach to server %s\n", server) | ||
c := &http.Client{} | ||
return &Client{ | ||
c: c, | ||
server: server, | ||
} | ||
} | ||
|
||
func (client *Client) Run(terminate chan<- error, routineUpdate chan<- []model.Goroutine) { | ||
ticker := time.NewTicker(time.Second * 1) | ||
defer ticker.Stop() | ||
|
||
for { | ||
resp, err := client.c.Get(client.server) | ||
if err != nil { | ||
terminate <- fmt.Errorf("Failed to list go routines. Err: %s", err.Error()) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
goroutines, err := model.ParseStackFrame(resp.Body) | ||
if err != nil { | ||
log.Printf("Error while parsing stack: %s", err.Error()) | ||
} else { | ||
routineUpdate <- goroutines | ||
} | ||
<-ticker.C | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package client_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"testing" | ||
|
||
"github.com/becheran/roumon/internal/client" | ||
"github.com/becheran/roumon/internal/model" | ||
) | ||
|
||
func TestPrint(t *testing.T) { | ||
c := client.NewClient("localhost", 6060) | ||
done := make(chan error) | ||
routines := make(chan []model.Goroutine) | ||
|
||
go c.Run(done, routines) | ||
select { | ||
case r := <-routines: | ||
fmt.Println(r) | ||
case <-done: | ||
log.Fatal("Failed") | ||
} | ||
} |
Oops, something went wrong.