对警报线程池的警报线程

TL; DR (TL;DR)

Download tutorial code here

在此处下载教程代码

介绍 (Intro)

So there are number of tutorials available for monitoring and alerting using Prometheus and this is another one. The reason I had to write this was the time it took me to setup and configure it locally. The resources are numerous but I couldn’t find a single step by step code tut that could share a practical code approach.

因此,有许多教程可用于使用Prometheus进行监视和警报,这是另一篇。 我不得不写这篇文章的原因是花了我在本地设置和配置它的时间。 资源很多,但是我找不到可以共享实用代码方法的一步一步的代码。

This tutorial will take you on an experiment using prometheus with Java Spring Boot framework.

本教程将带您进行将Prometheus与Java Spring Boot框架一起使用的实验。

本教程适合具有以下领域中级技能的人员 (This tutorial is suited for people having intermediate skills in below areas)

  1. Java and Spring frameworkJava和Spring框架
  2. MavenMaven
  3. CLI/YMLCLI / YML

THIS IS NOT A INFRA SETUP OR DEEP-DIVE TUT FOR PROMETHEUS. Tutorial is targeted for code integration only

这不是用于PROMETHEUS的INFRA设置或深潜TUT。 教程仅针对代码集成

什么是普罗米修斯? (What is Prometheus?)

An app monitoring and alerting tool.

一个应用程序监视和警报工具。

你为什么需要它? (Why do you need it?)

Building awesome software products is one part and maintaining them is another part. As you grow as a software professional you would realise the most important part of software is gathering metrics and gauging health of your services for an uninterrupted customer experience.

构建出色的软件产品是其中的一部分,而维护它们则是另一部分。 随着您成为软件专业人员的成长,您将意识到软件的最重要部分是收集指标并评估服务的运行状况,以实现不间断的客户体验。

你是怎么做到的? (How you do it?)

第1步: (Step 1:)

The tutorial assumes you have Java/ Spring framework background. First of all let’s setup a simple Spring Boot Application. Download the complete code here. You will see 3 APIs here simulating a simple 2XX response and another a simple 5XX response and last /alert-hook to receive a callback when an alert comes (more details in Step 4).

本教程假定您具有Java / Spring框架背景。 首先,让我们设置一个简单的Spring Boot Application。 在此处下载完整的代码。 您将在此处看到3个API,它们模拟一个简单的2XX响应,另一个模拟一个简单的5XX响应,最后一个/ alert-hook会在警报到来时接收回调(步骤4中有更多详细信息)。

The metrics settings and server port 8082 can be configured via application.properties file

指标设置和服务器端口8082可以通过application.properties文件进行配置

Sample Responses when you start Spring Boot App and hit 2xx and 5xx api
启动Spring Boot App并点击2xx和5xx API时的示例响应

The code uses a library called micrometer to create metrics that Prometheus can understand. These metrics are available over http://localhost:8082/actuator/prometheus

该代码使用称为测微计的库来创建Prometheus可以理解的指标。 这些指标可通过http:// localhost:8082 / actuator / prometheus获得

第2步: (Step 2:)

In a situation when your app starts misbehaving and starts throwing 5xx, you would want to proactively act on this situation w/o your customers letting you know about this situation. Thats where the tool like prometheus comes in.

在您的应用开始行为异常并开始抛出5xx的情况下,您可能希望在没有客户的情况下主动对这种情况采取行动,让您知道这种情况。 那就是像prometheus这样的工具出现的地方。

So lets install Prometheus (on MAC for me)

因此,让我们安装Prometheus(对我来说是在MAC上)

Download Prometheus binary here, unzip and do the following bare minimum configs.

在此处下载Prometheus二进制文件,解压缩并执行以下最低限度的配置。

Open prometheus.yml in the downloaded folder and add your Spring boot application info so that Prometheus can pull in the metrics. See line 30 where we have added a new target telling Prometheus where to pull metrics

在下载的文件夹中打开prometheus.yml ,然后添加您的Spring boot应用程序信息,以便Prometheus可以获取指标。 参见第30行,我们在其中添加了一个新的目标,告诉Prometheus在哪里提取指标

From your command prompt, cd into Prometheus dir and start the prometheus process. (It will automatically read above config file if the process is started in prometheus dir)

在命令提示符下,使用cd进入Prometheus目录,然后启动Prometheus进程。 (如果该过程在prometheus dir中启动,它将自动读取上述配置文件)

>>> ./prometheus

>>> ./prometheus

