b1gc8v 发表于 2024-10-10 17:09:45

运维(32) Prometheus+Grafana监控SpringBoot


    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/b3c924ed0e814303a0a5a51bed33337d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=F1kiX99ugUdO2HZ9ugh574djU0U%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1、</span>前言</h1>Prometheus:一个开源系统监控和警报工具包。Grafana:Go语言<span style="color: black;">研发</span>的开源数据可视化工具,<span style="color: black;">能够</span>做数据监控和数据统计,带有告警功能。Micrometer:收集Java性能数据<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2、</span>SpringBoot集成Micrometer</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1、pom.xml中引入依赖</h1>&lt;!-- micrometer:收集Java性能数据 --&gt;
    &lt;dependency&gt;
    &lt;groupId&gt;io.micrometer&lt;/groupId&gt;
    &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;
    &lt;/dependency&gt;<h1 style="color: black; text-align: left; margin-bottom: 10px;">2、application.yml配置</h1>server:
    port: 9200

    spring:
    application:
    name: demo

    management:
    endpoints:
    web:
    exposure:
    include: *
    metrics:
    tags:
    application: ${spring.application.name}<h1 style="color: black; text-align: left; margin-bottom: 10px;">3、Micrometer配置</h1>@Configuration
    public class MetricsConfig {

    @Bean
    MeterRegistryCustomizer&lt;MeterRegistry&gt; configurer(
    @Value("${spring.application.name}") String applicationName) {
    return (registry) -&gt; registry.config().commonTags("application", applicationName);
    }

    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">起步</span>应用,<span style="color: black;">拜访</span> http://127.0.0.1:9200/actuator/prometheus</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/20713bce66c248efbf52e8f7b67cfb92~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=dQTBtoHkfdoLoAxn2pxtFPw3hTA%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">3、</span><span style="color: black;">安排</span>Prometheus+Grafana</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/43e8a9e494b04effb7d6f68e22f97f53~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=eH7B2TAbFxJD4mBblLbZ%2FDX69d4%3D" style="width: 50%; margin-bottom: 20px;"></div># 准备
    git clone https://gitee.com/zhengqingya/docker-compose.git
    cd docker-compose/Liunx

    # `docker-compose-prometheus.yml` 需修改grafana中配置的mysql连接信息
    # `prometheus.yml` <span style="color: black;">自动</span>配置

    # 运行服务
    docker-compose -f docker-compose-prometheus.yml -p prometheus up -dgrafana<span style="color: black;">拜访</span><span style="color: black;">位置</span> ip<span style="color: black;">位置</span>:3000 默认登录账号<span style="color: black;">秘码</span>:admin/adminprometheus<span style="color: black;">拜访</span><span style="color: black;">位置</span>: ip<span style="color: black;">位置</span>:9090exporter<span style="color: black;">拜访</span><span style="color: black;">位置</span>: ip<span style="color: black;">位置</span>:9100/metrics<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/3efa2cf752d24d048c5379d8ce7d3c53~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=7pydSCfd7jSvNmyNnjGRCYtoyNM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>prometheus.yml配置需和springboot应用对应</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/571576e7371f4db788f28d888fdd05db~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=HDfiJvGaDG%2BEDJVw8carwP3UUnw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">4、</span>监控SpringBoot</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1、新增Prometheus数据源</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Configuration -&gt; Data sources -&gt; Add data source -&gt; Prometheus</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/4c9c432e9b7b4eda8bf5d3e55570e4e0~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=WPQ%2FxKYNQZjpIgdSiSwrpgoG9NM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/481c84ee764b4f35b189f0966b80c3a6~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=gVsUy%2FSnrc%2FR3kL9UNQwVi3xdv4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/95c1d977b4b7448db1521a6946716b5d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=klndi2%2F2YtM44shYZRWhiQLxxuI%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">2、导入Dashboard</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Create -&gt; Import</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">grafana面板资源 https://grafana.com/grafana/dashboards/4701</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/44518bbaebeb437298e18b233ded9169~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=HTEQjQppsIm4KYR81cxwxjyEM9g%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/0d5c437444364d4fa6c36e42b38fd944~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=%2BMM2uHpewzeztfn1I3pIqciQPzY%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/8a6f52e9562640feaf73d7dd0959307b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=3xlbmfTAwJNZsM6kdijlY8SuIdo%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">5、</span>邮件告警</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1、配置grafana.ini</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/38b61565447e4c60a2f7831fd83910bf~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=RgotJMA8%2BKZgnRovdZtGzdai%2Fuo%3D" style="width: 50%; margin-bottom: 20px;"></div>#################################### SMTP / Emailing ##########################
   
    # <span style="color: black;">是不是</span>启用
    enabled = true
    # 服务<span style="color: black;">位置</span>
    host = smtp.qq.com:465
    # 邮箱用户名
    user = xxx@qq.com
    # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
    # 授权<span style="color: black;">秘码</span>
    password = xxx
    ;cert_file =
    ;key_file =
    skip_verify = true
    # 邮件From<span style="color: black;">位置</span>
    from_address = xxx@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

   
    ;welcome_email_on_sign_up = false
    ;templates_pattern = emails/*.html<h1 style="color: black; text-align: left; margin-bottom: 10px;">2、Alerting -&gt; Notification channels</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/56eb20699282420cac88d4131229bda8~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=xKZlOfxtgafj2mYucJ9LtOqT30s%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/300c0eee273d48fe8fe2b2e055083ce2~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=YQHv1cXf%2Ben7Jk5FLHdOLJMYKew%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 测试发送<span style="color: black;">通告</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/fc69f5f488944634a6d70ee3a2963102~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=mztxbt71yptC9vFi4Bj3Q5nHhQw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3、Add panel</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/15887db7e69c454d842c466d43a71d14~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=VYKRULgAlLQXj4j4IlxdUZIazGE%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 仿造Heap used配置一个</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">tips: Metrics browser中不支持模板变量 ( ex: $application )</p>sum(jvm_memory_used_bytes{application="demo", instance="192.168.101.88:9200", area="heap"})*100/sum(jvm_memory_max_bytes{application="demo",instance="192.168.101.88:9200", area="heap"})<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p6-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/df73f8b94cd34c2a85e71a6983790c44~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=xde%2BnA8EYPzcPTGo9RTzJJTT73E%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/ba65c5299401479cba076c51d81ee9ac~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=Qg%2Bp2HP9fu9OZQRnFA1j11LAKsQ%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> Apply</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/ed9512e06a824721af12bedd422e0473~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=P03RL9Z%2B4G53OfnVfgMmgShND9M%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 超标告警<span style="color: black;">通告</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/4038355bd74f4410b0b07760dea5b316~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=PaFGl5Vo2OQvfDBQNcgkSdRJr9c%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/7a6f59aee0d94d448dbe88b5243de2b2~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728815871&amp;x-signature=G0Vo9oSapL77T9ZdFyxeYSwbRS8%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">6、</span>本文案例demo源码</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://gitee.com/zhengqingya/java-workspace</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">今日分享语句: 不奋斗,你的才华<span style="color: black;">怎样</span>配得上你的任性。 不奋斗,你的脚步<span style="color: black;">怎样</span>赶得上父母老去的速度。 不奋斗,世界这么大你靠什么去<span style="color: black;">瞧瞧</span>。</p>




qzmjef 发表于 2024-11-5 05:15:13

交流如星光璀璨,点亮思想夜空。
页: [1]
查看完整版本: 运维(32) Prometheus+Grafana监控SpringBoot