基本说明

Prometheus+Grafana无疑是目前最流行的监控预警系统,这个系统是基于GO语言运行的,所有我们首先需要配置Go语言的环境,这里涉及到我另一篇文章的内容,我就先不作重述了。
链接地址为:
https://blog.csdn.net/weixin_48803304/article/details/107296099

1.GO环境配置

这里提供一个我整合以后的脚本文件

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
cur_dir=$(pwd)# 定义显示文本色彩
Color_Text()
{echo -e " \e[0;$2m$1\e[0m"
}Echo_Red()
{echo $(Color_Text "$1" "31")
}Echo_Green()
{echo $(Color_Text "$1" "32")
}Echo_Yellow()
{echo $(Color_Text "$1" "33")
}Echo_Blue()
{echo $(Color_Text "$1" "34")
}
Echo_Blue '[info] 安装Golang'
if [ ! -d "/tools" ];thenmkdir /tools
fi
cd /tools
if [ ! -f 'go1.17.linux-amd64.tar.gz' ];thenEcho_Blue '[info] 开始下载安装包'wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz
elseEcho_Yellow "[info] 安装包已经存在,继续执行..."
fi
if [ ! -d "/usr/local/go" ];thenEcho_Blue '[info] 解压安装包'tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
elseEcho_Yellow "[info] 文件夹/usr/local/go已经存在,继续执行..."
fi
if [ ! -f "/etc/profile.d/golang.sh" ];thenEcho_Blue '[info] 写入变量'
cat >>/etc/profile.d/golang.sh<<EOF
export GOROOT=/usr/local/go
export PATH=\$PATH:\$GOROOT/bin
export GOPATH=/root/go
export PATH=\$PATH:\$GOPATH/BIN
EOF
elseEcho_Yellow "[info] GO环境变量已经存在,继续执行..."
fi
source /etc/profile.d/golang.sh
source /etc/profile.d/golang.sh

可以执行go version查看结果

[root@localhost tools]# go version
go version go1.15.5 linux/amd64

2.配置Prometheus

官网为https://prometheus.io/,我们进入下载页面,下载我们需要的包或是扩展https://prometheus.io/download/

mkdir /home/prometheus

为了方便管理和维护,我把所有的prometheus项目及控件放到一个目录中,首先我们下载prometheus

cd /home/prometheus/
wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz
mkdir prometheus && tar zxvf prometheus-2.28.1.linux-amd64.tar.gz -C ./prometheus --strip-components 1
cd prometheus/

目录中就是我们需要的文件,我们可以将prometheus设置为一项服务

cat >>/etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=https://prometheus.io/[Service]
Type=simple
MemoryLimit=100M
CPUQuota=20%WorkingDirectory=/home/prometheus/prometheus/
ExecStart=/home/prometheus/prometheus/prometheus --config.file=/home/prometheus/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

添加防火墙规则并启动服务

firewall-cmd --permanent --zone=public --add-port=9090/tcp
firewall-cmd --reload
systemctl enable prometheus
systemctl start prometheus
systemctl status prometheus

这个时候我们就可以通过http方式访问我们的服务了
不同的扩展需要到不同的地方下载,官方提供了入口
https://prometheus.io/docs/instrumenting/exporters/#databases

Prometheus进阶

1.node_exporter

在Prometheus的架构设计中,Prometheus Server并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的CPU使用率,我们需要使用到Exporter。Prometheus周期性的从exporter暴露的HTTP服务地址(通常是/metrics)拉取监控样本数据。

exporter可以是一个相对开放的概念,本质是一个独立运行的程序独立于监控目标以外,也可以是直接内置在监控目标中。只要能够向Prometheus提供标准格式的监控样本数据(TS时间序列)即可。
为了能够采集到主机的运行指标如CPU, 内存,磁盘等信息。就需要用到node_exporter。
下载并解压缩包

cd /home/prometheus
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz
mv node_exporter-1.1.2.linux-amd64 node_exporter
cd node_exporter/

设置系统服务

cat >>/etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=node_exporter
After=network.target [Service]
Type=simple
MemoryLimit=100M
CPUQuota=20%
ExecStart=/home/prometheus/node_exporter/node_exporter[Install]
WantedBy=multi-user.targetEOF

添加防火墙规则并启动服务

firewall-cmd --permanent --zone=public --add-port=9100/tcp
firewall-cmd --reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter

常用的模板ID8919

2.安装grafana

