Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API returns nothing when I want container's stats #16078

Closed
GabMgt opened this issue Sep 4, 2015 · 3 comments
Closed

API returns nothing when I want container's stats #16078

GabMgt opened this issue Sep 4, 2015 · 3 comments

Comments

@GabMgt
Copy link

GabMgt commented Sep 4, 2015

Hello, I have a problem with the Docker API, but first:

$ docker version
Client:
 Version:      1.8.2-rc1
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   28220ac
 Built:        Thu Sep  3 19:07:51 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.2-rc1
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   28220ac
 Built:        Thu Sep  3 19:07:51 UTC 2015
 OS/Arch:      linux/amd64

$ docker info   
Containers: 17
Images: 8
Storage Driver: devicemapper
 Pool Name: docker-254:0-1512633-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 3.557 GB
 Data Space Total: 107.4 GB
 Data Space Available: 8.216 GB
 Metadata Space Used: 7.848 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.14 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.104 (2015-08-10)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.1.0-1-amd64
Operating System: Debian GNU/Linux stretch/sid
CPUs: 8
Total Memory: 15.65 GiB
Name: n-pc
ID: LWBS:FFUU:5FGD:UXXH:J5FB:G4WL:WUZM:RFS4:3TEC:3IGG:K7GU:YWBV
WARNING: No memory limit support
WARNING: No swap limit support

$ uname -a
Linux n-pc 4.1.0-1-amd64 #1 SMP Debian 4.1.3-1 (2015-08-03) x86_64 GNU/Linux

I am using the API with command line, and when I want to get a container's stats, the API returns nothing:

$ echo -e "GET /containers/57d3/stats?stream=0 HTTP/1.1\r\n" | nc -U /var/run/docker.sock 
HTTP/1.1 200 OK
Content-Type: application/json
Server: Docker/1.8.2-rc1 (linux)
Date: Fri, 04 Sep 2015 08:13:10 GMT
Content-Length: 0

With the "docker" command I can get the stats, but I really need to use the API:

docker stats --no-stream 57d3
CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
57d3                 1.16%               0 B/16.81 GB        0.00%               8.565 MB/1.499 MB

However the API is working...

echo -e "GET /version HTTP/1.1\r\n" | nc -U /var/run/docker.sock | tail -1 | json
{
    "ApiVersion": "1.20",
    "Arch": "amd64",
    "BuildTime": "Thu Sep  3 19:07:51 UTC 2015",
    "GitCommit": "28220ac",
    "GoVersion": "go1.4.2",
    "KernelVersion": "4.1.0-1-amd64",
    "Os": "linux",
    "Version": "1.8.2-rc1"
}

What am I doing wrong please? Thank you!

@cpuguy83
Copy link
Member

cpuguy83 commented Sep 4, 2015

This is likely happening because docker is sending the response header first...
Note that I cannot repro this with curl, only with piping to nc as you have here.
Also the CLI uses the same exact API.

@duglin
Copy link
Contributor

duglin commented Sep 8, 2015

I think this is an 'nc' issue. Try: ... nc -q -1 -U /var/run/docker.sock (note the "-q -1").

I believe 'nc' is closing the http request before the server does its job and as a result we stop the 'stats' processing. If you try other docker cmds that don't check the http request you should see that it works.

Gonna close this because its not really a docker issue as much as an nc issue. Can you use curl instead?

@duglin duglin closed this as completed Sep 8, 2015
@GabMgt
Copy link
Author

GabMgt commented Sep 9, 2015

Thank you, it works! but i prefer to set -q to 5 (because -1 is for waiting forever) and 5 will set a timeout to 5 seconds.

I can use curl instead on Debian Stretch but not in Ubuntu 14.04 because: curl: option --unix-socket: is unknown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants