第一节、环境和软件版本

1.1、操作系统环境

主机ip 操作系统 部署软件 备注
192.168.10.10 Centos7.9 Grafana、Pushgateway、Blackbox Exporter 监控ui
192.168.10.11 Centos7.9 Loki 日志存储
192.168.10.12 Centos7.9 Promethues 存储监控指标
192.168.10.13 Centos7.9 logstash 日志过滤
192.168.10.14 Centos7.9 Filebeat、node_exporter 日志和监控指标采集
192.168.10.15 Windows server2016 Filebeat、node_exporter 日志和监控指标采集

1.2、软件版本

软件名称 版本 备注
grafana 8.3.3 监控ui
Loki 2.5.0 日志存储
promethues 2.32.1 监控指标存储
pushgateway 1.4.2 接收自定义监控指标
filebeat 6.4.3 日志采集客户端
node_exporter 1.3.1 监控指标采集客户端
logstash 7.16.2 日志过滤
Blackbox Exporter 0.19.0 监控网站、http\tcp\udp等

1.3、系统初始化

1、关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2、关闭selinux

setenforce 0
vim /etc/selinux/config
SELINUX=disabled

1.4、架构图

第二节、监控平台部署

2.1、服务端部署

1、grafana

提示:主机192.168.10.10操作

安装

tar -xvf grafana-8.3.3.linux-amd64.tar
cd grafana-8.3.3/

启动

nohup ./bin/grafana-server > ./log/grafana.log &

浏览器访问:http://192.168.10.10:3000

用户名和密码:admin/admin

2、promethues

提示:主机192.168.10.12操作

安装

tar -xvf prometheus-2.32.1.linux-amd64.tar
cd prometheus-2.32.1.linux-amd64/

启动

nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:49800 1>nohup.log 2>&1 &

浏览器访问:http://192.168.10.12:49800

3、grafana集成promethues

在grafana添加数据源promethues,具体步骤如图





2.2、客户端部署

1、linuxx系统

  • 安装

    部署node_exporter,解压tar包即可
tar -xvf node_exporter-1.3.1.linux-amd64.tar.gz
cd node_exporter-1.3.1.linux-amd64/
  • 启动
nohup ./node_exporter --web.listen-address=:49999 --log.format=logfmt --collector.textfile.directory=./collection.textfile.directory/ --collector.ntp.server-is-local  >/dev/null &

2、windows系统

  • 安装

    Widows安装解压即可

  • 编写启动脚本startNode.bat
start /b "" .\windows_exporter-0.17.0-amd64.exe --telemetry.addr=":9182" --collector.textfile.directory="./collection.textfile.directory/"
  • 启动

    双击启动脚本即可,如下图

3、配置promethues

  • 编写配置文件

    vi prometheus.yml
  - job_name: "NODE"
static_configs:
- targets: ['192.168.10.14:49999']
labels:
env: prd001
group: PAAS
hostip: 192.168.10.14 - targets: ['192.168.10.15:9182']
labels:
env: prd001
group: PAAS
hostip: 192.168.10.15
  • 重启promethues
nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:49800 1>nohup.log 2>&1 &
  • 查看promethues





    4、配置grafana并查看
  • 导入监控模板

    在grafan导入监控windows和linux模板,Windows模板编号:10467,Linux模板编号:11074,具体操作如下图





  • 查看linux面板



  • 查看windows面板



第三节、部署日志平台

3.1、安装服务端

1、安装

tar -xvf loki.tar.gz
cd loki/

启动

nohup ./loki-linux-amd64 -config.file=config.yaml 1> ./log/loki.log & 2> ./log/loki_error.log &
ss -tunlp | grep 3100
tcp LISTEN 0 128 [::]:3100 [::]:* users:(("loki-linux-amd6",pid=8422,fd=10))

2、配置grafana









3.2、部署logstash

