部署prometheus+Grafana可视化仪表盘监控服务

2024-03-16 17:12

本文主要是介绍部署prometheus+Grafana可视化仪表盘监控服务,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、部署prometheus及监控仪表盘

简介

Prometheus是开源监控报警系统和时序列数据库(TSDB)。

Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控,输出被监控组件信息的HTTP接口被叫做exporter。目前互联网公司常用的组件大部分都有exporter可以直接使用,比如Varnish、Haproxy、Nginx、MySQL、Linux系统信息(包括磁盘、内存、CPU、网络等等)。

1 基础环境

环境/组件 版本 下载地址 操作系统 CentOS 7.3 http://archive.kernel.org/centos-vault/7.3.1611/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso

Prometheus 2.6.0 Download | Prometheus

go 1.12.3 https://mirrors.xlhy1.com/source-code/go1.12.3.linux-amd64.tar.gz

Grafana 5.4.2 https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm

2 安装go

2.1 安装

rz             #上传go1.12.3.linux-amd64.tar.gz压缩包
tar -C /usr/local/ -xzvf go1.12.3.linux-amd64.tar.gz

2.2 配置环境变量

vim /etc/profile                            #打开配置文件
export PATH=$PATH:/usr/local/go/bin         #添加内容source /etc/profile                         #刷新环境变量配置文件

2.3 验证版本

go version

3. 安装Prometheus

3.1 安装

rz                                                                      #上传 prometheus-2.6.0.linux-amd64.tar.gz
tar -C /usr/local/ -xzvf prometheus-2.6.0.linux-amd64.tar.gz            #解压缩到指定目录
cd /usr/local/                                                          #进入目录
ln -sv /usr/local/prometheus-2.6.0.linux-amd64/ /usr/local/prometheus   #创建软连接

3.2 修改prometheus配置文件

vim /usr/local/prometheus/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"- "/usr/local/prometheus/rules/node.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'static_configs:- targets: ['192.168.0.4:9090']

3.3 启动prometheus

nohup /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

3.4 访问

浏览器访问:ip:9090/targets

注意:如果是云服务器,配置文件中的ip为ifconfig命令查到的IP,浏览器访问的ip为公网ip

4. 安装Grafana

4.1 安装

rz                                              #上传 grafana-5.4.2-1.x86_64.rpm
rpm -ivh --nodeps grafana-5.4.2-1.x86_64.rpm    #编译安装

4.2 可能在安装grafana时有依赖库,需要搭建个本地yum源安装fontconfig、urw-fonts

yum install fontconfig
yum install urw-fonts

4.3 启动Grafana

systemctl daemon-reload
systemctl enable grafana-server.service         #设为开机自启动
systemctl start grafana-server.service

4.4 访问grafana

浏览器访问IP:3000端口,即可打开grafana页面,默认用户名密码都是admin,初次登录会要求修改默认的登录密码

4.5 点击主界面的“Add data source”

4.6 选择Prometheus

4.7 Dashboards页面选择“Prometheus 2.0 Stats”

4.8 Settings页面填写普罗米修斯地址并保存

4.9 切换到我们刚才添加的“Prometheus 2.0 Stats”即可看到整个监控页面

二、Prometheus + Grafana监控之主机性能

监控linux机器(node-exporter) https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

1.被监控的机器安装node-exporter

1.1 解压安装

rz                               #上传node_exporter-0.17.0.linux-amd64.tar.gz
tar -xvf -C /usr/local/ node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/      
cd /usr/local/
ln -sv node_exporter-0.17.0.linux-amd64 node_exporter

1.2 启动node-exporter

nohup /usr/local/node_exporter/node_exporter --web.listen-address=":9100" &

启动成功后,可以访问 http://1.117.225.137:9100/metrics(IP和端口要改成相应环境的,公网ip)

2.prometheus添加监控项

2.1 修改prometheus配置文件

vim /usr/local/prometheus/prometheus.yml        #打开配置文件
#默认node-exporter端口为9100
添加配置文件内容如下:
# 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.
​
# 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"- "/usr/local/prometheus/rules/node.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'static_configs:- targets: ['192.168.0.4:9090']- job_name: 'prometheus-yjsx'static_configs:- targets: ['1.117.225.137:9100']   #公网ip

2.2 重启普罗米修斯

[root@xplinux ~]# ps axu | grep prometheus          #查看进程
root      6969  0.0  4.1 146340 41780 pts/1    Sl   15:15   0:01 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
root     14193  0.0  0.0 112708   980 pts/1    R+   16:35   0:00 grep --color=auto prometheus
​
kill -9 6969                                      #结束进程
nohup /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml & #启动

3. Grafana导入画好的dashboard

Upload上传node-exporter_rev5.json文件(也可以直接使用官方模板,需要此node-exporter_rev5.json文件的可以私信我获取)

修改名字,选择我们前文创建好的数据源,点击导入即可

如果没有任何显示,是grafana缺少相关显示需要用到的插件piechart

grafana的默认插件目录是,可以将下载好的插件解压到这个目录,重启grafana即可 piechart插件下载链接:

cd /var/lib/grafana/plugins                         #进入目录
rz                                                  #上传插件 grafana-piechart-panel-5f249d5.zip
unzip grafana-piechart-panel-5f249d5.zip            #解压缩
service grafana-server restart                      #重启Grafana
ls /usr/sbin/grafana-cli plugins                    #查看已安装插件

