第一节、环境和软件版本

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. Thymeleaf是什么?该如何使用。

    先了解Thymeleaf是什么 1. Thymeleaf 简介 Thymeleaf 是新⼀代 Java 模板引擎,与 Velocity.FreeMarker 等传统 Java 模板引擎不同,Thyme ...

  2. Python3的单元测试模块Mock与性能测试模块CProfile

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_92 我们知道写完了代码需要自己跑一跑进行测试,一个写好的程序如果连测试都没有就上到生产环境是不敢想象的,这么做的人不是太自信就是太 ...

  3. CF242E XOR on Segment

    CF242E XOR on Segment codeforces 洛谷 关于异或,无法运用懒标记实现区间异或: 可以像trie树一样拆位,将每个值拆成二进制数,对此建相应个数的线段树. 0 1与 0异 ...

  4. Dapr学习(4)之eShopOnDapr部署(Rancher2.63&k3s)

    本篇主要讲述一下github上基于Dapr实现的商城demo在(K8s or K3s)环境中的部署实践,本文环境基于k3s&rancher2.6.3 1.eShopOnDapr源代码及概述 源 ...

  5. OSSCore 开源解决方案介绍

    基于.NetCore的积木化服务框架,主要将常规解决方案进行进一步的抽象下沉形成相关基础可选框架单元(在Framework 目录),并在此基础上实现常规系统模块(在Modules 目录),如用户管理, ...

  6. 汇编/C/C++/MFC/JAVA/C# 进阶群103197177

    欢迎广大喜欢编程朋友加入进来.如果是大神请分享你的经验,带领广大小伙伴一起打怪升级得经验:如果是编程新人,那么这里是你不二的选择,分享,奉献是我们追求的目标:我们之中大部分是有一年多工作经验的热血编程 ...

  7. 通过cpu热插拔解决rcu stall的问题

    在linux 3.10环境一次故障处理中,发现有类似如下打印: NFO: rcu_sched_state detected stalls on CPUs/tasks: {15 } (detected ...

  8. 2-1 走进selenium新世界

    走进Selenium新世界 浏览器 Firefox Setup 35.0.1 安装完成后设置菜单栏 关闭浏览器自动更新 插件配置(必备武器) FireBug Firebug是firefox下的一个扩展 ...

  9. 简单创建一个SpringCloud2021.0.3项目(二)

    目录 1. 项目说明 1. 版本 2. 用到组件 3. 功能 2. 上一篇教程 3. 创建公共模块Common 4. 网关Gateway 1. 创建Security 2. Security登陆配置 3 ...

  10. electron 起步

    electron 起步 为什么要学 Electron,因为公司需要调试 electron 的应用. Electron 是 node 和 chromium 的结合体,可以使用 JavaScript,HT ...