tar -xvf logstash-7.16.2.tar
cd logstash-7.16.2/
bin/logstash-plugin install file:///bankapp/logstash/plugin/logstash-codec-plain.zip
bin/logstash-plugin install file:///bankapp/logstash/plugin/logstash-output-loki.zip
vi pipelines/log_collect.conf
input{
beats {
port => 10515
}
}
input{
http {
host => "0.0.0.0"
port => 10516
type => "healthcheck"
}
}
filter {
grok{
match => {
"message" => ".*\[INFO\] \[(?<funcname>(.*?)):.*"
}
}
grok {
match => ["message", "%{TIMESTAMP_ISO8601:logdate}"]
}
if [appname] == "switch" {
date {
match => ["logdate", "yyyy-MM-dd HH:mm:ss.SSS"]
target => "@timestamp" ## 榛樿target灏辨槸"@timestamp
}
}else {
date {
match => ["logdate", "yyyy-MM-dd'T'HH:mm:ss.SSS"]
target => "@timestamp" ## 榛樿target灏辨槸"@timestamp
}
}
mutate {
remove_field => ["tags"]
remove_field => ["offset"]
remove_field => ["logdate"]
}
}
output {
if [type] == "healthcheck" {
}else{
loki {
url => "http://192.168.10.10:3100/loki/api/v1/push"
batch_size => 112640 #112.64 kilobytes
retries => 5
min_delay => 3
max_delay => 500
message_field => "message"
}
}

启动

nohup ./bin/logstash -f ./pipelines/log_collect.conf 1>nohup.loog 2>nohup.log &

3.3、部署客户端filebeat

日志格式如下

gtms-switch-center 2022-04-19 17:28:14.616 [http-nio-8080-exec-989] INFO  c.p.switchcenter.web.controller.SwitchController

1、linux系统

  • 安装
tar -xvf filebeat.tar.gz
cd filebeat/
  • 编写配置文件
vi filebeat.yml
filebeat.prospectors:
- input_type: log
paths:
- /bankapp/switch/gtms-switch-center/com.pactera.jep.log.biz*.log
multiline:
pattern: '^gtms-switch-center'
negate: true
match: after
max_lines: 200
timeout: 20s
fields:
env: "prd001"
appid: "switch"
appname: "switch"
hostip: "192.168.10.15"
reload.enabled: true
reload.period: 2S
fields_under_root: true
output.logstash:
hosts: ["192.168.10.11:10515" ]
enabled: true
  • 启动
nohup ./filebeat -e -c filebeat.yml -d "publish" 1>/dev/null 2>&1 &

2、windows系统

  • windows安装直接解压即可,解压如下

  • 编写配置文件filebeat.yml
filebeat.prospectors:
- input_type: log
encoding: gbk
paths:
- C:/bankapp/switch/gtms-switch-center/com.pactera.jep.log.biz*.log
multiline:
pattern: '^gtms-switch-center'
negate: true
match: after
max_lines: 200
timeout: 20s
fields:
env: "prd001"
appid: "switch"
appname: "switch"
hostip: "192.168.10.16"
reload.enabled: true
reload.period: 2S
fields_under_root: true
output.logstash:
hosts: ["192.168.10.11:10515" ]
enabled: true
  • 编写后台启动脚本startFilebeat.vbs
set ws=WScript.CreateObject("WScript.Shell")
ws.Run "filebeat.exe -e -c filebeat.yml",0
  • 启动,双击脚本startFilebeat.vbs

3.4、grafana查看日志

用grafana查看日志,可以根据自己的删选条件(关键字、时间等)选择查询响应的日志信息,具体如图





第四节、自定义监控

自定义监控可以根据自己编写的脚本,把需要监控的监控指标发送到pushgateway上,最后存储在promethues,使用grafana查看。

4.1、pushgateway

1、部署pushgateway

tar -xvf pushgateway-1.4.2.linux-amd64.tar.gz
cd pushgateway-1.4.2.linux-amd64/

启动

nohup ./pushgateway --web.listen-address=:48888 1>nohup.log 2>&1 &

2、promethues集成pushgateway

  • 编辑配置文件

    vi prometheus.yml
  - job_name: 'pushgateway'
static_configs:
- targets: [‘192.168.10.10:48888']
labels:
instance: pushgateway
  • 重启prometheus
nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:49800 1>nohup.log 2>&1 &

提示:停掉prometheus,再次启动

4.2、监控jvm

1、编写监控jvm脚本并运行

编写脚本

vi jvm_stat_exporter.sh
!# /bin/ksh
echo "start ..."
#JAVA_PROCESS_LIST=`jps | grep -v " Jps$" | grep -v " Jstat$"`
#echo $JAVA_PROCESS_LIST
HOST_IP=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v 192.168|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
#echo "$HOST_IP"
push_jvm_stat()
{
line=$1
#echo $line
PID=`echo $line | cut -d ' ' -f 1`
PNAME=`echo $line | cut -d ' ' -f 2`
#echo "PID:$PID,HOST_IP:$HOST_IP,PNAME:$PNAME" GC_LINE=`jstat -gc $PID | tail -1`
#echo "$GC_LINE"
# S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
# S0C
S0C=`echo $GC_LINE | cut -d ' ' -f 1`
S1C=`echo $GC_LINE | cut -d ' ' -f 2`
S0U=`echo $GC_LINE | cut -d ' ' -f 3`
S1U=`echo $GC_LINE | cut -d ' ' -f 4`
EC=`echo $GC_LINE | cut -d ' ' -f 5`
EU=`echo $GC_LINE | cut -d ' ' -f 6`
OC=`echo $GC_LINE | cut -d ' ' -f 7`
OU=`echo $GC_LINE | cut -d ' ' -f 8`
MC=`echo $GC_LINE | cut -d ' ' -f 9`
MU=`echo $GC_LINE | cut -d ' ' -f 10`
CCSC=`echo $GC_LINE | cut -d ' ' -f 11`
CCSU=`echo $GC_LINE | cut -d ' ' -f 12`
YGC=`echo $GC_LINE | cut -d ' ' -f 13`
YGCT=`echo $GC_LINE | cut -d ' ' -f 14`
FGC=`echo $GC_LINE | cut -d ' ' -f 15`
FGCT=`echo $GC_LINE | cut -d ' ' -f 16`
GCT=`echo $GC_LINE | cut -d ' ' -f 17`
#echo $S0C $S1C $S0U $S1U $EC $EU $OC $OU $MC $MU $CCSC $CCSU $YGC $YGCT $FGC $FGCT $GCT
#echo "******* $HOST_IP $PNAME *******"
cat <<EOF | curl --data-binary @- http://192.168.10.10:48888/metrics/job/test_jvm_job/instance/${HOST_IP}_$PNAME
# TYPE jvm_s0c gauge
jvm_s0c{processname="$PNAME",hostip="$HOST_IP"} $S0C
# TYPE jvm_s1c gauge
jvm_s1c{processname="$PNAME",hostip="$HOST_IP"} $S1C
# TYPE jvm_s0u gauge
jvm_s0u{processname="$PNAME",hostip="$HOST_IP"} $S0U
# TYPE jvm_s1u gauge
jvm_s1u{processname="$PNAME",hostip="$HOST_IP"} $S1U
# TYPE jvm_ec gauge
jvm_ec{processname="$PNAME",hostip="$HOST_IP"} $EC
# TYPE jvm_eu gauge
jvm_eu{processname="$PNAME",hostip="$HOST_IP"} $EU
# TYPE jvm_oc gauge
jvm_oc{processname="$PNAME",hostip="$HOST_IP"} $OC
# TYPE jvm_ou gauge
jvm_ou{processname="$PNAME",hostip="$HOST_IP"} $OU
# TYPE jvm_mc gauge
jvm_mc{processname="$PNAME",hostip="$HOST_IP"} $MC
# TYPE jvm_mu gauge
jvm_mu{processname="$PNAME",hostip="$HOST_IP"} $MU
# TYPE jvm_ccsc gauge
jvm_ccsc{processname="$PNAME",hostip="$HOST_IP"} $CCSC
# TYPE jvm_ccsu gauge
jvm_ccsu{processname="$PNAME",hostip="$HOST_IP"} $CCSU
# TYPE jvm_ygc counter
jvm_ygc{processname="$PNAME",hostip="$HOST_IP"} $YGC
# TYPE jvm_ygct counter
jvm_ygct{processname="$PNAME",hostip="$HOST_IP"} $YGCT
# TYPE jvm_fgc counter
jvm_fgc{processname="$PNAME",hostip="$HOST_IP"} $FGC
# TYPE jvm_fgct counter
jvm_fgct{processname="$PNAME",hostip="$HOST_IP"} $FGCT
# TYPE jvm_gct counter
jvm_gct{processname="$PNAME",hostip="$HOST_IP"} $GCT
EOF
# echo "******* $PNAME 2 *******"
}
while [ 1 = 1 ]
do
jps |grep -v " Jps$" | grep -v " Jstat$" | while read line_jps
do
push_jvm_stat "$line_jps"
done
echo "`date` pushed" > ./lastpushed.log
sleep 5
done

授权并运行脚本

chmod +x  jvm_stat_exporter.sh
./jvm_stat_exporter.sh

2、查看jvm指标

  • 在pushgateway查看如下图

  • 在grafana查看监控指标如下

第五节、监控服务

5.1、部署Blackbox Exporter

1、安装

tar -xvf blackbox_exporter-0.19.0.linux-amd64.tar.gz
cd blackbox_exporter-0.19.0.linux-amd64/

2、启动

nohup ./blackbox_exporter &

3、访问

浏览器访问http://192.168.10.10:9115

5.2、监控端口

1、配置promethues集成blackbox_exporter监控端口22

  - job_name: 'prometheus_port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.10.14:22]
labels:
instance: port_22_ssh
hostip: 192.168.10.14
group: 'tcp'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.10.10:9115

2、重启prometheus

nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:49800 1>nohup.log 2>&1 &

提示:停掉prometheus,再次启动

5.3、监控http

1、配置promethues集成blackbox_exporter监控http

  - job_name: web_status
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://192.168.10.15:8080]
labels:
instance: starweb
hostip: 192.168.10.15
group: 'web' relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.10.10:9115

2、重启prometheus

nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:49800 1>nohup.log 2>&1 &

提示:停掉prometheus,再次启动

FAQ

1、loki接收不到日志或者promethues获取不到监控指标登录

解决办法:

查看防火墙规则是否放开,或者直接关闭防火墙(生产环境不建议关闭防火墙)

prometheus监控实战的更多相关文章

  1. Prometheus监控实战day1-监控简介

    福利 Prometheus监控实战PDF电子书下载 链接:https://pan.baidu.com/s/1QH4Kvha5g70OhYQdp4YsfQ 提取码:oou5 若你喜欢该资料,请购买该资料 ...

  2. prometheus监控实战--基础

    1.简介 prometheus就是监控系统+TSDB(时间序列数据库),通过pull方式从exporter获取时间序列数据,存入本地TSDB,被监控端需安装exporter作为http端点暴露指标数据 ...

  3. Prometheus监控实战应用

    目录 1.Prometheus的主要特征及概述 2.普罗米修斯原理架构图 3.下载安装启动Prometheus 4.web客户端操作 5.默认图像 6.目录解释 7.配置文件 8.监控指标 8.1.监 ...

  4. Prometheus监控实战day2——监控主机和容器

    Prometheus使用exporter工具来暴露主机和应用程序上的指标,目前有很多exporter可供利用.对于收集各种主机指标数据(包括CPU.内存和磁盘),我们使用Node Exporter即可 ...

  5. 监控实战Prometheus+Grafana

    这期的分享是监控实战,其实不想写这篇的,因为网上相关的文章也挺多的,但是出于光说不练都是假把式,而且也想告诉你:当帅气的普罗米修斯(Prometheus)遇到高颜值的格拉法纳(Grafana)究竟会擦 ...

  6. K8S(13)监控实战-部署prometheus

    k8s监控实战-部署prometheus 目录 k8s监控实战-部署prometheus 1 prometheus前言相关 1.1 Prometheus的特点 1.2 基本原理 1.2.1 原理说明 ...

  7. prometheus和granfana企业级监控实战v5

    文件地址:https://files.cnblogs.com/files/sanduzxcvbnm/prometheus和granfana企业级监控实战v5.pdf

  8. Docker 监控实战

    如今,越来越多的公司开始使用 Docker 了,现在来给大家看几组数据: 2 / 3 的公司在尝试了 Docker 后最终使用了它 也就是说 Docker 的转化率达到了 67%,而转化市场也控制在 ...

  9. Prometheus监控学习笔记之教程推荐

    最近学习K8S和基于容器的监控,发现了如下的教程质量不错,记录下来以备参考 1. K8S最佳实战(包括了K8S的Prometheus监控和EFK日志搜集) https://jimmysong.io/k ...

随机推荐

  1. PHP几个数组函数

    array_intersect比较两个数组的键值,并返回交集: <?php $a1=array("a"=>"red","b"=& ...

  2. 关于又拍云免费cdn全网加速服务的长期评测(各种踩坑)

    原文转载自「刘悦的技术博客」 ( https://v3u.cn/a_id_128 ) 妇孺皆知,前端优化中最重要的优化手段之一就是cdn加速,所谓cdn加速就是采用更多的缓存服务器(CDN边缘节点), ...

  3. google nexus5x 刷机抓包逆向环境配置(一)

    本文仅供学习交流使用,如侵立删! google nexus5x 刷机抓包逆向环境配置(一) 操作环境 nexus5x kaliLinux win10 准备 官方工具包官方下载地址:https://dl ...

  4. FutureTask源码深度剖析

    FutureTask源码深度剖析 前言 在前面的文章自己动手写FutureTask当中我们已经仔细分析了FutureTask给我们提供的功能,并且深入分析了我们该如何实现它的功能,并且给出了使用Ree ...

  5. Redis入门到实战

    一.Redis基础 Redis所有的命令都可以去官方网站查看 1.基本命令 keys * 查找所有符合给定模式pattern(正则表达式)的 key .可以进行模糊匹配 del key1,key2,. ...

  6. Express 使用 Cookie

    在使用 Cookie 之前,需要给 Express 加载中间件,cookie-parser: npm i cookie-parser Express 使用中间件: import express fro ...

  7. 给博客添加个充电按钮(仿B站)

    今天我准备吧B站的充电按钮移植到本博客,开始- 上代码: HTML <html> <head> <link href="./space.8.f69f7d6f8f ...

  8. identity4 系列————持久化配置篇[五]

    前言 上面已经介绍了3个例子了,并且介绍了如何去使用identity. 但是在前面的例子中,我们使用的都是在内存中操作,那么正式上线可能需要持久到数据库中. 这里值得说明的是,并不一定一定要持久化到数 ...

  9. 【HTML】学习路径1-网页基本结构-标签基本语法

    本系列将学习最基础的web前端知识: HTML---CSS---JavaScripts---jQuery 四大部分学习完以后再进入到JavaWeb的知识.(后端) 然后再学习SpringBoot技术. ...

  10. html、css实现导航栏5种常用下拉效果

    实现的效果:鼠标移入按钮时按钮中的内容就会出现,分别展示不同的出现效果.效果难点:不使用JavaScript,那这个效果的难点就是在于:hover伪类的掌控,以及考验对html的结构掌握. 1. ht ...