当前位置: 首页 > news >正文

构建Docker容器监控系统(Cadvisor +Prometheus+Grafana)

Cadvisor +Prometheus+Grafana

1.1、Cadvisor产品简介

        Cadvisor是Google开源的一款用于展示和分析容器运行状态的可视化工具。通过在主机上运行Cadvisor用户可以轻松的获取到当前主机上容器的运行统计信息,并以图表的形式向用户展示。

1.2、安装docker-ce

[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# docker versionClient: Docker Engine - CommunityVersion:           24.0.5API version:       1.43Go version:        go1.20.6Git commit:        ced0996Built:             Fri Jul 21 20:39:02 2023OS/Arch:           linux/amd64Context:           defaultServer: Docker Engine - CommunityEngine:Version:          24.0.5API version:      1.43 (minimum version 1.12)Go version:       go1.20.6Git commit:       a61e2b4Built:            Fri Jul 21 20:38:05 2023OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.6.21GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8runc:Version:          1.1.7GitCommit:        v1.1.7-0-g860f061docker-init:Version:          0.19.0GitCommit:        de40ad0

阿里云镜像加速器

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台欢迎登录阿里云,全球领先的云计算及人工智能科技公司,阿里云为200多个国家和地区的企业、开发者和政府机构提供云计算基础服务及解决方案。阿里云云计算、安全、大数据、人工智能、企业应用、物联网等云计算服务。https://cr.console.aliyun.com/

[root@localhost ~]# cat << END > /etc/docker/daemon.json
{"registry-mirrors":[ "https://nyakyfun.mirror.aliyuncs.com" ]
}
END[root@localhost ~]# systemctl daemon-reload[root@localhost ~]# systemctl restart docker

 下载组件镜像

[root@localhost ~]# docker pull tutum/influxdbUsing default tag: latest
latest: Pulling from tutum/influxdb
a3ed95caeb02: Pull complete 
23efb549476f: Pull complete 
aa2f8df21433: Pull complete 
ef072d3c9b41: Pull complete 
c9f371853f28: Pull complete 
a248b0871c3c: Pull complete 
749db6d368d0: Pull complete 
db2492acfcc3: Pull complete 
b7e7d2e12d53: Pull complete 
4272a53eef10: Pull complete 
9b2fefdb5321: Pull complete 
Digest: sha256:5b7c5e318303ad059f3d1a73d084c12cb39ae4f35f7391b79b0ff2c0ba45304b
Status: Downloaded newer image for tutum/influxdb:latest
docker.io/tutum/influxdb:latest[root@localhost ~]# docker pull google/cadvisorUsing default tag: latest
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete 
44a45bb65cdf: Pull complete 
0bbe1a2fe2a6: Pull complete 
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
docker.io/google/cadvisor:latest[root@localhost ~]# docker pull grafana/grafanaUsing default tag: latest
latest: Pulling from grafana/grafana
97518928ae5f: Pull complete 
5b58818b7f48: Pull complete 
d9a64d9fd162: Pull complete 
4e368e1b924c: Pull complete 
867f7fdd92d9: Pull complete 
387c55415012: Pull complete 
07f94c8f51cd: Pull complete 
ce8cf00ff6aa: Pull complete 
e44858b5f948: Pull complete 
4000fdbdd2a3: Pull complete 
Digest: sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062
Status: Downloaded newer image for grafana/grafana:latest
docker.io/grafana/grafana:latest[root@localhost ~]# docker imagesREPOSITORY        TAG       IMAGE ID       CREATED         SIZE
grafana/grafana   latest    9b957e098315   20 months ago   275MB
google/cadvisor   latest    eb1210707573   4 years ago     69.6MB
tutum/influxdb    latest    c061e5808198   6 years ago     290MB

 创建自定义网络


[root@localhost ~]# docker network create monitorbfe09a56d338b3173da008204dac13e46873ab8c46601683bba6457178e7dbcc[root@localhost ~]# docker network lsNETWORK ID     NAME      DRIVER    SCOPE
dbe5fb2353e8   bridge    bridge    local
fc4521838733   host      host      local
bfe09a56d338   monitor   bridge    local
4e2c57eec484   none      null      local

 

1.3、部署Cadvisor

被监控主机上部署Cadvisor容器

[root@localhost ~]# docker run -d \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:ro \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --volume=/dev/disk/:/dev/disk:ro \
> --publish=8080:8080 \
> --detach=true \
> --name=cadvisor \
> google/cadvisor:latest39067a18d264733e884272d932cd1d2bf1ae279092729aca01cfc0f12fa2571d

1.4访问cAdvisor页面

访问http://192.168.2.118:8080 cAdvisor页面可以看到收集到的数据

 

 

1.5Prometheus产品简介

        Prometheus是一个最初在SoundCloud上构建的开源系统监视和警报工具包。自2012年成立以来,很多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发者和用户社区。 它现在是一个独立的开源项目,可以独立于任何公司进行维护。 为了强调这一点,并阐明项目的治理结构,Prometheus于2016年加入Cloud Native Computing Foundation(云原生基金会),作为继Kubernetes之后的第二个托管项目。

Prometheus的主要特征有:

  • 多维度数据模型-由指标键值对标识的时间序列数据组成
  • PromQL,一种灵活的查询语言
  • 不依赖分布式存储; 单个服务器节点是自治的
  • 以HTTP方式,通过pull模型拉取时间序列数据
  • 支持通过中间网关推送时间序列数据
  • 通过服务发现或者静态配置,来发现目标服务对象
  • 支持多种多样的图表和界面展示

1.6、部署Prometheus 

[root@localhost ~]# docker pull prom/prometheusUsing default tag: latest
latest: Pulling from prom/prometheus
3cb635b06aa2: Pull complete 
34f699df6fe0: Pull complete 
33d6c9635e0f: Pull complete 
f2af7323bed8: Pull complete 
c16675a6a294: Pull complete 
827843f6afe6: Pull complete 
3d272942eeaf: Pull complete 
7e785cfa34da: Pull complete 
05e324559e3b: Pull complete 
170620261a59: Pull complete 
ec35f5996032: Pull complete 
5509173eb708: Pull complete 
Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb
Status: Downloaded newer image for prom/prometheus:latest
docker.io/prom/prometheus:latest

先准备配置

[root@localhost ~]# vim /tmp/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']- job_name: 'docker'      ##定义一个叫docker的组static_configs:
- targets: ['192.168.2.118:8080']   ##填写一个或多个cadvisor的主机地址用逗号隔开

运行容器

[root@localhost ~]# docker run -d \
--name=prometheus  -p 9090:9090  \
-v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \-v /etc/localtime:/etc/localtime \
prom/prometheus402b019bb5fd489911f925ae717e87994e68ec7b836f37bc106de8f3c2801cbc#如果起不来就重启一下docker,再用docker restart $(docker ps -qa) 重启所有容器

1.7访问prometheus页面

http://192.168.2.118:9090

 

 

 

看到docker组状态up为正常

查询项是可以查到数据的

 1.8、部署Granfana

[root@localhost ~]# docker run -d \
> --name=grafana \
>  -p 3000:3000 \
> grafana/grafana42b131dbf96ac1b613c6b8ac305c94eb322b8cf6b320f48990ad059bba5ba0d6

1.9配置Granfana

访问http://192.168.2.118:3000默认账户admin 密码 admin首次登陆需要修改密码

 

 配置数据源

 

 

 

 

 

 导入模板

 

 选择对应的数据源,点击导入,就可以看到被监控主机的数据

 准备测试容器

[root@localhost ~]# docker run --name=nginx -d -p 80:80 nginx
d2000b50c5a035fde255c5f488fde43653733806a36167c4b73460a0c74d27f6

 

 

 到此Cadvisor +Prometheus+Grafana基本架构部署完毕

相关文章:

构建Docker容器监控系统(Cadvisor +Prometheus+Grafana)

Cadvisor PrometheusGrafana 1.1、Cadvisor产品简介 Cadvisor是Google开源的一款用于展示和分析容器运行状态的可视化工具。通过在主机上运行Cadvisor用户可以轻松的获取到当前主机上容器的运行统计信息&#xff0c;并以图表的形式向用户展示。 1.2、安装docker-ce [rootloc…...

java实现文件的下载

系统日志的获取不可能每次都登录服务器&#xff0c;所以在页面上能够下载系统运行的日志是必须的 如何来实现日志的下载&#xff0c;这样的一个功能 前端我们用到的是window.open(...)这样可以发送一个get请求到后台 后台接收到get请求之后&#xff0c;如何实现对文件的下载 R…...

分享Python技术下AutojsPro7云控代码

引言 有图有真相&#xff0c;那短视频就更是真相了。下面是三大语言的短视频。 Java源码版云控示例&#xff1a; Java源码版云控示例在线视频 Net源码版云控示例&#xff1a; Net源码版云控示例在线视频亚丁号-知识付费平台 支付后可见 扫码付费可见 Python源码版云控示例…...

【Linux】网络通信

【Linux】网络通信 文章目录 【Linux】网络通信1、网络基础1.1 计算机网络1.2 网络模型TCP & UDP1&#xff09;IP地址2&#xff09;端口3&#xff09;TCP协议与UDP协议的比较 1.3 网络传输1.3.1 传输逻辑1.3.2 传输条件1.3.3 传输流程 1.4 地址管理 2、网络编程2.1 基本概念…...

【mysql】—— 表的约束

目录 序言 &#xff08;一&#xff09;空属性 &#xff08;二&#xff09;默认值 &#xff08;三&#xff09;列描述 &#xff08;四&#xff09;zerofill &#xff08;五&#xff09;主键 &#xff08;六&#xff09;自增长 &#xff08;七&#xff09;唯一键 &#…...

jeecgboot 登录成功默认其他路由

util.js...

【1572. 矩阵对角线元素的和】

来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 描述&#xff1a; 给你一个正方形矩阵 mat&#xff0c;请你返回矩阵对角线元素的和。 请你返回在矩阵主对角线上的元素和副对角线上且不在主对角线上元素的和。 示例 1&#xff1a; 输入&#xff1a;mat [[1,2,3]…...

GaussDB 开发篇+Java调用JDBC访问openGauss数据库

★ 数据库信息 ✔ 数据库版本&#xff1a;openGauss 5.0.0 ✔ 数据库端口&#xff1a;5432 ✔ 数据库名称&#xff1a;db_zzt ★ Java代码 package PAC_001;import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sq…...

钕铁硼永磁材料基本概念

目录 一、何为磁性材料二、永磁材料的主要性能三、永磁材料的历史四、永磁材料的分类五、钕铁硼永磁材料5.1 产业链5.2 生产工艺 之前也写过其他行业的一些生产过程和工艺流程&#xff0c;大家有兴趣的可以翻翻以前的文章。 一、何为磁性材料 参加过九年义务教育的同学应该都知…...

2005-2020年280个地级市绿色全要素生产率测算原始数据

2005-2020年280个地级市绿色全要素生产率测算原始数据 1、时间&#xff1a;2005-2020年 2、来源&#xff1a;中国城市统计年鉴、中国区域统计年鉴、中国能源年鉴、中国环境年鉴等 3、范围&#xff1a;280个地级市 4、指标&#xff1a;年末单位从业人员数、规模以上工业企业…...

电流的测量(反馈电流表)

另一方面&#xff0c;反馈电流表使用不同的方法来产生电流测量&#xff08;见图 3&#xff09;。他们使用有源跨阻放大器将电流转换为电压读数。电压输出是电流输入的倒数乘以反馈电阻器 R F的值。 V输出 -I输入* R F 图 3. 反馈电流表方法使用有源跨阻放大器将电流转换为…...

白帽黑帽与linux安全操作

目录 白帽黑帽 Linux安全 白帽黑帽 白帽&#xff08;White Hat&#xff09;和黑帽&#xff08;Black Hat&#xff09;通常用于描述计算机安全领域中的两种不同角色。白帽黑客通常被认为是合法的安全专家&#xff0c;他们通过合法途径寻找和修复安全漏洞&#xff0c;帮助企业和…...

【TypeScript】进阶之路语法细节,类型和函数

进阶之路 类型别名(type)的使用接口(interface)的声明的使用二者区别&#xff1a; 联合类型和交叉类型联合类型交叉类型 类型断言获取DOM元素 非空类型断言字面量类型的使用类型缩小&#xff08;类型收窄&#xff09;TypeScript 函数类型函数类型表达式内部规则检测函数的调用签…...

每日一题 611有效三角形的个数(相向双指针)

题目 给定一个包含非负整数的数组 nums &#xff0c;返回其中可以组成三角形三条边的三元组个数。 示例 1: 输入: nums [2,2,3,4] 输出: 3 解释:有效的组合是: 2,3,4 (使用第一个 2) 2,3,4 (使用第二个 2) 2,2,3示例 2: 输入: nums [4,2,3,4] 输出: 4 题解 class Solu…...

Flink源码之JobMaster启动流程

Flink中Graph转换流程如下&#xff1a; Flink Job提交时各种类型Graph转换流程中&#xff0c;JobGraph是Client端形成StreamGraph后经过Operator Chain优化后形成的&#xff0c;然后提交给JobManager的Restserver&#xff0c;最终转发给JobManager的Dispatcher处理。 Completa…...

C#,数值计算——抛物线插值与Brent方法(Parabolic Interpolation and Brent‘s Method)的计算方法与源程序

using System; namespace Legalsoft.Truffer { /// <summary> /// 抛物线插值与Brent方法 /// Parabolic Interpolation and Brents Method /// </summary> public class Brent : Bracketmethod { public double xmin { get; set…...

基于Selenium技术方案的爬取界面内容实践

1. 定位页面&#xff08;多窗口切换&#xff09; WebDriver提供了处理多个窗口的能力&#xff0c;这是通过使用“WebDriver.switchTo.window()”方法来切换到已知名称的窗口来实现的。如果名称未知&#xff0c;您可以使用“WebDriver.getWindowHandles()”获取已知窗口列表。您…...

线程记录(1)

创建线程&#xff1a; 一、1.继承Thread&#xff0c;重写run()&#xff0c;将操作写入其中 2.创建子类对象&#xff0c;start() 二、1.实现runnable接口&#xff0c;实现run() 2.创建子类对象&#xff0c;将子类对象作为参数传递到thread的构造器中&#xff0c;创建出Thread类…...

requests

操作步骤 安装 requests 发送GET请求 发送POST请求 说明&#xff1a; data: 参数接收form表单数据&#xff0c;后台会⾃动附加form表单请求信息头&#xff08;data数据格式为字典&#xff09; json:参数接收json数据&#xff0c;后台会⾃动附加json表单请求信息头&…...

Python 监控 Windows 服务

Python 监控 Windows 服务 Python 在 Windows 系统上可以使用 wmi 模块来实现对 Windows 服务的监控。本文将介绍如何使用 Python 监控 Windows 服务&#xff0c;并实现服务状态的查询和服务启停功能。 安装依赖 在使用 wmi 模块之前&#xff0c;需要先安装 wmi包。可以使用…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

3.3.1_1 检错编码(奇偶校验码)

从这节课开始&#xff0c;我们会探讨数据链路层的差错控制功能&#xff0c;差错控制功能的主要目标是要发现并且解决一个帧内部的位错误&#xff0c;我们需要使用特殊的编码技术去发现帧内部的位错误&#xff0c;当我们发现位错误之后&#xff0c;通常来说有两种解决方案。第一…...

Java如何权衡是使用无序的数组还是有序的数组

在 Java 中,选择有序数组还是无序数组取决于具体场景的性能需求与操作特点。以下是关键权衡因素及决策指南: ⚖️ 核心权衡维度 维度有序数组无序数组查询性能二分查找 O(log n) ✅线性扫描 O(n) ❌插入/删除需移位维护顺序 O(n) ❌直接操作尾部 O(1) ✅内存开销与无序数组相…...

关于iview组件中使用 table , 绑定序号分页后序号从1开始的解决方案

问题描述&#xff1a;iview使用table 中type: "index",分页之后 &#xff0c;索引还是从1开始&#xff0c;试过绑定后台返回数据的id, 这种方法可行&#xff0c;就是后台返回数据的每个页面id都不完全是按照从1开始的升序&#xff0c;因此百度了下&#xff0c;找到了…...

vue3 字体颜色设置的多种方式

在Vue 3中设置字体颜色可以通过多种方式实现&#xff0c;这取决于你是想在组件内部直接设置&#xff0c;还是在CSS/SCSS/LESS等样式文件中定义。以下是几种常见的方法&#xff1a; 1. 内联样式 你可以直接在模板中使用style绑定来设置字体颜色。 <template><div :s…...

sqlserver 根据指定字符 解析拼接字符串

DECLARE LotNo NVARCHAR(50)A,B,C DECLARE xml XML ( SELECT <x> REPLACE(LotNo, ,, </x><x>) </x> ) DECLARE ErrorCode NVARCHAR(50) -- 提取 XML 中的值 SELECT value x.value(., VARCHAR(MAX))…...

Element Plus 表单(el-form)中关于正整数输入的校验规则

目录 1 单个正整数输入1.1 模板1.2 校验规则 2 两个正整数输入&#xff08;联动&#xff09;2.1 模板2.2 校验规则2.3 CSS 1 单个正整数输入 1.1 模板 <el-formref"formRef":model"formData":rules"formRules"label-width"150px"…...

Go 语言并发编程基础:无缓冲与有缓冲通道

在上一章节中&#xff0c;我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道&#xff0c;它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好&#xff0…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

【C++进阶篇】智能指针

C内存管理终极指南&#xff1a;智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...