This should start prometheus server with some default setting like time interval after which prometheus will pull in the metrics.

这将使用一些默认设置(例如时间间隔)启动Prometheus服务器,此后Prometheus将提取指标。

After prometheus is started, visit http://localhost:9090/graph to view the Prometheus panel where you can query and view the metrics pushed by our Boot app.

启动Prometheus之后,请访问http:// localhost:9090 / graph以查看Prometheus面板,您可以在其中查询和查看由Boot应用程序推送的指标。

Try querying the metrics like shown in below screenshot.

尝试查询指标,如下面的屏幕截图所示。

orders_5xx_total and orders_2xx_total are the metrics which we pushed from our app

orders_5xx_total和orders_2xx_total是我们从应用程序中推送的指标

第三步: (Step 3:)

Till now you have collected the data and now it’s time to set alerts on top of this data. A very important alert that you would need is the error rate breaching a threshold.

到目前为止,您已经收集了数据,现在该在此数据之上设置警报了。 您需要的一个非常重要的警报是错误率超过阈值。

For this example, we will set an alert which will trigger if 5xx rate is more than 1%.

对于此示例,我们将设置一个警报,如果5xx比率大于1%,则将触发该警报。

Let’s create a rules file that will have our condition represented in prometheus query language and some information that we want to push when this alert is triggered.

让我们创建一个规则文件,该文件将以普罗米修斯查询语言表示我们的条件,并在触发此警报时要推送的一些信息。

alert-rules.yml is our sample rule file which looks like below. (Gist available in the end)

alert-rules.yml是我们的示例规则文件,如下所示。 (要点最后可用)

Update prometheus.yml with the info of this file using below configs

使用以下配置,使用此文件的信息更新prometheus.yml

Restart the prometheus server and you should see below Alerts info if you visit Alerts section in panel

重新启动prometheus服务器,如果您访问面板中的“警报”部分,则应该在下面看到警报信息

Now to simulate the alert scenario, let’s hit a few 5xx urls and few 2xx urls from our spring boot app. Make sure 5xx hits are more than 2xx

现在模拟警报场景,让我们从我们的Spring Boot应用程序中点击几个5xx网址和几个2xx网址。 确保5xx命中大于2xx

After few seconds (of Rule evaluation/Scrape interval time), you will start seeing Alert Status go into Pending and then into Firing, which means Alert has been triggered.

几秒钟(“规则评估/抓取间隔时间”)后,您将开始看到“警报状态”进入“待处理”,然后进入“开火”,这意味着已触发警报。

第4步 (Step 4)

To get this Alert over various channels like Emails/Webhooks/Slack etc we need another tool called AlertManager.

要通过各种渠道(例如电子邮件/ Webhooks / Slack等)获取此警报,我们需要另一个名为AlertManager的工具。

Download Alertmanager binary here and connect prometheus to alertmanager by updating the alertmanager.yml configuration first.

在此处下载Alertmanager二进制文件,并通过首先更新alertmanager.yml配置将prometheus连接到alertmanager。

In alertmanager.yml, update line 13 (see below screenshot) to point to api /alert-hook in our spring boot app. It means when ever an alert will come, AlertManager will notify us at this location.

在alertmanager.yml中,更新第13行(请参见下面的屏幕截图)以指向我们的Spring Boot应用程序中的api / alert-hook。 这意味着,每当有警报发出时,AlertManager都会在此位置通知我们。

Secondly update, prometheus.yml to connect to Alertmanager server. See below screenshot line 12 of prometheus.yml

其次,更新prometheus.yml以连接到Alertmanager服务器。 参见下面的prometheus.yml屏幕截图第12行

Now run alertmanager from your CLI

现在从您的CLI运行alertmanager

>>./alertmanager

>> ./ alertmanager

and restart the prometheus server

并重新启动Prometheus服务器

>>./prometheus

>> ./普罗米修斯

Now if you hit some 5xx more via spring boot API, you should see in your spring boot application console that after few seconds of evaluation, an alert was triggered and received a callback at /alert-hook API

现在,如果您通过Spring Boot API再打5xx,您应该在Spring Boot应用程序控制台中看到经过几秒钟的评估之后,警报已触发并在/ alert-hook API处收到了回调

You can also validate this via Alertmanager Panel, available

您也可以通过Alertmanager面板(可用)进行验证

http://localhost:9093/#/alerts

http:// localhost:9093 /#/ alerts

And printing callback via your boot console logs

并通过启动控制台日志打印回调