grafana官网地址为https://grafana.com/
进入下载页面,可以找到不同的系统的安装方法,我直接使用 centos的安装方法
https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1

wget https://dl.grafana.com/oss/release/grafana-8.0.5-1.x86_64.rpm
sudo yum install -y grafana-8.0.5-1.x86_64.rpm
grafana-cli plugins install grafana-image-renderer
yum -y install libatk-bridge* libXss* libgtk*
firewall-cmd --permanent --zone=public --add-port=3000/tcp
firewall-cmd --reload
systemctl enable grafana-server
systemctl start grafana-server
systemctl status grafana-server

关于grafana绑定prometheus的例子网上有很多,感兴趣的朋友可以搜索一下

SMTP设置

vi /etc/grafana/grafana.ini
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true
host = smtp.qq.com:465
user = lzyats@qq.com
# 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 = lzyats@qq.com
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com
# SMTP startTLS policy (defaults to 'OpportunisticStartTLS')
#startTLS_policy = NoStartTLS[emails]
;welcome_email_on_sign_up = false
;templates_pattern = emails/*.html

如果想在钉钉报警中带图片,记得配置图片地址

[external_image_storage]
provider = local

3.grafana模板

由于grafana是个开放的平台,自然会有许多模板提供,地址是
https://grafana.com/grafana/dashboards
我们关注一下node_exporter的模板,推荐使用9276

mysql_exporter.service

vi /etc/systemd/system/mysqld_exporter81.service

[Unit]
Description=mysqld_exporter81
After=network.target
[Service]
Type=simple
User=mysql
# exporter对应授权账号,exporter123对应授权密码,localhost对应授权账号密码所在的地址
Environment=DATA_SOURCE_NAME=exporter:123456@(l192.168.200.130:3306)/
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9104--config.my-cnf /home/data/mysql80/my1.cnf \--collect.slave_status \--collect.slave_hosts \--log.level=error \--collect.info_schema.processlist \--collect.info_schema.innodb_metrics \--collect.info_schema.innodb_tablespaces \--collect.info_schema.innodb_cmp \--collect.info_schema.innodb_cmpmem
Restart=on-failure
[Install]
WantedBy=multi-user.targe

systemctl enable mysqld_exporter81
systemctl start mysqld_exporter81
systemctl status mysqld_exporter81

vi /etc/systemd/system/mysqld_exporter82.service

[Unit]
Description=mysqld_exporter82
After=network.target
[Service]
Type=simple
User=mysql
# exporter对应授权账号,exporter123对应授权密码,localhost对应授权账号密码所在的地址
Environment=DATA_SOURCE_NAME=exporter:123456@(l192.168.200.130:3308)/
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9105--config.my-cnf /home/data/mysql80/my2.cnf \--collect.slave_status \--collect.slave_hosts \--log.level=error \--collect.info_schema.processlist \--collect.info_schema.innodb_metrics \--collect.info_schema.innodb_tablespaces \--collect.info_schema.innodb_cmp \--collect.info_schema.innodb_cmpmem
Restart=on-failure
[Install]
WantedBy=multi-user.targe

systemctl enable mysqld_exporter82
systemctl start mysqld_exporter82
systemctl status mysqld_exporter82

alertmanager

vi /etc/systemd/system/alertmanager.service

[Unit]
Description=alertmanager
Documentation=https://prometheus.io/
After=network.target[Service]
Type=simple
WorkingDirectory=/home/prometheus/alertmanager/
ExecStart=/home/prometheus/alertmanager/alertmanager --config.file=/home/prometheus/alertmanager/alertmanager.yml
#Restart=always
RestartSec=60
Restart=on-failure[Install]
WantedBy=multi-user.target

systemctl enable alertmanager
systemctl start alertmanager
systemctl status alertmanager

apache_exporter

vi /etc/systemd/system/apache_exporter.service

[Unit]
Description=Prometheus apache exporter
Documentation=https://github.com/Lusitaniae/apache_exporter
After=network.target[Service]
Type=simple
ExecStart=/usr/local/apache_exporter/apache_exporter --scrape_uri=http://lzyats:lijiangkkk@127.0.0.1:8081/server-status?auto \
--telemetry.address=0.0.0.0:9117 \
--telemetry.endpoint=/metrics
Restart=on-failure[Install]
WantedBy=multi-user.target

systemctl enable apache_exporter
systemctl start apache_exporter
systemctl status apache_exporter

redis_exporter

这个需要单独下载,下载地址为:https://github.com/oliver006/redis_exporter/releases/download/v1.24.0/redis_exporter-v1.24.0.linux-amd64.tar.gz
vi /etc/systemd/system/redis_exporter.service

[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target[Service]
Type=simple
MemoryLimit=100M
CPUQuota=20%
WorkingDirectory=/home/prometheus/redis_exporter
ExecStart=/home/prometheus/redis_exporter/redis_exporter -redis.addr=127.0.0.1:6379 -redis.password=lijiangkkkRestart=on-failure[Install]
WantedBy=multi-user.target
firewall-cmd --permanent --zone=public --add-port=9121/tcp
firewall-cmd --reload
systemctl enable redis_exporter
systemctl start redis_exporter
systemctl status redis_exporter

有一点需要注意的是1.0版本以上,多实例的配置方法改变为

scrape_configs:- job_name: 'redis_exporter_targets'static_configs:- targets:- redis://192.168.200.130:6379- redis://192.168.200.130:6389- redis://192.168.200.131:6379- redis://192.168.200.131:6389metrics_path: /scraperelabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]target_label: instance- target_label: __address__replacement: 127.0.0.1:9121- job_name: 'redis_exporter'static_configs:- targets:- 127.0.0.1:9121

nginx-vts-exporter

1.安装nginx 插件

我使用的是tengine2.33,重新编译一下,加上需要的扩展

cd /tools/
git clone git://github.com/vozlt/nginx-module-vts.git
cd tengine-2.3.3./configure --prefix=/etc/nginx --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --user=nginx --group=nginx --add-module=/tools/nginx-module-vtsmake && make installmkdir /var/log/nginxmkdir /etc/nginx/conf/conf.d

接下来配置nginx

http {vhost_traffic_status_zone;vhost_traffic_status_filter_by_host on;server {#   vhost_traffic_status off;location /status {vhost_traffic_status_display;vhost_traffic_status_display_format html;}}
}

docker运行方法

docker run -d -p 9913:9913 --env NGINX_STATUS="http://192.168.201.12/status/format/json" --name gh-nginx sophos/nginx-vts-exporter

2.安装nginx-vts-exporter

nginx-vts-exporter扩展需要进入官网的其他区域查找,进入https://prometheus.io/docs/instrumenting/exporters/找到以下部分

点击下载最新的版本,最好是下载编译好的包

wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
tar zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
mv nginx-vts-exporter-0.10.3.linux-amd64 /home/prometheus/nginx-vts-exporter

设置为启动服务

vi /etc/systemd/system/nginx-vts-exporter.service
[Unit]
Description=nginx-vts-exporter
Documentation=https://github.com/prometheus/redis_exporter
After=network.target[Service]
Type=simple
MemoryLimit=100M
CPUQuota=20%
WorkingDirectory=/home/prometheus/nginx-vts-exporter
ExecStart=/home/prometheus/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri=http://127.0.0.1/status/format/jsonRestart=on-failure[Install]
WantedBy=multi-user.target
firewall-cmd --permanent --zone=public --add-port=9913/tcp
firewall-cmd --reload
systemctl enable nginx-vts-exporter
systemctl start nginx-vts-exporter
systemctl status nginx-vts-exporter

导入模板2949

gearman-exporter

wget https://github.com/bakins/gearman-exporter/releases/download/v0.5.0/gearman-exporter.linux.amd64
mv gearman-exporter.linux.amd64 gearman-exporter
chmod +x gearman-exporter
vi /etc/systemd/system/gearman-exporter.service
[Unit]
Description=gearman-exporter
Documentation=https://github.com/bakins/gearman-exporter
After=network.target[Service]
Type=simple
MemoryLimit=100M
CPUQuota=20%
WorkingDirectory=/home/prometheus/
ExecStart=/home/prometheus/gearman-exporter --addr 192.168.200.131:9418Restart=on-failure[Install]
WantedBy=multi-user.target
firewall-cmd --permanent --zone=public --add-port=9418/tcp
firewall-cmd --reload
systemctl enable gearman-exporter
systemctl start gearman-exporter
systemctl status gearman-exporter

模板11423

Prometheus+Grafana相关推荐

  1. (四) prometheus + grafana + alertmanager 配置Kafka监控

    安装请看https://blog.51cto.com/liuqs/2027365 ,最好是对应的版本组件,否则可能会有差别. (一)prometheus + grafana + alertmanage ...

  2. Node_exporter+Prometheus+Grafana 快速实现Linux系统性能数据提取、存储和可视化展示

    Node_exporter+Prometheus+Grafana 快速实现Linux系统性能数据提取.存储和可视化展示 1. 前言 2. Node_exporter 2.1 安装 node_expor ...

  3. prometheus+grafana+pushgateway+node-exporter+consul搭建监控系统

    目录 一.总览 二.安装prometheus + grafana 三. 安装一个exporter 四.pushgateway安装 五. service discovery之consul 六.alert ...

  4. 搭建prometheus+grafana监控系统

    prometheus简介 Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包 .自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发 ...

  5. 3.Prometheus + Grafana实现可视化、告警

    3.Prometheus + Grafana实现可视化.告警 3.1.什么是Grafana 3.2.快速入门 3.3.Grafana的下载 3.4.启动grafana 3.5.配置数据源 3.6.配置 ...

  6. 使用Prometheus+Grafana 监控MySQL/MONGODB

    使用Prometheus+Grafana 监控MySQL/MONGODB 之前就久仰 Prometheus 大名,因为有用zabbix 进行监控,就没去安装它.现在正好用上监控MONGO+MYSQL. ...

  7. Prometheus+Grafana PG监控部署以及自定义监控指标

    点击上方"蓝字" 关注我们,享更多干货! 1.前言 Prometheus:是从云原生计算基金会(CNCF)毕业的项目.Prometheus是Google监控系统BorgMon类似实 ...

  8. 基于Prometheus+Grafana监控SQL Server数据库

    墨墨导读:本文整理了基于Prometheus+Grafana监控SQL Server数据库的全过程,分享至此,希望对大家有帮助. 搭建SQL Server环境 使用容器建立SQL Server环境非常 ...

  9. 技术实践丨Prometheus+Grafana搭建HBase监控仪表盘

    摘要:Grafana+Prometheus是目前非常流行的监控方案,图形化展示非常强大. 本文分享自华为云社区<Prometheus+Grafana搭建HBase监控仪表盘>,原文作者:L ...

  10. Prometheus+Grafana监控PostgreSQL

    Prometheus+Grafana监控PostgreSQL Prometheus:2.32.0 Grafana:8.3.3 PG:13.2 Linux:CentOS7.6 docker:18.06. ...

最新文章

  1. mysql数据库常用命令
  2. char值序列是什么Java_CharSequence和java之间的确切区别
  3. java.math.BigDecimal()的用法
  4. 计算机视觉开源库OpenCV之照明和色彩空间
  5. 【Web安全】实战sqlmap绕过WAF
  6. Python爬虫西安七天天气预报
  7. MySql 扩展存储引擎
  8. 获取treeview中当前鼠标所指的节点treenode 。
  9. Lock的lock()方法
  10. mysql hint use force ignore_MySQL实时在线备份恢复方案
  11. android sim卡分析,Android 判断SIM卡属于哪个移动运营商详解及实例
  12. oracle 11g r2 rac中节点时间不同步,Oracle 11gR2 安装RAC错误之--时钟不同步
  13. wine手动安装wine-mono和wine-gecko组件
  14. 人工智能知识全面讲解: RBF神经网络
  15. 修改电脑微信提示音+dll文件编辑器
  16. 【MATLAB】求解含有三角函数的方程
  17. 用计算机美化演讲稿过程,计算机应用基础第10章--PowerPoint应用—制作论文答辩演讲稿.ppt...
  18. Fcitx使用搜狗词库与皮肤
  19. Python替换月份为英文缩写
  20. 心灵捕手——走进内心世界

热门文章

  1. YOLO算法创新改进系列项目汇总(入门级教程指南)
  2. 计算机专业C语言复试常见问题(二)
  3. 【 2021 MathorCup杯大数据挑战赛 A题 二手车估价】初赛复赛总结、方案代码及论文
  4. 最通俗易懂的python与mysql数据库交互
  5. c语言中英文字母的符号,C语言中的符号(国外英文资料).doc
  6. 模块独立(耦合性与内聚性)
  7. 《Qt5+安装包制作(Qt Installer Framework)》
  8. 基于Java毕业设计校园面包超市系统源码+系统+mysql+lw文档+部署软件
  9. C语言:输出汉语拼音与多行
  10. 一个技术创业者的自白:你为什么想创业?