我怎么能读取http流请求的第一个响应

时间:2015-07-17 08:03:03

标签: ruby docker

当我在ruby脚本中请求curl http://localhost:7788/containers/sampe/stats时。

它将获得每秒接收数据的http流。该请求不会被断开。

在使用Ruby

获取JSON格式的第一个响应后,如何断开请求
{"read":"2015-07-17T15:47:20.253706054+08:00","network":{"rx_bytes":1526,"rx_packets":19,"rx_errors":0,"rx_dropped":0,"tx_bytes":738,"tx_packets":9,"tx_errors":0,"tx_dropped":0},"precpu_stats":{"cpu_usage":{"total_usage":0,"percpu_usage":null,"usage_in_kernelmode":0,"usage_in_usermode":0},"system_cpu_usage":0,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"cpu_stats":{"cpu_usage":{"total_usage":1024776164,"percpu_usage":[180823377,321637272,276090785,246224730],"usage_in_kernelmode":240000000,"usage_in_usermode":560000000},"system_cpu_usage":19962290000000,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":90214400,"max_usage":90451968,"stats":{"active_anon":34742272,"active_file":9658368,"cache":55472128,"hierarchical_memory_limit":1073741824,"inactive_anon":0,"inactive_file":45813760,"mapped_file":30703616,"pgfault":12415,"pgmajfault":286,"pgpgin":23508,"pgpgout":1483,"rss":34742272,"rss_huge":0,"total_active_anon":34742272,"total_active_file":9658368,"total_cache":55472128,"total_inactive_anon":0,"total_inactive_file":45813760,"total_mapped_file":30703616,"total_pgfault":12415,"total_pgmajfault":286,"total_pgpgin":23508,"total_pgpgout":1483,"total_rss":34742272,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"failcnt":0,"limit":1073741824},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]}}

{"read":"2015-07-17T15:47:20.253706054+08:00","network":{"rx_bytes":1526,"rx_packets":19,"rx_errors":0,"rx_dropped":0,"tx_bytes":738,"tx_packets":9,"tx_errors":0,"tx_dropped":0},"precpu_stats":{"cpu_usage":{"total_usage":0,"percpu_usage":null,"usage_in_kernelmode":0,"usage_in_usermode":0},"system_cpu_usage":0,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"cpu_stats":{"cpu_usage":{"total_usage":1024776164,"percpu_usage":[180823377,321637272,276090785,246224730],"usage_in_kernelmode":240000000,"usage_in_usermode":560000000},"system_cpu_usage":19962290000000,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":90214400,"max_usage":90451968,"stats":{"active_anon":34742272,"active_file":9658368,"cache":55472128,"hierarchical_memory_limit":1073741824,"inactive_anon":0,"inactive_file":45813760,"mapped_file":30703616,"pgfault":12415,"pgmajfault":286,"pgpgin":23508,"pgpgout":1483,"rss":34742272,"rss_huge":0,"total_active_anon":34742272,"total_active_file":9658368,"total_cache":55472128,"total_inactive_anon":0,"total_inactive_file":45813760,"total_mapped_file":30703616,"total_pgfault":12415,"total_pgmajfault":286,"total_pgpgin":23508,"total_pgpgout":1483,"total_rss":34742272,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"failcnt":0,"limit":1073741824},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]}}

1 个答案:

答案 0 :(得分:1)

根据Docker Remote API,您可以请求curl http://localhost:7788/containers/sampe/stats?stream=0然后它只会提取一个结果并断开连接。