2023年最新prometheus + grafana搭建和使用

一、安装prometheus

1.1 安装

prometheus官网下载地址

sudo -i
mkdir -p /opt/prometheus
#移动解压后的文件名到/opt/,并改名prometheus
mv prometheus-2.45 /opt/prometheus/
#创建一个专门的prometheus用户: -M 不创建家目录, -s 不让登录
useradd -M -s /usr/sbin/nologin prometheus

##更改prometheus用户的文件夹权限:
chown prometheus:prometheus -R /opt/prometheus
1.2 修改配置
global:
  scrape_interval: 30s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 30s # Evaluate rules every 15 seconds. The default is every 1 minute.

# 其他全局配置...

scrape_configs:
  # Prometheus 自身的监控配置
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9070"]

  - job_name: 'node_widgets'
    scheme: https  # 使用 HTTPS
    tls_config:
      insecure_skip_verify: true  # 忽略证书验证
    static_configs:
      - targets: ['xxxxx.xxx.com:443']  # 替换为您的服务器 B 地址和端口
    metrics_path: '/prometheus/metrics'  # Node Exporter 的路径

如果修改了配置可以验证配置

./promtool check config new_prometheus.yml

热更新

curl -X POST http://localhost:9070/-/reload
1.3 配置自启动
vim /etc/systemd/system/prometheus.service
写入数据
[Unit]
Description=Prometheus Server
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
WorkingDirectory=/opt/prometheus/prometheus-2.45
ExecStart=/opt/prometheus/prometheus-2.45/prometheus --web.listen-address ":9070" --config.file /opt/prometheus/prometheus-2.45/new_prometheus.yml --storage.tsdb.path /opt/prometheus/prometheus-2.45/data --storage.tsdb.retention.time=20d --web.enable-lifecycle
[Install]
WantedBy=multi-user.target

开机自启动

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl restart prometheus
sudo systemctl status prometheus

二、安装node_exporter

2.1 官网下载地址 https://prometheus.io/download/
2.2 开机自启动

添加

sudo vim /etc/systemd/system/node_exproter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=ubuntu
Group=ubuntu
ExecStart=/opt/prometheus/node_exproter-1.7.0/node_exporter --web.listen-address=":9101"
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable node_exproter
sudo systemctl restart node_exproter
sudo systemctl status node_exproter

三、安装grafana

3.1 官网下载地址 https://grafana.com/grafana/download?edition=oss&platform=linux
3.2 添加开机启动

添加service

sudo vim /etc/systemd/system/grafana.service
[Unit]
Description=Grafana server
Documentation=http://docs.grafana.org
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/grafana-v10.2.2/bin/grafana-server \
  --config=/opt/prometheus/grafana-v10.2.2/conf/grafana.ini \
  --homepath=/opt/prometheus/grafana-v10.2.2 \
  --http-port=3000
[Install]
WantedBy=multi-user.target
3.2 修改 grafana.init 邮箱配置
[smtp]
enabled = true
host = smtp.gmail.com:587
user = xuzan@lippu.ltd
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = 授权码
cert_file =
key_file =
skip_verify = true
from_address = xuzan@lippu.ltd
from_name = Grafana
ehlo_identity =
startTLS_policy =
sudo systemctl daemon-reload
sudo systemctl enable grafana
sudo systemctl restart grafana
sudo systemctl status grafana

四、alertmanager 安装

4.1 安装官网地址 https://prometheus.io/download/
4.2 新增启动项

编辑

sudo vim /etc/systemd/system/alertmanager.service
[Unit]
Description=Alert Manager
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/alertmanager-0.26.0/alertmanager \
  --config.file=/opt/prometheus/alertmanager-0.26.0/alertmanager.yml \
  --storage.path=/opt/prometheus/alertmanager-0.26.0/data \
  --web.listen-address=:9071 \
  --cluster.listen-address=:9072

Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable alertmanager
sudo systemctl restart alertmanager
sudo systemctl status alertmanager
4.3 使用了prometheus 需要修改 new_prometheus.yml

新增

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - alertmanager:9071

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "alert.yml"

在项目更目录下新增 新增alert.yml

groups:
- name: Prometheus alert
  rules:
  # 对任何实例超过30s无法联系的情况发出警报
  - alert: 服务告警
    expr: up == 0
    for: 30s
    labels:
      severity: critical
    annotations:
      instance: "{{ $labels.instance }}"
      description: "{{ $labels.job }} 服务已关闭"
具体告警规则:

alert: 这是告警的名称,在这个例子中命名为 "服务告警"。
expr: 这是触发告警的表达式。在这个例子中,表达式 up == 0 检查 up 指标是否等于 0。up 指标是 Prometheus 用来表示目标实例可达性的标准指标,其中 0 表示不可达,1 表示可达。
for: 这个条件指定了在触发告警之前必须满足告警条件的持续时间。在这里设置为 30s,意味着只有当 up 指标持续为 0 超过 30 秒时,才会触发告警。
labels: 这部分定义了附加到告警上的标签。在这个例子中,它设置了一个严重性标签(severity: critical),表示这是一个严重的告警。
annotations:
这部分提供了关于告警的更多信息,通常用于在告警通知中显示。在这个例子中,它包括两个注解:
instance: "{{ $labels.instance }}":这将显示触发告警的实例。
description: "{{ $labels.job }} 服务已关闭":这提供了一个描述性的消息,指出哪个服务(job)已经关闭。
4.4 验证配置
./promtool check config new_prometheus.yml

在这里插入图片描述
重新热加载配置

curl -X POST http://localhost:9070/-/reload

五、grafana 添加数据源

5.1 添加数据来源

这里填写prometheus 的数据源地址,因为grafana 和 prometheus 放到一台服务器上了,所以我填写的是localhost
在这里插入图片描述

5.2 添加dashboards,添加地址: https://grafana.com/grafana/dashboards/

选择一个dashborads
在这里插入图片描述
copy dashborads 的ID
在这里插入图片描述
在grafana 界面导入dashborad ,可以通过ID导入
在这里插入图片描述

最后选择刚刚的数据源
在这里插入图片描述

最终显示
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/229542.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

2.6 A 的 LU 分解

一、A LU 线性代数很多关键的概念实际上就是矩阵的分解(factorization)。原始矩阵 A A A 变成两个或三个特殊矩阵的乘积。第一个分解,实际上也是最重要的分解,来自消元法。因子 L L L 和 U U U 都是三角形矩阵,分…

用 @icestack/ui 构建适配微信小程序的 daisyui

用 icestack/ui 构建适配微信小程序的 daisyui 用 icestack/ui 构建适配微信小程序的 daisyui 前言思考与实践如何使用? 安装初始化配置构建样式 作为 tailwindcss plugin 来使用 安装配置智能提示 在微信小程序里使用 安装注册构建 演示小程序收到启发的项目参考地址 前言…

在pom.xml中添加maven依赖,但是类里面import导入的时候报错

问题: Error:(27, 8) java: 类TestKuDo是公共的, 应在名为 TestKuDo.java 的文件中声明 Error:(7, 23) java: 程序包org.apache.kudu不存在 Error:(8, 23) java: 程序包org.apache.kudu不存在 Error:(9, 23) java: 程序包org.apache.kudu不存在 Error:(10, 30) jav…

网工内推 | 外企、合资公司急招网工,国内外旅游,健身年卡

01 深圳市耐施菲信息科技有限公司 招聘岗位:网络工程师 职责描述: 1、负责项目的计划、实施、过程管控、项目验收等工作; 2、负责大型项目设备实施、安装调试等售后维护工作; 3、分析、设计网络拓扑结构、配置H3C、华为等交换机…

Unity3D中实现箭头指向目标点的效果(shader)

系列文章目录 Unity工具 文章目录 系列文章目录前言一、效果如下二、制作步骤2-1、制作shader2-2、shader代码2-3、制作材质球2-4、新建Quad2-5、制作预制体2-6 、实现代码2-7、设置Quad到脚本2-8、路径设置如下 三、说明四、运行程序总结 前言 大家好,我是心疼你…

将 ONLYOFFICE 协作空间的公共房间嵌入到网页

在 ONLYOFFICE 协作空间2.0版本中,我们新增了公共房间,可与外部用户共享文件。公共房间可以集成到您的网站或单页应用程序 (SPA) 中,访问者无需下载或注册自己的协作空间帐户即可查看文档。我们在本文中介绍了分步指南。 什么是公共房间&…

【vtkWidgetRepresentation】第六期 vtkFinitePlaneRepresentation

很高兴在雪易的CSDN遇见你 ,给你糖糖 欢迎大家加入雪易社区-CSDN社区云 前言 本文分享VTK中的平面Plane表示方法,希望对各位小伙伴有所帮助! 感谢各位小伙伴的点赞关注,小易会继续努力分享,一起进步! …

为什么数据科学应用要使用Python作为实现工具

