1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #1505 from dotcloud/improve_events

Add image name in /events
This commit is contained in:
Michael Crosby 2013-08-14 15:40:36 -07:00
commit 15bc2240ac
5 changed files with 51 additions and 12 deletions

View file

@ -820,7 +820,7 @@ func (container *Container) monitor() {
}
utils.Debugf("Process finished")
if container.runtime != nil && container.runtime.srv != nil {
container.runtime.srv.LogEvent("die", container.ShortID())
container.runtime.srv.LogEvent("die", container.ShortID(), container.runtime.repositories.ImageName(container.Image))
}
exitCode := -1
if container.cmd != nil {

View file

@ -49,6 +49,10 @@ What's new
**New!** You can now use ps args with docker top, like `docker top <container_id> aux`
.. http:get:: /events:
**New!** Image's name added in the events
:doc:`docker_remote_api_v1.3`
*****************************

View file

@ -1095,6 +1095,37 @@ Create a new image from a container's changes
:statuscode 404: no such container
:statuscode 500: server error
Monitor Docker's events
***********************
.. http:get:: /events
Get events from docker, either in real time via streaming, or via polling (using `since`)
**Example request**:
.. sourcecode:: http
POST /events?since=1374067924
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: application/json
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
{"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
{"status":"stop","id":"dfdf82bd3881","from":"base:latest","time":1374067966}
{"status":"destroy","id":"dfdf82bd3881","from":"base:latest","time":1374067970}
:query since: timestamp used for polling
:statuscode 200: no error
:statuscode 500: server error
3. Going further
================

View file

@ -76,7 +76,7 @@ func (srv *Server) ContainerKill(name string) error {
if err := container.Kill(); err != nil {
return fmt.Errorf("Error killing container %s: %s", name, err)
}
srv.LogEvent("kill", name)
srv.LogEvent("kill", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
} else {
return fmt.Errorf("No such container: %s", name)
}
@ -95,7 +95,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
if _, err := io.Copy(out, data); err != nil {
return err
}
srv.LogEvent("export", name)
srv.LogEvent("export", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
return nil
}
return fmt.Errorf("No such container: %s", name)
@ -832,7 +832,7 @@ func (srv *Server) ContainerCreate(config *Config) (string, error) {
}
return "", err
}
srv.LogEvent("create", container.ShortID())
srv.LogEvent("create", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
return container.ShortID(), nil
}
@ -841,7 +841,7 @@ func (srv *Server) ContainerRestart(name string, t int) error {
if err := container.Restart(t); err != nil {
return fmt.Errorf("Error restarting container %s: %s", name, err)
}
srv.LogEvent("restart", name)
srv.LogEvent("restart", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
} else {
return fmt.Errorf("No such container: %s", name)
}
@ -861,7 +861,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error {
if err := srv.runtime.Destroy(container); err != nil {
return fmt.Errorf("Error destroying container %s: %s", name, err)
}
srv.LogEvent("destroy", name)
srv.LogEvent("destroy", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
if removeVolume {
// Retrieve all volumes from all remaining containers
@ -928,7 +928,7 @@ func (srv *Server) deleteImageAndChildren(id string, imgs *[]APIRmi) error {
return err
}
*imgs = append(*imgs, APIRmi{Deleted: utils.TruncateID(id)})
srv.LogEvent("delete", utils.TruncateID(id))
srv.LogEvent("delete", utils.TruncateID(id), "")
return nil
}
return nil
@ -975,7 +975,7 @@ func (srv *Server) deleteImage(img *Image, repoName, tag string) ([]APIRmi, erro
}
if tagDeleted {
imgs = append(imgs, APIRmi{Untagged: img.ShortID()})
srv.LogEvent("untag", img.ShortID())
srv.LogEvent("untag", img.ShortID(), "")
}
if len(srv.runtime.repositories.ByID()[img.ID]) == 0 {
if err := srv.deleteImageAndChildren(img.ID, &imgs); err != nil {
@ -1042,7 +1042,7 @@ func (srv *Server) ContainerStart(name string, hostConfig *HostConfig) error {
if err := container.Start(hostConfig); err != nil {
return fmt.Errorf("Error starting container %s: %s", name, err)
}
srv.LogEvent("start", name)
srv.LogEvent("start", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
} else {
return fmt.Errorf("No such container: %s", name)
}
@ -1054,7 +1054,7 @@ func (srv *Server) ContainerStop(name string, t int) error {
if err := container.Stop(t); err != nil {
return fmt.Errorf("Error stopping container %s: %s", name, err)
}
srv.LogEvent("stop", name)
srv.LogEvent("stop", container.ShortID(), srv.runtime.repositories.ImageName(container.Image))
} else {
return fmt.Errorf("No such container: %s", name)
}
@ -1222,9 +1222,9 @@ func (srv *Server) HTTPRequestFactory() *utils.HTTPRequestFactory {
return srv.reqFactory
}
func (srv *Server) LogEvent(action, id string) {
func (srv *Server) LogEvent(action, id, from string) {
now := time.Now().Unix()
jm := utils.JSONMessage{Status: action, ID: id, Time: now}
jm := utils.JSONMessage{Status: action, ID: id, From: from, Time: now}
srv.events = append(srv.events, jm)
for _, c := range srv.listeners {
select { // non blocking channel

View file

@ -622,6 +622,7 @@ type JSONMessage struct {
Progress string `json:"progress,omitempty"`
ErrorMessage string `json:"error,omitempty"` //deprecated
ID string `json:"id,omitempty"`
From string `json:"from,omitempty"`
Time int64 `json:"time,omitempty"`
Error *JSONError `json:"errorDetail,omitempty"`
}
@ -650,6 +651,9 @@ func (jm *JSONMessage) Display(out io.Writer) error {
if jm.ID != "" {
fmt.Fprintf(out, "%s: ", jm.ID)
}
if jm.From != "" {
fmt.Fprintf(out, "(from %s) ", jm.From)
}
if jm.Progress != "" {
fmt.Fprintf(out, "%c[2K", 27)
fmt.Fprintf(out, "%s %s\r", jm.Status, jm.Progress)