进一步阅读 (Further Reading)

This tutorial has touched monitoring and alerting from a 100ft view. You should deep dive now to understand architecture in details, Prometheus Query language, aggregate functions and more. If you were able to connect the dots and share the vision, start going through official docs here.

本教程从100英尺视图触及了监视和警报。 现在,您应该深入研究,以详细了解体系结构,Prometheus Query语言,聚合函数等。 如果您能够连接各个点并分享愿景,请在此处开始阅读官方文档。

资料下载 (Downloads)

Code used in the tutorial is open-sourced and is available at Github. Download here

本教程中使用的代码是开源的,可以在Github上找到。 在这里下载

Complete prometheus.yml and alertmanager.yml and alert-rules.yml are available as Gists below

完整的prometheus.yml和alertmanager.yml和alert-rules.yml可作为以下要点获得

翻译自: https://medium.com/@apuravchauhan/app-monitoring-and-alerting-a-practical-prometheus-spring-boot-tutorial-d79449b9278d

对警报线程池的警报线程


http://www.taodudu.cc/news/show-5926514.html

相关文章:

  • 2022-2028全球与中国警报合理化软件市场现状及未来发展趋势
  • php 消除警报,php suhosin警报
  • webfunny警报设置:如何快速验证警报是否有效?
  • 很强大的恋爱攻略
  • 项目实训-不死僵尸
  • 一条忍着不死的鱼
  • 贪吃蛇python撞墙不死_不敢相信,60行python代码就写出了贪吃蛇游戏
  • 蚂蚁为什么摔不死?-王睿琦
  • 2007年度網絡最新警句,樂不死你
  • 不死种子
  • Chrome的小恐龙被我“开挂”了,看我如何用一行代码让它拥有不死之身
  • 缔造Android推送服务不死之身
  • 让服务具有不死之身的方法
  • 练就你app的不死之身
  • android不死service,Android面试题-Service不死之身-Go语言中文社区
  • Service不死之身
  • 首位中国AI主播出现但不稀奇,天猫精灵每天都能给你读新闻
  • 天猫超市幕后功臣并入阿里,店宝宝:互利互惠
  • 关系型数据库中所谓的“关系”是指( )。
  • 求出所有的水仙花数。所谓水仙花数是指一个三位数,其各位数字的立方和等于该数字本身。比如153是一个水仙花数,因为153=1^3+5^3+3^3。
  • 编程求1000之内的所有“完数”。所谓“完数”是指一个数恰好等于它的因子之和。例如,6是完数,因为6=1+2+3。
  • 打印出所有的“水仙花数”。 所谓“水仙花数”,是指一个三位数,其各位数字的立方和等 于该数本身。(Python经典编程案例)
  • 打印所有的水仙花数,所谓水仙花数是指一个三位数,其中各位数字的立方和等于该数本身,如153=1^3+5^3+3^3。
  • 2021-04-09编程求1000以内的所有“完数”。所谓“完数”是指一个数恰好等于它的因子之和。例如,6是完数,因为6=1+2+3
  • C语言:对输入的一个数判断是否是素数。所谓素数是指这个数只能被1和自身整除。要求在主函数输入一个数,调用函数Fun()判断该数是否是素数。
  • 打印出所有的“水仙花数”。所谓“水仙花数”是指一个3位数,其各位数字的立方和等于该数本身。
  • 输入一个整数矩阵,计算位于矩阵边缘的元素之和。所谓矩阵边缘的元素,就是第一行和最后一行的元素以及第一列和最后一列的元素。
  • c语言编程判断输入的一个字符串是否是“回文”。所谓“回文”字符串就是左读和右读都一样的字符串。例如: “abcba“就是一个回文字符串。
  • C语言编程>第一周 ⑥ 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
  • 《所谓情商高,就是会说话》的读书笔记