1.3 为什么要使用Python作为实现工具 视频为《Python数据科学应用从入门到精通》张甜 杨维忠 清华大学出版社一书的随书赠送视频讲解1.3节内容。本书已正式出版上市,当当、京东、淘宝等平台热销中,搜索书名即可。内容涵盖数据科学应用的全流程&#xff0…

【夯实技术基本功】「底层技术原理体系」全方位带你认识和透彻领悟正则表达式(Regular Expression)的开发手册(正则符号深入解析 )

[TOC](【夯实技术基本功】「底层技术原理体系」全方位带你认识和透彻领悟正则表达式(Regular Expression)的开发手册(正则符号深入解析 )) 借鉴官网的速查表 基础匹配符号 反向匹配表 各种操作符的运算优先级 承接上文,在正则表达式中&…

K8s 入门指南(一):单节点集群环境搭建

前言 官方文档:Kubernetes 文档 | Kubernetes 系统配置 CentOS 7.9(2 核 2 G) 本文为 k8s 入门指南专栏,将会使用 kubeadm 搭建单节点 k8s 集群,详细讲解环境搭建部署的细节,专栏后面章节会以实战代码介绍…

leetcode 面试题 02.02. 返回倒数第k个节点

提建议就是,有些题还是有联系的,建议就收看完 876.链表的中间节点(http://t.csdnimg.cn/7axLa),再将这一题联系起来 面试题 02.02. 返回倒数第k个节点 题目: 实现一种算法,找出单向链表中倒数第…

geolife笔记:整理处理单条轨迹

以 数据集笔记 geolife (操作篇)_geolife数据集-CSDN博客 轨迹为例 1 读取数据 import pandas as pd data pd.read_csv(Geolife Trajectories 1.3/Data//000/Trajectory/20081023025304.plt,headerNone, skiprows6,names[Latitude, Longitude, Not_Im…

Volumetric Lights 2 HDRP

高清晰度渲染管道,包括先进的新功能,如半透明阴影图和直接灯光投射加上许多改进。 插件是一个快速,灵活和伟大的前瞻性光散射解决方案的高清晰度渲染管道。只需点击几下,即可改善场景中的照明视觉效果。 兼容: 点光源 聚光灯 碟形灯 矩形灯 通过覆盖摄像机周围大面积区域的…

oracle 下载java之前版本

登录oracle官网:Oracle | Cloud Applications and Cloud Platform 点击resource 进入该页面 点击这个 出现之前版本

学习pytorch19 pytorch使用GPU训练

pytorch使用GPU进行训练 1. 数据 模型 损失函数调用cuda()2. 使用谷歌免费GPU gogle colab 需要创建谷歌账号登录使用, 网络能访问谷歌3. 执行4. 代码 B站土堆学习视频: https://www.bilibili.com/video/BV1hE411t7RN/?p30&spm_id_frompageDriver&vd_sourc…

机器学习算法(7)-朴素贝叶斯算法和K最近邻算法

一、说明 在在这篇文章中,我将解释两种机器学习算法,称为贝叶斯定理和 K 最近邻算法。贝叶斯定理以 18 世纪英国数学家托马斯贝叶斯的名字命名,是确定条件概率的数学公式。k 最近邻算法,也称为 KNN 或 k-NN,是一种非参…

【Pyqt】QObject::connect: Cannot queue arguments of type ‘QTextCursor‘

问题说明 文本框接收到新的数据 不会自动滚动,并提示警告 QObject::connect: Cannot queue arguments of type ‘QTextCursor’ (Make sure ‘QTextCursor’ is registered using qRegisterMetaType().) 原因 线程回来的槽函数里面 调用了ui的代码 我们不能通过线程…

测试文档---智力冲刺

文章目录 项目背景测试计划UI测试接口测试手工测试 测试总结 项目背景 项目描述:“智力冲刺”是一款网页小游戏,就像我们平时看到的网页游戏一样,前端页面负责展示游戏效果,后端服务器来实现游戏的逻辑。在我们的“智力冲刺”游戏…

【从零认识ECS云服务器 | 快速上线个人网站】三、对外发布网站

3.1 配置域名 用户是如何访问网站的呢? 用户在浏览器(IE、Chrome、FireFox等)上输入域名,如:http://www.aliyun.com ; 浏览器自动调用DNS(域名服务)将域名解析为IP地址,如:123.123…

P3 Qt 控件 —— pushButton

前言 🎬 个人主页:ChenPi 🐻推荐专栏1: 《C_ChenPi的博客-CSDN博客》✨✨✨ 🔥 推荐专栏2: 《Linux C应用编程(概念类)_ChenPi的博客-CSDN博客》✨✨✨ 🌺本篇简介 :这一章我们学一…
最新文章