Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
becheran committed Mar 2, 2021
1 parent 23cbd4c commit e9219c0
Show file tree
Hide file tree
Showing 14 changed files with 921 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool":"golangci-lint",
"go.lintFlags": [
"--fast"
]
}
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
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.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# roumon
Universal goroutine monitor using pprof and termui

![Build Status](https://github.com/becheran/roumon/workflows/CI/badge.svg)
[![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.

![screenshot](doc/Screenshot.png)

## Features

TODO

## Installation

TODO

## Usage

TODO

## Contributing

Pull requests and issues [are welcome](./CONTRIBUTING.md)!
58 changes: 58 additions & 0 deletions cmd/Client/main.go
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")
}
Binary file added doc/Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions go.mod
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
)
18 changes: 18 additions & 0 deletions go.sum
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=
47 changes: 47 additions & 0 deletions internal/client/client.go
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
}
}
24 changes: 24 additions & 0 deletions internal/client/client_test.go
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")
}
}
Loading

0 comments on commit e9219c0

Please sign in to comment.