【云原生】Docker容器命令监控+Prometheus监控平台

简介: 【云原生】Docker容器命令监控+Prometheus监控平台

1.常用命令监控

docker ps
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS          PORTS     NAMES
30d9a0e764a3   busybox   "sh"      12 seconds ago   Up 11 seconds             busybox2
0d44a42e10dc   busybox   "sh"      17 seconds ago   Up 15 seconds             busybox1

字段含义

container id:容器的ID

images:基于创建的镜像

command:当前运行环境使用的进程

created:创建的时间

status:运行的时间

ports:映射的端口

names:容器的名称

docker top

查看指定容器内的进程

[root@localhost ~]# docker top busybox1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                2335                2314                0                   11:16               pts/0               00:00:00            sh

选项

与在Linux中运行的ps选项相同

a  显示现行终端机下的所有进程,包括其他用户的进程。

u  以用户为主的格式来显示进程状况。

x  显示所有进程,不以终端机来区分。


-A  显示所有进程。

-e  此参数的效果和指定"A"参数相同。

-f  显示UID,PPID,C与STIME栏位。

查看详细docker容器进程

[root@localhost ~]# docker top busybox1 aux
USER                PID                 %CPU                %MEM                VSZ                 RSS                 TTY                 STAT                START               TIME                COMMAND
root                2335                0.0                 0.0                 1320                252                 pts/0               Ss+                 11:16               0:00                sh
docker stats

动态显示容器的运行进程

查看所有容器的进程信息

[root@localhost ~]# docker stats
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O     PIDS
30d9a0e764a3   busybox2   0.00%     56KiB / 3.686GiB    0.00%     648B / 0B     0B / 0B       1
0d44a42e10dc   busybox1   0.00%     56KiB / 3.686GiB    0.00%     1.09kB / 0B   1.18MB / 0B   1

查看容器的动态进程

[root@localhost ~]# docker stats busybox1
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O     PIDS
0d44a42e10dc   busybox1   0.00%     56KiB / 3.686GiB    0.00%     1.09kB / 0B   1.18MB / 0B   1

字段含义

container id:容器id

name:容器名字

CPU %:CPU使用百分比

MEM USAGE/limit:容器使用的总内存,以及它允许使用的总内存

mem%:内存使用百分比

net I/O:容器通过其网络接口接收和发送的数据量

block I/O:容器从主机上的块设备写入和读取的数据量

pids:容器已经创建的进程或线程的数量

选项

-a:显示所有容器(默认显示正在运行)

--no-stream:禁用流统计,只拉取第一个结果

--no-trunc:不截断输出

2.weave scope

weave scope 的最大的特点就是会自动生成一张docker容器地图,让我们能够直观的理解,监控和控制器。

1.下载

wget https://github.com/weaveworks/scope/releases/download/v1.13.2/scope

2.安装
[root@localhost ~]# chmod +x scope 
[root@localhost ~]# ./scope launch
Unable to find image 'weaveworks/scope:1.13.2' locally
1.13.2: Pulling from weaveworks/scope
ba3557a56b15: Pull complete 
3ac4c0e9800c: Pull complete 
d052e74a4dae: Pull complete 
aacb9bf49f73: Pull complete 
06841e6f61a9: Pull complete 
ee99b95c7732: Pull complete 
dd0e726a9a15: Pull complete 
05cb5f9d0d32: Pull complete 
e956cf3e716a: Pull complete 
Digest: sha256:8591bb11d72f784f784ac8414660759d40b7c0d8819011660c1cc94271480a83
Status: Downloaded newer image for weaveworks/scope:1.13.2
458ddccb286a03b96e523e41d149ee102f6007cd55b4be179334675e5e7c311e
Scope probe started
Weave Scope is listening at the following URL(s):
  * http://192.168.2.5:4040/
3.访问查询即可

http://192.168.2.5:4040/

 

3.Prometheus监控平台

1.部署数据收集器cadvisor

[root@localhost ~]# docker run -v /:/rootfs:ro -v /var/run/:/var/run/:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 8080:8080 -d --name cadivsor google/cadvisor