对警报线程池的警报线程_应用程序监视和警报实用的Prometheus Spring Boot教程相关推荐

  1. 线程池传递对象参数_一次线程池参数错误引起的线上故障

    在JAVA里,我们通常会把没有前后依赖关系的逻辑操作扔到多个线程里并行执行,以提高代码运行效率. 同时,我们一般也不会单独显式创建线程,而是通过线程池设置线程.使用线程池的好处是减少在创建和销毁线程上 ...

  2. python 判断线程是否执行完毕_判断线程池中的线程是否全部执行完毕

    在使用多线程的时候有时候我们会使用 java.util.concurrent.Executors的线程池,当多个线程异步执行的时候,我们往往不好判断是否线程池中所有的子线程都已经执行完毕,但有时候这种 ...

  3. java线程池原理简答_面试官让我讲讲Java线程池的实现原理,我笑了...

    期待与你,一起进步 随着cpu核数越来越多,不可避免的利用多线程技术以充分利用其计算能力.所以,多线程技术是服务端开发人员必须掌握的技术. 线程的创建和销毁,都涉及到系统调用,比较消耗系统资源,所以就 ...

  4. java线程池的面试题_献给准备面试的你,Java线程and线程池面试题小结

    最近这几天一直在整理Java相关的面试题,"金九银十"是求职的最佳时间,但是现在的"银十"也已经过去了一半的时间,相信现在还在为面试四处奔波的小伙伴已经很疲惫了 ...

  5. 线程池:治理线程的法宝

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 作者:Oo鲁毅oO juejin.im/post/5e1b1fcc ...

  6. 一个线程池中的线程异常了,那么线程池会怎么处理这个线程?

    一个线程池中的线程异常了,那么线程池会怎么处理这个线程? 参考文章: (1)一个线程池中的线程异常了,那么线程池会怎么处理这个线程? (2)https://www.cnblogs.com/fangua ...

  7. 【Java 并发编程】线程池机制 ( 线程池阻塞队列 | 线程池拒绝策略 | 使用 ThreadPoolExecutor 自定义线程池参数 )

    文章目录 一.线程池阻塞队列 二.拒绝策略 三.使用 ThreadPoolExecutor 自定义线程池参数 一.线程池阻塞队列 线程池阻塞队列是线程池创建的第 555 个参数 : BlockingQ ...

  8. 【Java 并发编程】线程池机制 ( ThreadPoolExecutor 线程池构造参数分析 | 核心线程数 | 最大线程数 | 非核心线程存活时间 | 任务阻塞队列 )

    文章目录 前言 一.ThreadPoolExecutor 构造参数 二.newCachedThreadPool 参数分析 三.newFixedThreadPool 参数分析 四.newSingleTh ...

  9. 【Android 异步操作】线程池 ( Worker 简介 | 线程池中的工作流程 runWorker | 从线程池任务队列中获取任务 getTask )

    文章目录 一.线程池中的 Worker ( 工作者 ) 二.线程池中的工作流程 runWorker 三.线程池任务队列中获取任务 getTask 在博客 [Android 异步操作]线程池 ( 线程池 ...

最新文章

  1. “”开天眼“”,天地分割效果
  2. R语言偏相关或者部分相关性系数计算实战:通过拟合两个回归模型、或者pysch包计算偏相关系数(Partial Correlation)、通过方差分析获得偏相关系数的F统计量(偏F检验、二型检验)
  3. 20150917html第二次课
  4. windows10商店无法下载linux,Windows 10 Store 下载极慢
  5. 关于SVN Server自助修改密码详细教程
  6. MySQL主主复制 外键_MySQL 组复制介绍
  7. html文本打印lt;igt;字段,Web前端学习第九课,使用文本格式化标签
  8. hdu 2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
  9. andriod环境搭建
  10. SWF怎么转换AVI视频格式呢?
  11. zend studio10运行php,加速Zend Studio 运行的10点技巧
  12. UML建模:基于智慧校园的二手交易平台
  13. jQuery菜鸟教程
  14. 栅格布局 xs sm md lg
  15. 最好的评价线性回归的指标-R Squared
  16. python发短信sim800_玩转 ESP32 + Arduino (十八) 采用SIM800L发送短信和定位(基础知识)...
  17. 人脸识别 —— insightface
  18. CDA数据分析师level2(模拟题考点记录)
  19. 【人工智能算法】算法基础之离散优化[旅行商问题 背包问题]
  20. tensorflow实现卷积神经网络——经典网络(LeNet5、AlexNet、VGG-16、ResNet)

热门文章

  1. Activity(测姻缘总结)
  2. Kotlin中自定义dialog
  3. html自定义单选按钮,美化表单——自定义单选按钮和复选按钮
  4. 太有意思啦,谁研究的哪
  5. 高校各系发出的爱情短信
  6. pytorch中的contiguous()函数的浅浅解释
  7. MySQL深入学习(三十):数据库的设计规范
  8. 工业自动化流水线上的机器视觉检测应用 (二):图像检测
  9. 工作记录:EasyExcel对于不定长Excel表头的处理,写excel
  10. 病毒分析——静态特征分析 及 动态行为分析