当前位置: 首页 > news >正文

Prometheus 的应用服务发现及黑河部署等

目录

  promtool检查语法

部署Prometheus Server

 检查语法是否规范

部署node-exporter

部署Consul

直接请求API进行服务注册

使用register命令注册服务(建议使用) 单个和多个注册,多个后面多加了s

在Prometheus上做consul的服务发现

部署Consul Exporter

在Prometheus上做Consul Exporter的服务发现 因为Prometheus是对Consul做的服务发现所以

部署MySQL Exporter

在Prometheus上做Consul Exporter的服务发现

部署nginx Exporter

 在Prometheus上做Consul Exporter的服务发现

在Prometheus上做tomcat

tomcat允许远程登录

 tomcat下载及扩充支持相应的功能

 注册到consul上面去及Prometheus上做服务发现

署Blackbox Exporter 取决于黑盒监控

在Prometheus里面做黑河发现 


  1. Record Rule: 保存在配置文件中,由Prometheus Server周期去评估,结果会生成一个时序数据,回存至TSDB,并支持查询
  2.   Alert Rule: 布尔型告警表达式,保存在配置文件中,由Prometheus Server周期去评估,结果会生成一个时序数据,服务状态转换时,即会生成告警;
  • 布尔型告警表达式:监控指标的值或其他相关条件来判断系统是否处于异常状态,并触发相应的告警。

record 记录规则,

  • 当Prometheus里面用promQL写的规则执行文件,执行完成时,如果恰巧是grafana所需要的文件,就会直接在这里读取,而不是再从TSDB里面重新读取,从而省去大量IO

 查询持久化:
    把查询语句的执行结果长期保存; 

  记录规则:保存于配置文件,由Server自动在后台周期性执行; 
    evaluation_interval: 15s 

  promtool检查语法

 ./promtool check config prometheus.yml    #  promtool 可以用这命令检查语法

 /usr/local/consul services register server02.json   注册consul的发现表

/usr/local/consul services dederegister -id server02.json  注销consul的发现表

https://prometheus.io/download/  官网

部署Prometheus Server

下载程序包,以2.40.2版为例:

curl -LO https://github.com/prometheus/prometheus/releases/download/v2.40.2/prometheus-2.40.2.linux-amd64.tar.gz

展开程序包:

tar xf prometheus-2.40.2.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/prometheus-2.40.2.linux-amd64 /usr/local/prometheus

创建用户,并设定目录权限:

useradd -r prometheus
mkdir /usr/local/prometheus/data
chown -R prometheus.prometheus /usr/local/prometheus/data

创建Systemd Unitfile,保存于/usr/lib/systemd/system/prometheus.service文件中:

[Unit]
Description=Monitoring system and time series database
Documentation=https://prometheus.io/docs/introduction/overview/[Service]
Restart=always
User=prometheus
EnvironmentFile=-/etc/default/prometheus
ExecStart=/usr/local/prometheus/prometheus \--config.file=/usr/local/prometheus/prometheus.yml \--storage.tsdb.path=/usr/local/prometheus/data \--web.console.libraries=/usr/share/prometheus/console_libraries \--web.enable-lifecycle \$ARGS
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
LimitNOFILE=8192[Install]
WantedBy=multi-user.target

如有必要,可创建环境配置文件/etc/default/prometheus,通过变量ARGS为prometheus指定启动参数

启动服务:

systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service

验证监听的端口,并测试访问其暴露的指标

ss -tnlp | grep '9090'
curl localhost:9090/metrics

修改配置后的重载命令:

curl -XPOST http://localhost:9090/-/reload

基于文件的服务发现

[root@rocky8 prometheus]#mkdir targets 
[root@rocky8 targets]#vim nodes-linux.yml    #以yml结尾就行,后续容易在Prometheus里面指定
- targets:     #可以名字- 10.0.0.18:9100     - 10.0.0.8:9100labels:   #标签。可以多个app: nede-exporter[root@rocky8 prometheus]#vim prometheus.yml- job_name: "node_exporter"metrics_path: '/metrics'  #默认定义的输出路径scheme: 'http'file_sd_configs:          #基于文件发现- files:- targets/nodes-*.yml   #可以通配符refresh_interval: 2m
curl -XPOST http://localhost:9090/-/reload   定义完成之后可以重启

 检查语法是否规范

[root@rocky8 prometheus]#./promtool check config ./prometheus.yml   可以检查语法是否规范

部署node-exporter

提示:每个主机节点上均应该部署node-exporter;

下载程序包,以1.4.0版本为例:

curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz

展开程序包:

tar xf node_exporter-1.4.0.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/node_exporter-1.4.0.linux-amd64 /usr/local/node_exporter

创建用户,若prometheus用户已经存在,可略过该步骤:

useradd -r prometheus

创建Systemd Unitfile,保存于/usr/lib/systemd/system/node_exporter.service文件中:

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter \--collector.ntp \--collector.mountstats \--collector.systemd \--collector.ethtool \--collector.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always[Install]
WantedBy=multi-user.target

启动服务:

systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service

验证监听的端口,并测试访问其暴露的指标

ss -tnlp | grep '9100'
curl localhost:9100/metrics

部署Consul

组件功能:用于为Prometheus提供基于Consul进行服务发现的测试环境。

部署

下载Consul,以1.14.1版本为例:

curl -LO https://releases.hashicorp.com/consul/1.14.1/consul_1.14.1_linux_amd64.zip

展开程序包:

mkdir -p /usr/local/consul/{data,config}  #给consul 保存配置文件和数据的目录
unzip consul_1.14.1_linux_amd64.zip -d /usr/local/consul

创建用户,若consul用户已经存在,可略过该步骤:

useradd -r consul
chown consul.consul /usr/local/consul/{data,config}

创建Systemd Unitfile,保存于/usr/lib/systemd/system/consul.service文件中:

[Unit]
Description="HashiCorp Consul - A service mesh solution"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target[Service]
EnvironmentFile=-/etc/consul.d/consul.env
User=consul
Group=consul
ExecStart=/usr/local/consul/consul agent -dev -bootstrap \-config-dir /usr/local/consul/config \-data-dir /usr/local/consul/data \-ui \-log-level INFO \-bind 127.0.0.1 \-client 0.0.0.0
ExecReload=/bin/kill --signal HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target

启动服务:

systemctl daemon-reload
systemctl start consul.service
systemctl enable consul.service  #开机自动

直接请求API进行服务注册

列出已经注册的服务:

curl -XGET http://localhost:8500/v1/agent/services

获取某个特定服务的配置信息:

curl -XGET http://localhost:8500/v1/agent/service/<SERVICE_ID>

例如,下面定义了一个要注册的tomcat服务示例,它保存于tomcat.json文件中

{"id": "tomcat","name": "tomcat","address": "tomcat","port": 8080,"tags": ["tomcat"],"checks": [{"http": "http://tomcat:8080/metrics","interval": "5s"}]
}

我们可以使用类似如下命令完成服务注册。

curl -XPUT --data @tomcat.json http://localhost:8500/v1/agent/service/register

注销某个服务:

curl -XPUT http://localhost:8500/v1/agent/service/deregister/<SERVICE_ID>

使用register命令注册服务(建议使用) 单个和多个注册,多个后面多加了s

consul services register命令也可用于进行服务注册,只是其使用的配置格式与直接请求HTTP API有所不同。

-address=XXX 指明服务器地址,不指默认本地

-port=xx   指定服务的端口号

consul services register /path/to/pyload_file.json

注册单个服务时,使用service进行定义,注册多个服务时,使用services以列表格式进行定义。下面的示例定义了单个要注册的服务。

{"service": {"id": "tomcat","name": "tomcat","address": "tomcat","port": 8080,"tags": ["tomcat"],"checks": [{"http": "http://tomcat:8080/metrics","interval": "5s"}]}
}

下面的示例,以多个的服务的格式给出了定义。

{"services": [{"id": "tomcat","name": "tomcat","address": "tomcat","port": 8080,"tags": ["tomcat"],"checks": [{"http": "http://tomcat:8080/metrics","interval": "5s"}]}]
}

注销服务,也可以使用consul services deregister命令进行。

 consul services deregister -id <SERVICE_ID>

在Prometheus上做consul的服务发现

在consul上可以正常查到相关节点后,在Prometheus.yml上增加相关配置

  - job_name: "node_exporter"consul_sd_configs:- server: '10.0.0.8:8500'tags:- "node_exporter"     #只有consul里带有该标签的服务才会被 Prometheus 发现和监控refresh_interval: 1m[root@rocky8 prometheus]#curl -XPOST localhost:9090/-/reload  #重启

部署Consul Exporter

提示:仅需要为每个Consul实例部署consul-exporter,它负责将Consul的状态信息转为Prometheus兼容的指标格式并予以暴露。

下载程序包,以0.8.0版本为例:

curl -LO https://github.com/prometheus/consul_exporter/releases/download/v0.8.0/consul_exporter-0.8.0.linux-amd64.tar.gz

展开程序包:

tar xf consul_exporter-0.8.0.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/consul_exporter-0.8.0.linux-amd64 /usr/local/consul_exporter

创建用户,若consul用户已经存在,可略过该步骤:

useradd -r consul

创建Systemd Unitfile,保存于/usr/lib/systemd/system/consul_exporter.service文件中:

[Unit]
Description=consul_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target[Service]
Type=simple
User=consul
EnvironmentFile=-/etc/default/consul_exporter
# 具体使用时,若consul_exporter与consul server不在同一主机时,consul server要指向实际的地址;
ExecStart=/usr/local/consul_exporter/consul_exporter \--consul.server="http://localhost:8500" \--web.listen-address=":9107" \--web.telemetry-path="/metrics" \--log.level=info \$ARGS
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always[Install]
WantedBy=multi-user.target

启动服务:

systemctl daemon-reload
systemctl start consul_exporter.service
systemctl enable consul_exporter.service

在Prometheus上做Consul Exporter的服务发现 因为Prometheus是对Consul做的服务发现所以

Consul Exporter用于监控Consul万一consul崩了呢

[root@rocky8 services]#cat consul-exporter.json 
{"id": "consul_exporter","name": "consul_exporter.magedu.com","address": "prometheus.magedu.com","port": 9107,"tags": ["consul_exporter"],"checks": [{"http":"http://prometheus.magedu.com:9107/metrics","interval": "5s"}]
}[root@rocky8 prometheus]#vim prometheus.yml- job_name: "consul_exporter"consul_sd_configs:- server: '10.0.0.8'tags:- "consul_exporter"refresh_interval: 1m

 加入服务注册

curl -XPUT --data @consul-exporter.json http://localhost:8500/v1/agent/service/registercurl -XGET http://localhost:8500/v1/agent/services   查看

部署MySQL Exporter

提示:仅需要为每个MySQL Server实例部署mysql-exporter,它负责将MySQL Server的状态信息转为Prometheus兼容的指标格式并予以暴露。

下载程序包,以0.14.0版本为例:

curl -LO https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz

展开程序包:

tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/mysqld_exporter-0.14.0.linux-amd64 /usr/local/mysqld_exporter

创建用户,或mysql用户已经存在,可略过该步骤:

useradd -r mysql

创建Systemd Unitfile,保存于/usr/lib/systemd/system/mysqld_exporter.service文件中:

[Unit]
Description=consul_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target[Service]
Type=simple
User=mysql
EnvironmentFile=-/etc/default/mysqld_exporter
# 具体使用时,若mysql_exporter与mysql server不在同一主机时,mysql server要指向实际的地址;
# mysql_exporter连接mysql server使用的用户名和密码均为exporter,该用户要获得正确的授权;
Environment='DATA_SOURCE_NAME=exporter:exporter@(localhost:3306)'
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \--web.listen-address=":9104" \--web.telemetry-path="/metrics" \--collect.info_schema.innodb_tablespaces \--collect.info_schema.innodb_metrics \--collect.global_status \--collect.global_variables \--collect.slave_status \--collect.engine_innodb_status \$ARGS
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always[Install]
WantedBy=multi-user.target

在mysqld server上添加用户,并授权其能够加载mysql的信息并转换为指标输出。需要注意的是用户账号授权时使用的主机范围。

mysql> CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'exporter';
mysql> GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'exporter'@'localhost';
mysql> GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
mysql> FLUSH PRIVILEGES;

启动服务:

systemctl daemon-reload
systemctl start mysqld_exporter.service
systemctl enable mysqld_exporter.service

在Prometheus上做Consul Exporter的服务发现

[root@rocky8 services]#cat mysqld_exporter.json 
{"id": "mysqld_exporter","name": "mysqld_exporter.magedu.com","address": "prometheus.magedu.com","port": 9107,"tags": ["mysqld_exporter"],"checks": [{"http":"http://prometheus.magedu.com/metrics","interval": "5s"}]
}[root@rocky8 prometheus]#vim prometheus.yml- job_name: "mysqld_exporter"consul_sd_configs:- server: "10.0.0.8"tags:- "mysqld_exporter"refresh_interval: 1m

 加入服务注册

curl -XPUT --data @mysqld_exporter.json http://localhost:8500/v1/agent/service/registercurl -XGET http://localhost:8500/v1/agent/services   查看

部署nginx Exporter

基于镜像


