-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add graph visualization with throughtput metrics
- Loading branch information
1 parent
edacf6f
commit d67c8e5
Showing
28 changed files
with
394 additions
and
68 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
static: | ||
cd mirror/server && statik -f -src ./public | ||
|
||
proto: | ||
cd mirror && protoc -I=. --go_out=. *.proto |
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
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
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
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
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
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,92 @@ | ||
package graph | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/emicklei/dot" | ||
"github.com/shimmerglass/http-mirror-pipeline/mirror" | ||
) | ||
|
||
func FromModule(m mirror.Module) *dot.Graph { | ||
g := dot.NewGraph(dot.Directed) | ||
g.Attr("nodesep", "2") | ||
processNode(g, nil, m) | ||
return g | ||
} | ||
|
||
func GraphSVG(g *dot.Graph, w io.Writer) error { | ||
fmt.Println(g.String()) | ||
cmd := exec.Command("dot", "-Tsvg") | ||
cmd.Stdin = strings.NewReader(g.String()) | ||
cmd.Stdout = w | ||
|
||
return cmd.Run() | ||
} | ||
|
||
func processNode(g *dot.Graph, parents []dot.Node, m mirror.Module) []dot.Node { | ||
ctx := m.Context() | ||
current := g.Node(ctx.Name) | ||
role := ctx.Role() | ||
|
||
if role != "virtual" { | ||
current.Attr("label", dot.HTML( | ||
fmt.Sprintf(` | ||
%s<BR /> | ||
<FONT point-size="11"><B>Throughput:</B> %d/s</FONT><BR /> | ||
<FONT point-size="10">%s</FONT> | ||
`, ctx.Name, ctx.RPS, ctx.Type), | ||
)) | ||
} | ||
|
||
current.Attr("width", "3") | ||
|
||
switch ctx.Role() { | ||
case "virtual": | ||
current.Attr("shape", "underline") | ||
case "source": | ||
current.Attr("shape", "invhouse") | ||
current.Attr("color", "#2D232F") | ||
current.Attr("fillcolor", "#634B66") | ||
current.Attr("fontcolor", "#FFFFFF") | ||
current.Attr("style", "filled") | ||
case "sink": | ||
current.Attr("shape", "invhouse") | ||
current.Attr("color", "#144667") | ||
current.Attr("fillcolor", "#2176AE") | ||
current.Attr("fontcolor", "#FFFFFF") | ||
current.Attr("style", "filled") | ||
default: | ||
current.Attr("shape", "hexagon") | ||
current.Attr("color", "#94A0B3") | ||
current.Attr("fillcolor", "#D2D7DF") | ||
current.Attr("fontcolor", "#000000") | ||
current.Attr("style", "filled") | ||
} | ||
|
||
for _, p := range parents { | ||
g.Edge(p, current) | ||
} | ||
|
||
children := m.Children() | ||
leafs := []dot.Node{} | ||
|
||
for _, group := range children { | ||
parents := []dot.Node{current} | ||
for i, child := range group { | ||
parents = processNode(g, parents, child) | ||
|
||
if i == len(group)-1 { | ||
leafs = append(leafs, parents...) | ||
} | ||
} | ||
} | ||
|
||
if len(leafs) == 0 { | ||
leafs = append(leafs, current) | ||
} | ||
|
||
return leafs | ||
} |
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,10 +1,46 @@ | ||
package mirror | ||
|
||
import ( | ||
"strings" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
var ( | ||
RequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
Name: "requets_total", | ||
Help: "The total number of requets handled by the module", | ||
}, []string{"module"}) | ||
) | ||
|
||
type ModuleContext struct { | ||
Name string | ||
Type string | ||
Name string | ||
RPS int | ||
requestCounter uint64 | ||
} | ||
|
||
func (c *ModuleContext) Role() string { | ||
return strings.Split(c.Type, ".")[0] | ||
} | ||
|
||
func (c *ModuleContext) HandledRequest() { | ||
atomic.AddUint64(&c.requestCounter, 1) | ||
RequestsTotal.WithLabelValues(c.Name).Inc() | ||
} | ||
|
||
func (c *ModuleContext) Run() { | ||
for range time.Tick(time.Second) { | ||
c.RPS = int(atomic.SwapUint64(&c.requestCounter, 0)) | ||
} | ||
} | ||
|
||
type Module interface { | ||
Context() *ModuleContext | ||
SetInput(<-chan Request) | ||
Output() <-chan Request | ||
Children() [][]Module | ||
} |
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
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
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
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
Oops, something went wrong.