再刷新grafana页面,即可看到我们刚才设置好的node监控

三、Prometheus + Grafana监控之Kafka

监控kafka(kafka_exporter)

从 GitHub - danielqsj/kafka_exporter: Kafka exporter for Prometheus 下载

1. 安装kafka_exporter

注:1个kafka集群只需要1个exporter,在集群上的任意1台服务器部署。

kafka_exporter-1.2.0.linux-amd64.tar下载地址:忘求了,家人们可以百度找找

rz          #上传kafka_exporter-1.2.0.linux-amd64.tar
tar -xvf kafka_exporter-1.2.0.linux-amd64.tar -C /usr/local/
cd /usr/local/
ln -sv kafka_exporter-1.2.0.linux-amd64 kafka_exporter      #创建软连接
cd kafka_exporter

1.1 启动kafka_exporter

nohup ./kafka_exporter --kafka.server=172.16.1.224:9092 &

启动成功后,可以访问 http://172.16.1.224:9308/metrics/ ,(IP和端口要改成相应环境的)

看抓取的信息如下:

2. 修改Prometheus配置

2.1 修改prometheus组件的prometheus.yml加入kafka监控

vim /usr/local/prometheus-2.27.1/prometheus.yml     #打开prometheus配置文件
添加内容如下:图片已丢失!!!

2.2 启动验证

先kill掉Prometheus进程,用以下命令重启它,然后查看targets:
cd /usr/local/prometheus
nohup ./prometheus --config.file=prometheus.yml &

State=UP,说明成功

3. Grafana配置

导入仪表盘模板

通过浏览器访问:IP地址:3000

图片已丢失!!!

 👑👑👑结束语👑👑👑

这篇关于部署prometheus+Grafana可视化仪表盘监控服务的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/816164

相关文章

使用IDEA部署Docker应用指南分享

《使用IDEA部署Docker应用指南分享》本文介绍了使用IDEA部署Docker应用的四步流程:创建Dockerfile、配置IDEADocker连接、设置运行调试环境、构建运行镜像,并强调需准备本... 目录一、创建 dockerfile 配置文件二、配置 IDEA 的 Docker 连接三、配置 Do

SpringBoot监控API请求耗时的6中解决解决方案

《SpringBoot监控API请求耗时的6中解决解决方案》本文介绍SpringBoot中记录API请求耗时的6种方案,包括手动埋点、AOP切面、拦截器、Filter、事件监听、Micrometer+... 目录1. 简介2.实战案例2.1 手动记录2.2 自定义AOP记录2.3 拦截器技术2.4 使用Fi

Spring Boot Actuator应用监控与管理的详细步骤

《SpringBootActuator应用监控与管理的详细步骤》SpringBootActuator是SpringBoot的监控工具,提供健康检查、性能指标、日志管理等核心功能,支持自定义和扩展端... 目录一、 Spring Boot Actuator 概述二、 集成 Spring Boot Actuat

Spring Boot 与微服务入门实战详细总结

《SpringBoot与微服务入门实战详细总结》本文讲解SpringBoot框架的核心特性如快速构建、自动配置、零XML与微服务架构的定义、演进及优缺点,涵盖开发环境准备和HelloWorld实战... 目录一、Spring Boot 核心概述二、微服务架构详解1. 微服务的定义与演进2. 微服务的优缺点三

一文解密Python进行监控进程的黑科技

《一文解密Python进行监控进程的黑科技》在计算机系统管理和应用性能优化中,监控进程的CPU、内存和IO使用率是非常重要的任务,下面我们就来讲讲如何Python写一个简单使用的监控进程的工具吧... 目录准备工作监控CPU使用率监控内存使用率监控IO使用率小工具代码整合在计算机系统管理和应用性能优化中,监

RabbitMQ消息总线方式刷新配置服务全过程

《RabbitMQ消息总线方式刷新配置服务全过程》SpringCloudBus通过消息总线与MQ实现微服务配置统一刷新,结合GitWebhooks自动触发更新,避免手动重启,提升效率与可靠性,适用于配... 目录前言介绍环境准备代码示例测试验证总结前言介绍在微服务架构中,为了更方便的向微服务实例广播消息,

Zabbix在MySQL性能监控方面的运用及最佳实践记录

《Zabbix在MySQL性能监控方面的运用及最佳实践记录》Zabbix通过自定义脚本和内置模板监控MySQL核心指标(连接、查询、资源、复制),支持自动发现多实例及告警通知,结合可视化仪表盘,可有效... 目录一、核心监控指标及配置1. 关键监控指标示例2. 配置方法二、自动发现与多实例管理1. 实践步骤

MySQL 主从复制部署及验证(示例详解)

《MySQL主从复制部署及验证(示例详解)》本文介绍MySQL主从复制部署步骤及学校管理数据库创建脚本,包含表结构设计、示例数据插入和查询语句,用于验证主从同步功能,感兴趣的朋友一起看看吧... 目录mysql 主从复制部署指南部署步骤1.环境准备2. 主服务器配置3. 创建复制用户4. 获取主服务器状态5

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

prometheus如何使用pushgateway监控网路丢包

《prometheus如何使用pushgateway监控网路丢包》:本文主要介绍prometheus如何使用pushgateway监控网路丢包问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录监控网路丢包脚本数据图表总结监控网路丢包脚本[root@gtcq-gt-monitor-prome