Send all the container pids to the client.

This commit is contained in:
Tom Wilkie
2015-09-18 10:19:58 +00:00
committed by Tom Wilkie
parent e58f0f756f
commit 3dbb94eed3
4 changed files with 30 additions and 11 deletions

View File

@@ -3,7 +3,9 @@ Run tracer:
- ./tracer.sh start
TODO:
- need to stich traces together
- <s>need to stich traces together</s>
- deal with persistant connections
- make it work for goroutines
- test with jvm based app
- find way to get local ip address for an incoming connection
- make the container/process trace start/stop more reliable

View File

@@ -7,8 +7,8 @@ import (
"mime"
"net/http"
"strconv"
"strings"
dockerClient "github.com/fsouza/go-dockerclient"
"github.com/gorilla/mux"
"github.com/weaveworks/scope/probe/docker"
@@ -45,13 +45,31 @@ func (t *tracer) pidsForContainer(id string) ([]int, error) {
return pidTree.GetChildren(container.PID())
}
type Container struct {
Id string
Name string
PIDs []int
}
func (t *tracer) http(port int) {
router := mux.NewRouter()
router.Methods("GET").Path("/container").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
containers := []*dockerClient.Container{}
pidTree, err := process.NewTree(process.NewWalker("/proc"))
if err != nil {
respondWith(w, http.StatusBadRequest, err.Error())
return
}
containers := []Container{}
t.docker.WalkContainers(func(container docker.Container) {
containers = append(containers, container.Container())
children, _ := pidTree.GetChildren(container.PID())
out := Container{
Name: strings.TrimPrefix(container.Container().Name, "/"),
Id: container.ID(),
PIDs: children,
}
containers = append(containers, out)
})
respondWith(w, http.StatusOK, containers)

View File

@@ -95,7 +95,6 @@ func (t *trace) addChild(child *trace) {
// Fix up some fields
child.ClientDetails = candidate.ClientDetails
child.PID = candidate.PID
IncrementLevel(child, t.Level+1)
// Overwrite old record

View File

@@ -220,14 +220,14 @@
<script type="text/x-handlebars-template" id="traces">
{{#.}}
<tr class="trace" data-key="{{Key}}">
{{#if ServerDetails}}
{{#with ServerDetails}}
{{#if ClientDetails}}
{{#with ClientDetails}}
<td>{{spaces ../Level}}{{ts Start}}</td><td>{{duration .}}</td>
<td>{{../PID}}</td><td>{{FromAddr}}:{{FromPort}}</td>
<td>{{ToAddr}}:{{ToPort}}</td><td>{{count ../.}}</td>
{{/with}}
{{else}}
{{#with ClientDetails}}
{{#with ServerDetails}}
<td>{{spaces ../Level}}{{ts Start}}</td><td>{{duration .}}</td>
<td>{{../PID}}</td><td>{{FromAddr}}:{{FromPort}}</td>
<td>{{ToAddr}}:{{ToPort}}</td><td>{{count ../.}}</td>
@@ -241,15 +241,15 @@
</script>
<script type="text/x-handlebars-template" id="children">
{{#.}}
{{#if ServerDetails}}
{{#with ServerDetails}}
{{#if ClientDetails}}
{{#with ClientDetails}}
<tr>
<td>{{spaces ../Level}}{{ts Start}}</td><td>{{duration .}}</td>
<td>{{../PID}}</td><td>{{FromAddr}}:{{FromPort}}</td>
<td>{{ToAddr}}:{{ToPort}}</td><td>{{count ../.}}</tr>
{{/with}}
{{else}}
{{#with ClientDetails}}
{{#with ServerDetails}}
<tr>
<td>{{spaces ../Level}}{{ts Start}}</td><td>{{duration .}}</td>
<td>{{../PID}}</td><td>{{FromAddr}}:{{FromPort}}</td>