访问:http://192.168.2.5:8080/containers/

2.部署Prometheus
[root@localhost ~]# docker run -d -p 9100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
--net=host \
prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/devicemapper|rootfs/var/lib/docker/aufs)($$|/)"
Unable to find image 'prom/node-exporter:latest' locally
latest: Pulling from prom/node-exporter
aa2a8d90b84c: Pull complete 
b45d31ee2d7f: Pull complete 
b5db1e299295: Pull complete 
Digest: sha256:f2269e73124dd0f60a7d19a2ce1264d33d08a985aed0ee6b0b89d0be470592cd
Status: Downloaded newer image for prom/node-exporter:latest
WARNING: Published ports are discarded when using host network mode
795214fa2248b18fee6e6600bb567493db4be265b5c79c9445eb96020aab3578

编写Prometheus监控配置文件

[root@localhost ~]# vi prometheus.yml
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090','localhost:8080','localhost:9100']

主要配置文件内容

static_configs:

   - targets: ['localhost:9090','localhost:8080','localhost:9100']

注意:填写你需要监控的cadvisor的IP地址和端口号

3.部署可视化平台Gragana
[root@localhost ~]# docker run -d -i -p 3000:3000 \
-e "GF_SERVER_ROOT_URL=http://grafana.server.name"  \
-e "GF_SECURITY_ADMIN_PASSWORD=secret"  \
--net=host \
grafana/grafana
4.进入后台控制台

http://192.168.2.5:3000/

默认用户名和密码

admin

密码:GF_SECURITY_ADMIN_PASSWORD=secret字段内容

注意:如果不指定密码为admin

1.添加Prometheus模块

2.添加docker容器监控模板

docker容器模板:193

Linux主机监控模板:9276

监控结果

 

目录
相关文章
|
12月前
|
Prometheus 监控 Cloud Native
云原生监控实战:Prometheus+Grafana快速搭建指南
云原生监控实战:Prometheus+Grafana快速搭建指南
|
9月前
|
Prometheus 监控 Cloud Native
基于docker搭建监控系统&日志收集
Prometheus 是一款由 SoundCloud 开发的开源监控报警系统及时序数据库(TSDB),支持多维数据模型和灵活查询语言,适用于大规模集群监控。它通过 HTTP 拉取数据,支持服务发现、多种图表展示(如 Grafana),并可结合 Loki 实现日志聚合。本文介绍其架构、部署及与 Docker 集成的监控方案。
838 122
基于docker搭建监控系统&日志收集
|
12月前
|
存储 Prometheus 监控
OSS监控体系搭建:Prometheus+Grafana实时监控流量、错误码、存储量(开源方案替代云监控自定义视图)
本方案基于Prometheus构建OSS监控系统,涵盖架构设计、指标采集、可视化、告警及性能优化,助力企业实现高可用、低成本的自建监控体系。
1079 1
|
11月前
|
Cloud Native 中间件 调度
云原生信息提取系统:容器化流程与CI/CD集成实践
本文介绍如何通过工程化手段解决数据提取任务中的稳定性与部署难题。结合 Scrapy、Docker、代理中间件与 CI/CD 工具,构建可自动运行、持续迭代的云原生信息提取系统,实现结构化数据采集与标准化交付。
1214 1
云原生信息提取系统:容器化流程与CI/CD集成实践
|
12月前
|
存储 监控 Cloud Native
云原生监控实战:Prometheus+Grafana打造RDS多维度预警体系
本方案构建了基于Prometheus与Thanos的云原生RDS监控体系,涵盖数据采集、存储、可视化与告警全流程。支持10万+QPS采集、90%存储压缩,具备&lt;30秒告警延迟能力。通过自定义指标与智能预警策略,显著提升故障发现效率,实现分钟级响应。
776 5
|
11月前
|
Prometheus 监控 Cloud Native
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务实现步骤
921 0
|
Linux Docker 容器
Docker操作 :容器命令
Docker操作 (四)
471 56

热门文章

最新文章