推荐阅读:
[AI-人工智能]免翻墙的AI利器:樱桃茶·智域GPT,让你轻松使用ChatGPT和Midjourney - 免费AIGC工具 - 拼车/合租账号 八折优惠码: AIGCJOEDISCOUNT2024
[AI-人工智能]银河录像局: 国内可靠的AI工具与流媒体的合租平台 高效省钱、现号秒发、翻车赔偿、无限续费|95折优惠码: AIGCJOE
[AI-人工智能]免梯免翻墙-ChatGPT拼车站月卡 | 可用GPT4/GPT4o/o1-preview | 会话隔离 | 全网最低价独享体验ChatGPT/Claude会员服务
[AI-人工智能]边界AICHAT - 超级永久终身会员激活 史诗级神器,口碑炸裂!300万人都在用的AI平台
在Ubuntu系统中,通过配置Prometheus监控系统,可以有效监控系统的健康状况。本文详细介绍了如何在Ubuntu Mesa环境下安装和配置Prometheus,包括必要的依赖和配置文件的修改,实现了对系统资源的实时监控。通过实践,展示了Ubuntu与Prometheus的紧密结合,为系统管理员提供了高效的管理工具。
本文目录导读:
Prometheus 是一款开源的监控系统,广泛应用于各种规模的 IT 基础设施中,它具有强大的数据采集、处理、展示和告警功能,可以帮助运维人员实时监控系统的运行状态,本文将详细介绍如何在 Ubuntu 系统下安装和配置 Prometheus,以及如何使用它进行监控系统性能。
安装 Prometheus
1、安装依赖
在安装 Prometheus 之前,需要先安装一些依赖软件,打开终端,执行以下命令:
sudo apt-get update sudo apt-get install -y git build-essential libsnappy-dev libcurl4-openssl-dev
2、下载 Prometheus 源码
从 Prometheus 的 GitHub 仓库下载源码:
git clone https://github.com/prometheus/prometheus.git cd prometheus
3、编译 Prometheus
在源码目录下执行以下命令进行编译:
make build
编译完成后,会在prometheus/build
目录下生成prometheus
和promtool
两个可执行文件。
4、将 Prometheus 移动到系统路径
将编译好的 Prometheus 移动到/usr/local/bin
目录下:
sudo mv prometheus/build/prometheus /usr/local/bin/ sudo mv prometheus/build/promtool /usr/local/bin/
5、创建 Prometheus 数据存储目录
创建一个用于存储 Prometheus 数据的目录:
sudo mkdir /var/lib/prometheus sudo chown -R prometheus:prometheus /var/lib/prometheus
6、创建 Prometheus 配置文件
在/etc
目录下创建一个名为prometheus.yml
的配置文件:
sudo touch /etc/prometheus.yml sudo chown prometheus:prometheus /etc/prometheus.yml
7、配置 Prometheus 服务
在/etc/systemd/system
目录下创建一个名为prometheus.service
的服务文件:
sudo touch /etc/systemd/system/prometheus.service sudo chown prometheus:prometheus /etc/systemd/system/prometheus.service
编辑prometheus.service
文件,输入以下内容:
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus --config.file /etc/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
8、启动 Prometheus 服务
启动 Prometheus 服务并设置为开机自启:
sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus
配置 Prometheus
1、配置数据源
在prometheus.yml
文件中添加数据源配置,监控本地机器的 CPU、内存、磁盘等信息:
global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node-exporter' static_configs: - targets: ['localhost:9100']
node-exporter
是一个用于收集系统性能数据的工具,需要在目标机器上安装。
2、配置告警规则
在prometheus.yml
文件中添加告警规则配置,设置 CPU 使用率超过 90% 时发送告警:
alerting: alertmanagers: - static_configs: - targets: - 'localhost:9093' rule_files: - 'alerting_rules.yml'
在alerting_rules.yml
文件中添加以下内容:
groups: - name: example rules: - alert: HighCPUUsage expr: 100 * (1 - avg(rate(container_cpu_usage_seconds_total{job="node-exporter", image!="", container!="POD"}[5m])) by (instance)) for: 1m labels: severity: critical annotations: summary: "Instance {{ $labels.instance }} CPU usage high" description: "Instance {{ $labels.instance }} CPU usage is above 90% (current value is {{ $value }}%)"
3、重新加载 Prometheus 配置
修改完配置文件后,使用以下命令重新加载 Prometheus 配置:
sudo systemctl restart prometheus
使用 Prometheus
1、访问 Prometheus Web 界面
在浏览器中输入http://localhost:9090
,即可访问 Prometheus 的 Web 界面,在界面上可以查看监控数据、设置告警规则等。
2、查看监控数据
在 Prometheus Web 界面左侧的“Targets”菜单中,可以查看已添加的数据源,点击数据源,可以查看该数据源的具体监控数据。
3、查看告警信息
在 Prometheus Web 界面左侧的“Alerts”菜单中,可以查看当前的告警信息。
本文详细介绍了在 Ubuntu 系统下安装和配置 Prometheus 监控系统的过程,通过 Prometheus,我们可以实时监控系统的运行状态,及时发现并处理潜在的问题,提高系统的稳定性和可靠性。
关键词:Ubuntu, Prometheus, 监控系统, 配置, 安装, 数据源, 告警规则, Web 界面, 性能监控, 系统稳定性, 运维工具, 开源软件, 数据采集, 数据处理, 数据展示, 告警功能, 系统监控, 实时监控, 性能分析, 服务器监控, 应用监控, 网络监控, 虚拟化监控, 容器监控, 数据库监控, 日志监控, 资源监控, 系统安全, 故障排查, 性能优化, 监控工具, 监控平台, 监控解决方案, 监控技术, 监控体系, 监控策略, 监控场景, 监控应用, 监控效果, 监控价值
本文标签属性:
Ubuntu Prometheus 配置:ubuntu prime-select