version: '3.6'networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.107.0/24services:nginx:image: nginx:1.22.1volumes:   - ./nginx/stub_status-server.conf:/etc/nginx/conf.d/stub_status-server.conf:ro   #定义·文件夹networks:- monitoringexpose:- 8080- 80ports:- 80:80nginx-exporter:image: nginx/nginx-prometheus-exporter:0.11command:- '-nginx.scrape-uri=http://nginx:8080/stub_status'networks:- monitoringports:- '9113:9113'depends_on:- nginx
~              
[root@rocky8 nginx-and-exporter]#ls
docker-compose.yml  nginx
[root@rocky8 nginx-and-exporter]#vim docker-compose.yml 
[root@rocky8 nginx-and-exporter]#tree nginx/
nginx/
└── stub_status-server.conf0 directories, 1 file[root@rocky8 nginx-and-exporter]#cat nginx/stub_status-server.conf 
server {listen 8080;server_name localhost;
文件·location /stub_status {stub_status;access_log off;#allow 172.31.0.0/16;#deny all;}
}

启动

[root@rocky8 nginx-and-exporter]#docker-compose up

/usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core 

 在Prometheus上做Consul Exporter的服务发现

[root@rocky8 services]#/usr/local/consul/consul services register nginx-exporter.json  

curl -XGET http://localhost:8500/v1/agent/services   查看

[root@rocky8 services]#cat nginx-exporter.json 
{"service":{"id": "nginx_exporter","name": "nginx_exporter.magedu.com","address": "server02.magedu.com","port": 9113,"tags": ["nginx_exporter"],"checks": [{"http": "http://server02.magedu.com:9113/metrics","interval": "5s"}]}
}[root@rocky8 services]#cat prometheus.yml- job_name: "nginx_exporter"consul_sd_configs:- server: "10.0.0.8:8500"tags:- "nginx_exporter"refresh_interval: 1m

 [root@rocky8 prometheus]#curl -XPOST localhost:9090/-/reload  刷新在Prometheus上面查看

在Prometheus上做tomcat

[root@rocky8 tomcat-and-metrics]#ls
docker-compose.yml  tomcat
[root@rocky8 tomcat-and-metrics]#cat docker-compose.yml    #安装
version: '3.6'volumes:tomcat_webapps: {}networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.130.0/24services:tomcat:#image: tomcat:jdk11build:context: tomcatdockerfile: Dockerfile hostname: tomcat.magedu.comexpose:- 8080ports:- 8080:8080volumes:- tomcat_webapps:/usr/local/tomcat/webapps- ./tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xmlnetworks:- monitoringenvironment:TZ: Asia/Shanghai
[root@rocky8 tomcat-and-metrics]#cd tomcat/[root@rocky8 tomcat]#ls
context.xml  Dockerfile  sources.list  tomcat-users.xml[root@rocky8 tomcat]#cat tomcat-users.xml     #tomcat账户配置
<?xml version="1.0" encoding="UTF-8"?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"version="1.0">
<!--By default, no user is included in the "manager-gui" role requiredto operate the "/manager/html" web application.  If you wish to use this app,you must define such a user - the username and password are arbitrary.Built-in Tomcat manager roles:- manager-gui    - allows access to the HTML GUI and the status pages- manager-script - allows access to the HTTP API and the status pages- manager-jmx    - allows access to the JMX proxy and the status pages- manager-status - allows access to the status pages onlyThe users below are wrapped in a comment and are therefore ignored. If youwish to configure one or more of these users for use with the manager webapplication, do not forget to remove the <!.. ..> that surrounds them. Youwill also need to set the passwords to something appropriate.
-->
<!--<user username="admin" password="<must-be-changed>" roles="manager-gui"/><user username="robot" password="<must-be-changed>" roles="manager-script"/>
-->
<!--The sample user and role entries below are intended for use with theexamples web application. They are wrapped in a comment and thus are ignoredwhen reading this file. If you wish to configure these users for use with theexamples web application, do not forget to remove the <!.. ..> that surroundsthem. You will also need to set the passwords to something appropriate.
-->
<!--<role rolename="tomcat"/><role rolename="role1"/><user username="tomcat" password="<must-be-changed>" roles="tomcat"/><user username="both" password="<must-be-changed>" roles="tomcat,role1"/><user username="role1" password="<must-be-changed>" roles="role1"/>
--><role rolename="manager-gui"/><role rolename="manager-script"/><user username="tomcat" password="magedu.com" roles="manager-gui,manager-script"/>
</tomcat-users>

tomcat允许远程登录

[root@rocky8 tomcat]#cat context.xml   允许远程登录
<?xml version="1.0" encoding="UTF-8"?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" ><CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"sameSiteCookies="strict" />
<!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
--><Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

 tomcat的镜像仓库地址

[root@rocky8 tomcat]#cat sources.list 
deb https://repo.huaweicloud.com/debian/ bullseye main non-free contrib
deb-src https://repo.huaweicloud.com/debian/ bullseye main non-free contrib
deb https://repo.huaweicloud.com/debian-security/ bullseye-security main
deb-src https://repo.huaweicloud.com/debian-security/ bullseye-security main
deb https://repo.huaweicloud.com/debian/ bullseye-updates main non-free contrib
deb-src https://repo.huaweicloud.com/debian/ bullseye-updates main non-free contrib
deb https://repo.huaweicloud.com/debian/ bullseye-backports main non-free contrib
deb-src https://repo.huaweicloud.com/debian/ bullseye-backports main non-free contrib

 tomcat下载及扩充支持相应的功能

[root@rocky8 tomcat]#cat Dockerfile 
FROM tomcat:9.0-jdk17-openjdk-slimADD ./sources.list /etc/apt/sources.listENV TOMCAT_SIMPLECLIENT_VERSION=0.12.0
ENV TOMCAT_EXPORTER_VERSION=0.0.15RUN apt-get update && apt-get install -y curl && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient-${TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient-${TOMCAT_SIMPLECLIENT_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_common/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_common-${TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_common-${TOMCAT_SIMPLECLIENT_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_hotspot/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_hotspot-${TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_hotspot-${TOMCAT_SIMPLECLIENT_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_servlet/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_servlet-${TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_servlet-${TOMCAT_SIMPLECLIENT_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=io/prometheus/simpleclient_servlet_common/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_servlet_common-${TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_servlet_common-${TOMCAT_SIMPLECLIENT_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=nl/nlighten/tomcat_exporter_client/${TOMCAT_EXPORTER_VERSION}/tomcat_exporter_client-${TOMCAT_EXPORTER_VERSION}.jar --output /usr/local/tomcat/lib/tomcat_exporter_client-${TOMCAT_EXPORTER_VERSION}.jar && \curl -v --fail --location https://search.maven.org/remotecontent?filepath=nl/nlighten/tomcat_exporter_servlet/${TOMCAT_EXPORTER_VERSION}/tomcat_exporter_servlet-${TOMCAT_EXPORTER_VERSION}.war --output /usr/local/tomcat/webapps/metrics.warRUN mv /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps/
ADD ./context.xml /usr/local/tomcat/webapps/manager/META-INF/context.xml

 注册到consul上面去及Prometheus上做服务发现

[root@rocky8 services]#/usr/local/consul/consul services register tomcat.json 
Node name "rocky8.wang.org" will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
Registered service: tomcat.magedu.com[root@rocky8 services]#cat tomcat.json 
{"service":{"id": "tomcat","name": "tomcat.magedu.com","address": "server02.magedu.com","port": 8080,"tags": ["tomcat"],"checks": [{"http": "http://server02.magedu.com:8080/metrics","interval": "5s"}]}
}[root@rocky8 prometheus]#cat prometheus.yml- job_name: "tomcat"consul_sd_configs:- server: "10.0.0.8:8500"tags:- "tomcat"refresh_interval: 1m[root@rocky8 prometheus]#curl -XPOST localhost:9090/-/reload   重新加载

署Blackbox Exporter 取决于黑盒监控

提示:仅需要部署的Blackbox Exporter实例数据,取决于黑盒监控的任务量及节点的可用资源。

[root@rocky8 blackbox-exporter]#cat configs/blackbox.yml 
modules:# https://github.com/prometheus/blackbox_exporter/blob/master/example.ymlhttp_2xx:prober: httptimeout: 5shttp:valid_http_versions: - "HTTP/1.1"- "HTTP/2"valid_status_codes: []  # Defaults to 2xxenable_http2: falsemethod: GETno_follow_redirects: false# fail_if_ssl为true时,表示如果站点启用了SSL则探针失败,反之成功; # fail_if_not_ssl刚好相反;fail_if_ssl: falsefail_if_not_ssl: false#  fail_if_body_matches_regexp, fail_if_body_not_matches_regexp, fail_if_header_matches, fail_if_header_not_matches#  可以定义一组正则表达式,用于验证HTTP返回内容是否符合或者不符合正则表达式的内容fail_if_body_matches_regexp:- "Could not connect to database"tls_config:insecure_skip_verify: falsepreferred_ip_protocol: "ip4" # defaults to "ip6"http_with_proxy:prober: httphttp:proxy_url: "http://127.0.0.1:3128"skip_resolve_phase_with_proxy: truehttp_post_2xx:prober: httptimeout: 5shttp:method: POSTheaders:Content-Type: application/jsonbody: '{}'http_basic_auth_example:prober: httptimeout: 5shttp:method: POSTheaders:Host: "login.example.com"basic_auth:username: "username"password: "mysecret"http_custom_ca_example:prober: httphttp:method: GETtls_config:ca_file: "/certs/my_cert.crt"http_gzip:prober: httphttp:method: GETcompression: gziphttp_gzip_with_accept_encoding:prober: httphttp:method: GETcompression: gzipheaders:Accept-Encoding: gziptls_connect:prober: tcptimeout: 5stcp:tls: truedns_udp_example:prober: dnstimeout: 5sdns:query_name: "www.prometheus.io"query_type: "A"valid_rcodes:- NOERRORvalidate_answer_rrs:fail_if_matches_regexp:- ".*127.0.0.1"fail_if_all_match_regexp:- ".*127.0.0.1"fail_if_not_matches_regexp:- "www.magedu.com.\t300\tIN\tA\t127.0.0.1"fail_if_none_matches_regexp:- "127.0.0.1"validate_authority_rrs:fail_if_matches_regexp:- ".*127.0.0.1"validate_additional_rrs:fail_if_matches_regexp:- ".*127.0.0.1"
[root@rocky8 blackbox-exporter]#ls
configs  docker-compose.yml
[root@rocky8 blackbox-exporter]#cat docker-compose.yml 
version: '3.6'networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.136.0/24services:blackbox_exporter:image: prom/blackbox-exporter:v0.24.0volumes:- ./configs/:/etc/blackboxexporter/command:- '--config.file=/etc/blackboxexporter/blackbox.yml'networks:- monitoringports:- 9115:9115

在Prometheus里面做黑河发现 

[root@rocky8 prometheus]#cat prometheus.yml# Blackbox Exporter- job_name: 'blackbox'metrics_path: /probeparams:module: [http_2xx]  # Look for a HTTP 200 response.static_configs:- targets:- www.magedu.com- www.google.comrelabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]target_label: instance- target_label: __address__replacement: "10.0.0.18:9115"  # Blackbox exporter.- target_label: regionreplacement: "remote"[root@rocky8 prometheus]#curl -XPOST localhost:9090/-/reload  #加载

相关文章:

Prometheus 的应用服务发现及黑河部署等

目录 promtool检查语法 部署Prometheus Server 检查语法是否规范 部署node-exporter 部署Consul 直接请求API进行服务注册 使用register命令注册服务&#xff08;建议使用&#xff09; 单个和多个注册&#xff0c;多个后面多加了s 在Prometheus上做consul的服务发现 部署…...

JAVA SE -- 第十二天

&#xff08;全部来自“韩顺平教育”&#xff09; 常用类 一、包装类 1、包装类的分类 ①针对八种基本数据类型相应的引用类型--包装类 ②有了类的特点&#xff0c;就可以调用类中的方法 ③ 基本数据类型包装类booleanBooleancharCharacterbyteByteshortShortintInteger…...

实战:工作中对并发问题的处理

大家好&#xff0c;我是 方圆。最近在接口联调时发生了数据并发修改问题&#xff0c;我想把这个问题讲解一下&#xff0c;并把当时提出的解决方案进行实现&#xff0c;希望它能在大家以后在遇到同样的问题时提供一些借鉴和思考的方向。原文还是收录在我的 Github: enthusiasm 中…...

腾讯云Cloud Studio:基于Claude快速完成Excel工资自动核算

目录 1 什么是Cloud Studio&#xff1f;2 注册与代码管理2.1 账号注册2.2 Git关联 3 实战&#xff1a;Excel工资自动核算3.1 创建项目与配置3.2 “念咒师”Claude GPT3.3 代码编写与运行 1 什么是Cloud Studio&#xff1f; Cloud Studio是腾讯云为开发者提供的一个基于浏览器的…...

Spring Boot OAuth2 快速入门示例

系统要求 Spring Authorization Server 需要JDK1.8及以上版本。 项目搭建 使用在线项目初始化器 https://start.spring.io/ 生成项目[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ljKbMI4H-1690726855433)(images/screenshot_1690602511482.png)…...

MethodInterceptor

目录 1 MethodInterceptor 1.1 HandleSync 1.2 HandleException 1.3 /// This will be called via Reflection MethodInterceptor HandleSync private void HandleSync(IReadOnlyList<MethodFilterAttribute> filterAttributes, IReadOnlyList<ExceptionFilte…...

PID模块化__以stm32直流电机速度为例

文章目录 前言一、相关PID源码.c.h 二、如何使用1.创建变量2.初始化3.运算4.修改pid参数 总结 前言 本篇使用到的基于这个STM32CubeMX 直流电机PID速度控制、HAL库、cubemx、PID、速度控制、增量式 由于上次使用的pid没有模块化&#xff0c;当多出使用pid的时候就会很麻烦 所以…...

Java ~ Collection/Executor ~ DelayQueue【总结】

前言 文章 相关系列&#xff1a;《Java ~ Collection【目录】》&#xff08;持续更新&#xff09;相关系列&#xff1a;《Java ~ Executor【目录】》&#xff08;持续更新&#xff09;相关系列&#xff1a;《Java ~ Collection/Executor ~ DelayQueue【源码】》&#xff08;学…...

前端高级面试题-安全相关

1 XSS 跨⽹站指令码&#xff08;英语&#xff1a; Cross-site scripting &#xff0c;通常简称为&#xff1a; XSS &#xff09;是⼀种⽹站应⽤程式的安全漏洞攻击&#xff0c;是代码注⼊的⼀种。 它允许恶意使⽤者将程式码注⼊到⽹⻚上&#xff0c;其他使⽤者在观看⽹⻚时就会…...

【前缀和】560.和为 K 的子数组

Halo&#xff0c;这里是Ppeua。平时主要更新C&#xff0c;数据结构算法&#xff0c;Linux与ROS…感兴趣就关注我bua&#xff01; 和为K的子数组 题目:示例:题解&#xff1a;解法一:解法二: 题目: 示例: 题解&#xff1a; 解法一: 暴力解法:我们很容易想到通过两个for循环去遍…...

【Docker】安全及日志管理

安全及日志管理 Docker 安全及日志管理一&#xff1a;Docker 容器与虚拟机的区别1. 隔离与共享2. 性能与损耗 二&#xff1a;Docker 存在的安全问题1.Docker 自身漏洞2.Docker 源码问题 三&#xff1a;Docker 架构缺陷与安全机制1. 容器之间的局域网攻击2. DDoS 攻击耗尽资源3.…...

基于x-scan扫描线的3D模型渲染算法

基于x-scan算法实现的z-buffer染色。c#语言&#xff0c;.net core framework 3.1运行。 模型是读取3D Max的obj模型。 x-scan算法实现&#xff1a; public List<Vertex3> xscan() {List<Vertex3> results new List<Vertex3>();SurfaceFormula formula g…...

LeetCode36.Valid-Sudoku<有效的数独>

题目&#xff1a; 思路&#xff1a; 这题并不难&#xff0c;它类似于N皇后问题。在N皇后问题中&#xff0c;行&#xff0c;列&#xff0c;对角线&#xff0c;写对角线&#xff0c;都不能出现连续的皇后。 本题类似&#xff0c;不过他是行&#xff0c;列&#xff0c;还有一个B…...

Linux中的pause函数

2023年7月29日&#xff0c;周六上午 函数原型 在Linux中&#xff0c;pause()函数用于使当前进程暂停执行&#xff0c;直到接收到一个信号。 #include <unistd.h>int pause(void);pause()函数不接受任何参数。 通常&#xff0c;pause()函数用于编写简单的信号处理程序&…...

CommonCollections6链分析

前面和CC1一样 优点是不限制jdk版本和cc的版本 先开一个ChainedTransformer 然后创LazyMap 我们顺便执行一下避免上面写错 能弹计算器 没问题 后面就是CC6不同的地方了 我们需要一个TiedMapEntry 因为需要一个类调用了get方法 在TiedMapEntry的getValue()方法中调用了get()…...

优化基于tcp,socket的ftp文件传输程序

原始程序&#xff1a; template_ftp_server_old.py&#xff1a; import socket import json import struct import os import time import pymysql.cursorssoc socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST 192.168.31.111 PORT 4101 soc.bind((HOST,PORT)) p…...

MySQL 数据库 【增删查改(二)】

目录 一、表的设计 1、一对一 2、一对多 3、多对多 二、新增 三、查询 1、聚合查询 &#xff08;1&#xff09;聚合函数&#xff1a; &#xff08;2&#xff09; group by 子句 &#xff08;3&#xff09;having 2、联合查询 (1)内连接 (2)外连接 (3)自链接 (4)…...

力扣 -- 978. 最长湍流子数组

一、题目 二、解题步骤 下面是用动态规划的思想解决这道题的过程&#xff0c;相信各位小伙伴都能看懂并且掌握这道经典的动规题目滴。 三、参考代码 class Solution { public:int maxTurbulenceSize(vector<int>& nums) {int nnums.size();vector<int> f(n);…...

甘特图 Dhtmlx Gantt

介绍 在一些任务计划、日程进度等场景中我们会使用到甘特图&#xff0c;Dhtmlx Gantt 对于甘特图的实现支持很友好&#xff0c;文档API介绍全面&#xff0c;虽然增强版的收费&#xff0c;但免费版的足以够用。 官网&#xff1a;https://docs.dhtmlx.com/gantt/ 安装dhtml gannt…...

iOS 应用上架流程详解

iOS 应用上架流程详解 欢迎来到我的博客&#xff0c;今天我将为大家分享 iOS 应用上架的详细流程。在这个数字化时代&#xff0c;移动应用已经成为了人们生活中不可或缺的一部分&#xff0c;而 iOS 平台的 App Store 则是开发者们发布应用的主要渠道之一。因此&#xff0c;了解…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

边缘计算医疗风险自查APP开发方案

核心目标:在便携设备(智能手表/家用检测仪)部署轻量化疾病预测模型,实现低延迟、隐私安全的实时健康风险评估。 一、技术架构设计 #mermaid-svg-iuNaeeLK2YoFKfao {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg…...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

Springcloud:Eureka 高可用集群搭建实战(服务注册与发现的底层原理与避坑指南)

引言&#xff1a;为什么 Eureka 依然是存量系统的核心&#xff1f; 尽管 Nacos 等新注册中心崛起&#xff0c;但金融、电力等保守行业仍有大量系统运行在 Eureka 上。理解其高可用设计与自我保护机制&#xff0c;是保障分布式系统稳定的必修课。本文将手把手带你搭建生产级 Eur…...

Python爬虫(一):爬虫伪装

一、网站防爬机制概述 在当今互联网环境中&#xff0c;具有一定规模或盈利性质的网站几乎都实施了各种防爬措施。这些措施主要分为两大类&#xff1a; 身份验证机制&#xff1a;直接将未经授权的爬虫阻挡在外反爬技术体系&#xff1a;通过各种技术手段增加爬虫获取数据的难度…...

Linux-07 ubuntu 的 chrome 启动不了

文章目录 问题原因解决步骤一、卸载旧版chrome二、重新安装chorme三、启动不了&#xff0c;报错如下四、启动不了&#xff0c;解决如下 总结 问题原因 在应用中可以看到chrome&#xff0c;但是打不开(说明&#xff1a;原来的ubuntu系统出问题了&#xff0c;这个是备用的硬盘&a…...

CMake控制VS2022项目文件分组

我们可以通过 CMake 控制源文件的组织结构,使它们在 VS 解决方案资源管理器中以“组”(Filter)的形式进行分类展示。 🎯 目标 通过 CMake 脚本将 .cpp、.h 等源文件分组显示在 Visual Studio 2022 的解决方案资源管理器中。 ✅ 支持的方法汇总(共4种) 方法描述是否推荐…...

七、数据库的完整性

七、数据库的完整性 主要内容 7.1 数据库的完整性概述 7.2 实体完整性 7.3 参照完整性 7.4 用户定义的完整性 7.5 触发器 7.6 SQL Server中数据库完整性的实现 7.7 小结 7.1 数据库的完整性概述 数据库完整性的含义 正确性 指数据的合法性 有效性 指数据是否属于所定…...

Python Ovito统计金刚石结构数量

大家好,我是小马老师。 本文介绍python ovito方法统计金刚石结构的方法。 Ovito Identify diamond structure命令可以识别和统计金刚石结构,但是无法直接输出结构的变化情况。 本文使用python调用ovito包的方法,可以持续统计各步的金刚石结构,具体代码如下: from ovito…...

比较数据迁移后MySQL数据库和OceanBase数据仓库中的表

设计一个MySQL数据库和OceanBase数据仓库的表数据比较的详细程序流程,两张表是相同的结构,都有整型主键id字段,需要每次从数据库分批取得2000条数据,用于比较,比较操作的同时可以再取2000条数据,等上一次比较完成之后,开始比较,直到比较完所有的数据。比较操作需要比较…...