Docker Container 介紹
Docker Container( Docker 容器)是一種輕量級、可移植的、自給自足的軟件運行環境,它在 Docker 引擎的宿主機上運行。容器在許多方面類似于虛擬機,但它們更輕量,因為它們不需要模擬整個操作系統。相反,容器共享宿主機的操作系統內核,并在用戶空間中運行。
Docker 容器可觀測對于確保容器化應用程序的性能、穩定性和可用性至關重要,本文主要以純 Docker 環境下(非K8S ),構建 Container 的可觀測性。
觀測云
使用觀測云可以輕松采集到容器的 cpu 、內存、網絡、IO 等核心指標,并自動采集容器的標準輸出日志,使用觀測云可以有效地監控和管理容器化應用程序,一鍵實現容器可觀測。
部署 DataKit
登錄觀測云,點擊集成按鈕,選擇 DataKit,會自動生成安裝 DataKit 命令。
DataKit 安裝完成后,默認開啟了 container 采集器,container 采集器主要采集 K8S 和 docker 容器的指標、日志等信息。執行命令 datakit monitor 可以數據查看采集情況,在 Inputs Info 中 logging/xxx 表明正在采集當前 xxx 容器的日志,container-mertic 表明正在采集容器的指標。
關鍵指標
- docker_containers
Metric | Description | Type | Unit |
---|---|---|---|
block_read_byte | Total number of bytes read from the container file system (only supported docker). | int | B |
block_write_byte | Total number of bytes wrote to the container file system (only supported docker). | int | B |
cpu_numbers | The number of the CPU core. | int | count |
cpu_usage | The percentage usage of CPU on system host. | float | percent |
cpu_usage_base100 | The normalized cpu usage, with a maximum of 100%. | float | percent |
mem_capacity | The total memory in the host machine. | int | B |
mem_limit | The limit memory in the container. | int | B |
mem_usage | The usage of the memory. | int | B |
mem_used_percent | The percentage usage of the memory is calculated based on the capacity of host machine. | float | percent |
mem_used_percent_base_limit | The percentage usage of the memory is calculated based on the limit. | float | percent |
network_bytes_rcvd | Total number of bytes received from the network (only count the usage of the main process in the container, excluding loopback). | int | B |
network_bytes_sent | Total number of bytes send to the network (only count the usage of the main process in the container, excluding loopback). | int | B |
視圖
登錄觀測云控制臺,點擊「場景」 -「新建儀表板」,輸入 “docker” , 選擇 “Docker 監控視圖”,點擊 “確定” 即可添加內置視圖。
- 概覽
- CPU & 內存
- IO & Network
- 日志
監控器(告警)
容器重啟告警
容器啟動時間小于5分鐘,觸發容器重啟告警。
CPU 利用率告警
容器 cpu 使用率,基于宿主機總 cpu 百分比利用率進行判斷觸發告警。
內存利用率告警
容器內存使用率,基于容器內存限制(沒有設置容器內存限制按照主機最大內存計算)進行判斷觸發告警。
監控效果
- 重啟告警
- 監控自動恢復
總結
在觀測云的助力下,一鍵部署 Agent,自動采集 Docker 相關的日志、指標等數據, 在平臺一鍵開啟監控 Dashboard 和監控器,實時觀測容器運行情況,使容器可觀測性變的方便、快捷、高效。