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

目录

1.常用命令监控

[docker ps](#docker ps)

[docker top](#docker top)

[docker stats](#docker stats)

[2.weave scope](#2.weave scope)

1.下载

2.安装

3.访问查询即可

3.Prometheus监控平台

1.部署数据收集器cadvisor

2.部署Prometheus

3.部署可视化平台Gragana

4.进入后台控制台


1.常用命令监控

docker ps

bash 复制代码
[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

查看指定容器内的进程

bash 复制代码
[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容器进程

bash 复制代码
[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

动态显示容器的运行进程

查看所有容器的进程信息

bash 复制代码
[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

查看容器的动态进程

bash 复制代码
[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.安装

bash 复制代码
[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

bash 复制代码
[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监控配置文件

bash 复制代码
[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

bash 复制代码
[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

监控结果

相关推荐
糟糕喔38 分钟前
harbor私有仓库搭建
运维·docker·云原生·容器·kubernetes
05大叔3 小时前
微服务,拆分原则,远程调用,服务治理,OpenFeign
微服务·云原生·架构
就叫飞六吧5 小时前
K8s 端口暴露:集群统一暴露 vs 单 Pod 暴露
云原生·容器·kubernetes
returnthem9 小时前
Docker学习笔记
云原生·eureka
岁岁种桃花儿10 小时前
kubenetes从入门到上天系列第十五篇:Kubernetes的持久化存储PC和PVC
云原生·容器·kubernetes
数据知道10 小时前
云原生MongoDB:容器化部署与Kubernetes集成详细步骤
mongodb·云原生·kubernetes
还在忙碌的吴小二20 小时前
k8s是啥?
云原生·容器·kubernetes
zhen241 天前
K8s Service
云原生·容器·kubernetes
sbjdhjd1 天前
RHCE | Web 服务器与 Nginx 全栈详解
linux·nginx·http·云原生·oracle·架构·web
qhqh3101 天前
K8S的PV、PVC和storageClass的相关概念及实验
云原生·容器·kubernetes