├── .gitignore ├── README.md ├── SUMMARY.md ├── alertmanager ├── README.md ├── config.md ├── email.md ├── others.md ├── slack.md ├── webhooks.md ├── wechat.md ├── wechat │ ├── wechat01.png │ ├── wechat03.png │ └── wechat04.png └── what.md ├── application ├── README.md ├── django.md ├── laravel.md ├── phoenix.md ├── rails.md └── spring.md ├── arrangement ├── README.md ├── k8s.md └── swarm.md ├── concepts ├── README.md ├── data-model.md ├── jobs-and-instances.md └── metric-types.md ├── configuration ├── README.md ├── alerting.md ├── demo.md ├── global.md ├── remote_read.md ├── remote_write.md ├── rule_files.md ├── scrape_configs.md └── server_discovery.md ├── container ├── README.md ├── docker.md └── k8s.md ├── demo ├── README.md ├── alertmanager.md ├── grafana.md ├── rule.md └── target.md ├── devops ├── README.md ├── exporter.md ├── product.md └── receiver.md ├── exporter ├── README.md ├── nodeexporter.md ├── nodeexporter_grafana_template.md ├── nodeexporter_query.md ├── other.md ├── sample.md └── text.md ├── ha ├── README.md ├── alertmanger.md ├── img1.png ├── img2.png ├── img3.png ├── img4.png ├── img5.png └── prometheus.md ├── how-to-contribute.md ├── images ├── alertmanager │ ├── slack-alert1.png │ ├── slack-alert2.png │ ├── slack-alert3.png │ ├── slack-alert4.png │ ├── slack-alert5.png │ └── slack-alert6.png ├── cadvisor │ ├── cadvisor-01.png │ ├── cadvisor-02.png │ ├── cadvisor-03.png │ ├── cadvisor-04.png │ ├── cadvisor-05.png │ ├── prometheus01.png │ ├── prometheus02.png │ ├── prometheus03.png │ ├── prometheus04.png │ ├── prometheus05.png │ ├── prometheus06.png │ └── prometheus07.png ├── exporter │ ├── sample_exporter_data.png │ └── simple_exporter.png ├── install │ ├── prometheus-console.png │ └── prometheus-graph.png ├── qa │ └── reload_success.png └── visualiztion │ ├── grafana-add-graph.png │ ├── grafana-added-panel.png │ ├── grafana-datasource.png │ ├── grafana-default-dashbord.png │ ├── grafana-edit-panel.png │ ├── grafana-hide-controls.png │ ├── grafana-into-manage-dashboard.png │ ├── grafana-login.png │ ├── grafana-prometheus-data-source.png │ ├── prometheus-web-console.png │ └── prometheus-web-graph.png ├── install ├── README.md ├── binary.md └── docker.md ├── introduction ├── README.md ├── what.md └── why.md ├── optimize ├── README.md ├── config.md ├── logger.md └── status.md ├── password.html ├── promql ├── README.md ├── sql.md └── summary.md ├── pushgateway ├── README.md ├── how.md └── why.md ├── qa ├── README.md ├── auth.md ├── hotreload.md ├── jvm.md ├── losedata.md ├── memory.md └── pushgateway.md ├── revision-record.md ├── rule ├── README.md ├── config.md └── what.md ├── service ├── README.md ├── memcached.md ├── mongodb.md ├── mysql.md ├── nginx.md └── redis.md ├── store ├── README.md ├── local.md └── remote.md ├── tools ├── README.md ├── client.md └── promu.md ├── v2.0 ├── README.md ├── feature.md ├── rule.md └── store.md └── visualiztion ├── README.md ├── console.md └── grafana.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Node rules: 2 | ## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 3 | .grunt 4 | 5 | ## Dependency directory 6 | ## Commenting this out is preferred by some people, see 7 | ## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git 8 | node_modules 9 | 10 | # Book build output 11 | _book 12 | 13 | # eBook build output 14 | *.epub 15 | *.mobi 16 | *.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prometheus 实战 2 | 3 | v0.1.0 4 | 5 | 在过去一年左右时间里,我们使用 Prometheus 完成了对几个机房的基础和业务监控,大大提高了服务质量以及 oncall 水平,在此特别感谢 Promethues 这样优秀的开源软件。 6 | 7 | 当初选择 Prometheus 并不是偶然,因为: 8 | 9 | * Prometheus 是按照 Google SRE 运维之道的理念构建的,具有实用性和前瞻性。 10 | 11 | * Prometheus 社区非常活跃,基本稳定在 1个月1个版本的迭代速度,从 2016 年 v1.01 开始接触使用以来,到目前发布的 v1.8.2 以及最新最新的 v2.1 ,你会发现 Prometheus 一直在进步、在优化。 12 | 13 | * Go 语言开发,性能不错,安装部署简单,多平台部署兼容性好。 14 | 15 | * 丰富的数据收集客户端,官方提供了各种常用 exporter。 16 | 17 | * 丰富强大的查询能力。 18 | 19 | Prometheus 作为监控后起之秀,虽然还有做的不够好的地方,但是不妨碍我们使用和喜爱它。根据我们长期的使用经验来看,它足以满足大多数场景需求,只不过对于新东西,往往需要花费更多力气才能发挥它的最大能力而已。 20 | 21 | 本书主要根据个人过去一年多的使用经验总结而成,内容主要包括 Prometheus 基本知识、进阶、实战以及常见问题列表等方面,希望对大家有所帮助。 22 | 23 | 本开源书籍既适用于具备基础 Linux 知识的运维初学者,也可供渴望理解 Prometheus 原理和实现细节的高级用户参考,同时也希望书中给出的实践案例在实际部署监控中对大家有所帮助。 24 | 25 | 你准备好了吗?接下来就让我们一起开始这段神奇旅行吧! 26 | 27 | ## 技术交流 28 | 29 | 欢迎加入 Prometheus 技术交流 QQ 群,分享 Prometheus 资源,交流 Prometheus 技术。 30 | 31 | * QQ 群:465362780 (已满) 申请加入请备注:prometheus 实战 32 | * 加入我们的知识星球,在这里你可以和国内最专业的 Prometheus 同行一起交流和学习: 33 | 34 | ![image_228845211141_3](https://user-images.githubusercontent.com/1459834/41642276-7101ce02-749a-11e8-8da0-6cf702af0870.JPG) 35 | 36 | ## 关于作者 37 | 38 | * small_fish__ 39 | 40 | * [微博](https://weibo.com/songjiayang1) 41 | * [github](https://github.com/songjiayang) 42 | * 个人公众号 43 | 44 | ![第二范式](https://git.io/vAQvJ) 45 | 46 | - 薛锦 47 | 48 | * [微博](https://weibo.com/1660913012/profile?topnav=1&wvr=6) 49 | * [github](https://github.com/csxuejin) 50 | * 个人公众号 51 | 52 | ![GitHub Logo](https://songjiayang.gitbooks.io/go-basic-courses/content/pics/easy-hacking.jpg) 53 | 54 | ## GitHub 关注曲线 55 | 56 | [![Stargazers over time](https://starcharts.herokuapp.com/songjiayang/prometheus_practice.svg)](https://starcharts.herokuapp.com/songjiayang/prometheus_practice) 57 | 58 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [前言](README.md) 4 | * [修订记录](revision-record.md) 5 | * [如何贡献](how-to-contribute.md) 6 | * [Prometheus 简介](introduction/README.md) 7 | * [Prometheus 是什么](introduction/what.md) 8 | * [为什么选择 Prometheus](introduction/why.md) 9 | * [Prometheus 安装](install/README.md) 10 | * [二进制包安装](install/binary.md) 11 | * [Docker 安装](install/docker.md) 12 | * [基础概念](concepts/README.md) 13 | * [数据模型](concepts/data-model.md) 14 | * [Metric types](concepts/metric-types.md) 15 | * [作业与实例](concepts/jobs-and-instances.md) 16 | * [PromQL](promql/README.md) 17 | * [PromQL 基本使用](promql/summary.md) 18 | * [与 SQL 对比](promql/sql.md) 19 | * [数据可视化](visualiztion/README.md) 20 | * [Web Console](visualiztion/console.md) 21 | * [Grafana](visualiztion/grafana.md) 22 | * [Prometheus 配置](configuration/README.md) 23 | * [全局配置](configuration/global.md) 24 | * [告警配置](configuration/alerting.md) 25 | * [规则配置](configuration/rule_files.md) 26 | * [数据拉取配置](configuration/scrape_configs.md) 27 | * [远程可写存储](configuration/remote_write.md) 28 | * [远程可读存储](configuration/remote_read.md) 29 | * [服务发现](configuration/server_discovery.md) 30 | * [配置样例](configuration/demo.md) 31 | * [Exporter](exporter/README.md) 32 | * [文本格式](exporter/text.md) 33 | * [Sample Exporter](exporter/sample.md) 34 | * [Node Exporter 安装使用](exporter/nodeexporter.md) 35 | * [Node Exporter 常用查询](exporter/nodeexporter_query.md) 36 | * [Node Exporter Grafana 模版](exporter/nodeexporter_grafana_template.md) 37 | * [其他 Exporter 介绍](exporter/other.md) 38 | * [Pushgateway](pushgateway/README.md) 39 | * [Pushgateway 是什么](pushgateway/why.md) 40 | * [如何使用 Pushgateway? ](pushgateway/how.md) 41 | * [数据存储](store/README.md) 42 | * [Local Store](store/local.md) 43 | * [Remote Store](store/remote.md) 44 | * [告警规则](rule/README.md) 45 | * [如何配置](rule/config.md) 46 | * [触发逻辑](rule/what.md) 47 | * [Alertmanager](alertmanager/README.md) 48 | * [Alertmanager 是什么](alertmanager/what.md) 49 | * [配置详情](alertmanager/config.md) 50 | * [通过 Email 接收告警](alertmanager/email.md) 51 | * [通过企业微信接收告警](alertmanager/wechat.md) 52 | * [通过 Slack 接收告警](alertmanager/slack.md) 53 | * [通过 Webhook 接收告警](alertmanager/webhooks.md) 54 | * [其他告警接收方案](alertmanager/others.md) 55 | * [主机监控完整示例](demo/README.md) 56 | * [NodeExporter](demo/target.md) 57 | * [配置告警规则](demo/rule.md) 58 | * [Grafana 集成](demo/grafana.md) 59 | * [通过 Alertmanager 告警](demo/alertmanager.md) 60 | * [Prometheus 工具](tools/README.md) 61 | * [Promu 介绍和使用](tools/promu.md) 62 | * [Client SDK](tools/client.md) 63 | * [Prometheus 性能调优](optimize/README.md) 64 | * [通过 Metrics 查看 Prometheus 运行状态](optimize/status.md) 65 | * [通过日志分析 Prometheus 运行状态](optimize/logger.md) 66 | * [启动参数详解](optimize/config.md) 67 | * [Prometheus 与容器](container/README.md) 68 | * [Docker](container/docker.md) 69 | * [Kubernetes](container/k8s.md) 70 | * [Prometheus 常见服务监控](service/README.md) 71 | * [Nginx](service/nginx.md) 72 | * [Memcached](service/memcached.md) 73 | * [MongoDB](service/mongodb.md) 74 | * [MySQL](service/mysql.md) 75 | * [Redis](service/redis.md) 76 | * [Prometheus 常见应用监控](application/README.md) 77 | * [Spring boot](application/spring.md) 78 | * [Rails](application/rails.md) 79 | * [Django](application/django.md) 80 | * [Laravel](application/laravel.md) 81 | * [Phoenix](application/phoenix.md) 82 | * [Prometheus 与 DevOps](devops/README.md) 83 | * [从 0 开发一个 exporter](devops/exporter.md) 84 | * [使用 Webhooks 开发一个 alert receiver](devops/receiver.md) 85 | * [高可用方案探讨](ha/README.md) 86 | * [Prometheus Server 的高可靠](ha/prometheus.md) 87 | * [AlertManager 的高可靠](ha/alertmanger.md) 88 | * [v2.x 迁移注意](v2.0/README.md) 89 | * [新功能](v2.0/feature.md) 90 | * [新存储架构](v2.0/store.md) 91 | * [Rule 新配置](v2.0/rule.md) 92 | * [常见问题收录](qa/README.md) 93 | * [如何热加载新配置](qa/hotreload.md) 94 | * [为什么重启 Prometheus 过后,数据无法查询](qa/hotreload.md) 95 | * [如何删除 Pushgateway 的数据](qa/pushgateway.md) 96 | * [为什么内存使用这么高](qa/memory.md) 97 | * [为什么有数据丢失](qa/losedata.md) 98 | * [如何通过认证后拉取数据](qa/auth.md) 99 | * [监控 JVM](qa/jvm.md) 100 | -------------------------------------------------------------------------------- /alertmanager/README.md: -------------------------------------------------------------------------------- 1 | # Alertmanager 2 | 3 | 在 Prometheus 中告警分为两部分: 4 | 5 | - Prometheus 服务根据所设置的告警规则将告警信息发送给 Alertmanager。 6 | - Alertmanager 对收到的告警信息进行处理,包括去重,降噪,分组,策略路由告警通知。 7 | 8 | 使用告警服务主要的步骤如下: 9 | 10 | - 下载配置 Alertmanager。 11 | - 通过设置 `-alertmanager.url` 让 Prometheus 服务与 Alertmanager 进行通信。 12 | - 在 Prometheus 服务中设置告警规则。 -------------------------------------------------------------------------------- /alertmanager/config.md: -------------------------------------------------------------------------------- 1 | # 配置详情 2 | 3 | ### 全局配置 4 | 5 | ### 分组 6 | 7 | ### 去重 8 | 9 | ### 降噪 10 | 11 | ### 告警路由配置 -------------------------------------------------------------------------------- /alertmanager/email.md: -------------------------------------------------------------------------------- 1 | #通过 Email 接收告警 2 | 3 | 本章将通过一个简单的实验介绍如何通过 Email 接受告警。 4 | 5 | 相关信息说明: 6 | - Prometheus 版本:prometheus-1.7.1.darwin-amd64 7 | - Alertmanager 版本:alertmanager-0.8.0.darwin-amd64 8 | - 发送告警邮件的邮箱:qq email 9 | 10 | 假设该实验运行在本地机器上, Prometheus 默认端口为 9090,Alertmanager 默认端口为 9093。 11 | 12 | ### 修改 AlertManager 配置文件 13 | 14 | 其中一些关键配置如下: 15 | 16 | ``` 17 | global: 18 | smtp_smarthost: 'smtp.qq.com:587' 19 | smtp_from: 'xxx@qq.com' 20 | smtp_auth_username: 'xxx@qq.com' 21 | smtp_auth_password: 'your_email_password' 22 | 23 | route: 24 | # If an alert has successfully been sent, wait 'repeat_interval' to resend them. 25 | repeat_interval: 10s 26 | # A default receiver 27 | receiver: team-X-mails 28 | 29 | receivers: 30 | - name: 'team-X-mails' 31 | email_configs: 32 | - to: 'team-X+alerts@example.org' 33 | ``` 34 | 35 | ### 在prometheus下添加 alert.rules 文件 36 | 37 | 文件中写入以下简单规则作为示例。 38 | ``` 39 | ALERT memory_high 40 | IF prometheus_local_storage_memory_series >= 0 41 | FOR 15s 42 | ANNOTATIONS { 43 | summary = "Prometheus using more memory than it should {{ $labels.instance }}", 44 | description = "{{ $labels.instance }} has lots of memory man (current value: {{ $value }}s)", 45 | } 46 | ``` 47 | 48 | ### 修改 prometheus.yml 文件 49 | 50 | 添加以下规则: 51 | ``` 52 | rule_files: 53 | - "alert.rules" 54 | ``` 55 | 56 | ### 启动AlertManager服务 57 | ``` 58 | ./Alertmanager -config.file=simple.yml 59 | ``` 60 | 61 | ### 启动prometheus服务 62 | ``` 63 | ./prometheus -Alertmanager.url=http://localhost:9093 64 | ``` 65 | 66 | 根据以上步骤设置,此时 “team-X+alerts@example.org” 应该就可以收到 “xxx@qq.com” 发送的告警邮件了。 67 | -------------------------------------------------------------------------------- /alertmanager/others.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/alertmanager/others.md -------------------------------------------------------------------------------- /alertmanager/slack.md: -------------------------------------------------------------------------------- 1 | #通过 Slack 接收告警 2 | 3 | [Slack](https://slack.com) 作为 IM 办公软件,简单好用,在国外用的特别多,那如何用它来接收 Prometheus 的告警信息,让咱们的运维看上去高大上。 4 | 5 | ### 目的 6 | 7 | - 使用 slack 接受消息。 8 | - 消息能够带有 url, 自动跳转到 prometheus 对应 graph 查询页面。 9 | - 能自定义颜色。 10 | - 能够 @ 某人 11 | 12 | ### 准备工作 13 | 14 | 已注册了 slack 账号,并创建了一个 #test 频道。 15 | 16 | ### 配置步骤 17 | 18 | Step1: 为 #test 频道创建一个 incomming webhooks 应用。 19 | 20 | - 点击频道标题,选择 `Add an app or integration` 21 | 22 | ![Add an app or integration](/images/alertmanager/slack-alert1.png) 23 | 24 | - 在 app store 中搜索 `incomming webhooks`,选择第一个 25 | 26 | ![incomming webhooks](/images/alertmanager/slack-alert2.png) 27 | 28 | 创建成功以后,拷贝 app webhook 地址,后面会用到。 29 | 30 | Step2: 修改 prometheus rules,在 ANNOTATIONS 中添加特定字段。 31 | 32 | v1.x rule 写法: 33 | 34 | ``` 35 | ALERT InstanceStatus 36 | IF up {job="node"}== 0 37 | FOR 15s 38 | LABELS { 39 | instance = "", 40 | } 41 | ANNOTATIONS { 42 | summary = "服务器运行状态", 43 | description = 服务器已当机超过多少时间", 44 | link="http://xxx", 45 | color="#xxx", 46 | username="@sjy" 47 | } 48 | ``` 49 | 50 | v2.x alert rule 写法: 51 | 52 | ``` 53 | - alert: InstanceStatus 54 | expr: up {job="node"} == 0 55 | for: 15s 56 | labels: 57 | instance: "" 58 | annotations: 59 | summary: "服务器运行状态" 60 | description: 服务器已当机超过多少时间" 61 | link: "http://xxx" 62 | color: "#xxx" 63 | username: "@sjy" 64 | ``` 65 | 66 | 说明:我们在 rule 的 ANNOTATIONS 中添加了 link, color, username 三个字段,用它们来表示 `消息外链地址`,`消息颜色`和需要 `@` 的人。 67 | 68 | Step3: 修改 Alertmanager 配置。 69 | 70 | 使用 `slack_configs` 来配置 slack 的告警接收渠道: 71 | 72 | ``` 73 | 74 | receivers: 75 | - name: 'slack' 76 | slack_configs: 77 | - api_url: "xxx" 78 | channel: "#test" 79 | text: "{{ range .Alerts }} {{ .Annotations.description}}\n {{end}} {{ .CommonAnnotations.username}} <{{.CommonAnnotations.link}}| click here>" 80 | title: "{{.CommonAnnotations.summary}}" 81 | title_link: "{{.CommonAnnotations.link}}" 82 | color: "{{.CommonAnnotations.color}}" 83 | 84 | ``` 85 | 86 | 配置说明: 87 | 88 | - 按 alertname 分组。 89 | - slack_configs 配置中,使用了 template 语句,通过 CommonAnnotations 查找字段。 90 | - 插入外链不仅可以使用 title_link, 还可以使用 slack link 标记语法 。 91 | 92 | 更多 slack 配置,请参考 [incoming-webhooks](https://api.slack.com/incoming-webhooks)。 93 | 94 | 经过以上配置,我们收到的消息是这样: 95 | 96 | ![slack.alert.demo](/images/alertmanager/slack-alert5.png) 97 | 98 | 点击 title 或者 Click here,即可跳转到 Prometheus graph 页面: 99 | 100 | ![prometheus graph](/images/alertmanager/slack-alert6.png) 101 | 102 | 这样就很方便了,再也不用担心多个 Prometheus 节点,切换查询带来的烦恼。 103 | -------------------------------------------------------------------------------- /alertmanager/webhooks.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/alertmanager/webhooks.md -------------------------------------------------------------------------------- /alertmanager/wechat.md: -------------------------------------------------------------------------------- 1 | #通过企业微信接收告警 2 | 3 | Alertmanger 从 v0.12 开始已经默认支持企业微信了,下面我们就一起体验一下。 4 | 5 | ### 准备工作 6 | 7 | step 1: 访问[网站](https://work.weixin.qq.com/) 注册企业微信账号(不需要企业认证)。 8 | 9 | step 2: 访问[apps](https://work.weixin.qq.com/wework_admin/frame#apps) 创建第三方应用,点击`创建应用按钮` -> 填写应用信息: 10 | 11 | ![点击创建第三方应用](wechat/wechat01.png) 12 | 13 | ### 使用版本 14 | 15 | - prometheus: 2.0.darwin-amd64 16 | - node_exporter: 0.15.0.darwin-amd64 17 | - alertmanager: 0.14.darwin-amd64 18 | 19 | ### 详细配置: 20 | 21 | #### prometheus 配置: 22 | 23 | ``` 24 | # Alertmanager configuration 25 | alerting: 26 | alertmanagers: 27 | - static_configs: 28 | - targets: 29 | - localhost:9093 30 | 31 | rule_files: 32 | - "rules.yml" 33 | 34 | scrape_configs: 35 | - job_name: 'node' 36 | static_configs: 37 | - targets: ['localhost:9100'] 38 | ``` 39 | 40 | rules.yml 配置: 41 | 42 | ``` 43 | groups: 44 | - name: node 45 | rules: 46 | - alert: server_status 47 | expr: up{job="node"} == 0 48 | for: 15s 49 | annotations: 50 | summary: "机器 {{ $labels.instance }} 挂了" 51 | ``` 52 | 53 | #### alertmanger 配置: 54 | 55 | ``` 56 | route: 57 | group_by: ['alertname'] 58 | receiver: 'wechat' 59 | 60 | receivers: 61 | - name: 'wechat' 62 | wechat_configs: 63 | - corp_id: 'xxx' 64 | to_party: '1' 65 | agent_id: '1000002' 66 | api_secret: 'xxxx' 67 | ``` 68 | 69 | 参数说明: 70 | 71 | - corp_id: 企业微信账号唯一 ID, 可以在`我的企业`中查看。 72 | - to_party: 需要发送的组。 73 | - agent_id: 第三方企业应用的 ID,可以在自己创建的第三方企业应用详情页面查看。 74 | - api_secret: 第三方企业应用的密钥,可以在自己创建的第三方企业应用详情页面查看。 75 | 76 | 详情请参考[文档](https://work.weixin.qq.com/api/doc#10167/%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF)。 77 | 78 | ### 验证测试 79 | 80 | 当我们停掉 node_exporter 的时候,会收到如下告警信息: 81 | 82 | ![wechat03.png](wechat/wechat03.png) 83 | 84 | 当我们重新启动 node_exporter 的时候,会收到如下告警信息: 85 | 86 | ![wechat04.png](wechat/wechat04.png) 87 | 88 | ### 结论 89 | 90 | 企业微信从注册到 alertmanger 配置没有什么坑,而且它的通知非常及时,基本不丢消息,大家可以测试体验以下。 91 | -------------------------------------------------------------------------------- /alertmanager/wechat/wechat01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/alertmanager/wechat/wechat01.png -------------------------------------------------------------------------------- /alertmanager/wechat/wechat03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/alertmanager/wechat/wechat03.png -------------------------------------------------------------------------------- /alertmanager/wechat/wechat04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/alertmanager/wechat/wechat04.png -------------------------------------------------------------------------------- /alertmanager/what.md: -------------------------------------------------------------------------------- 1 | # Alertmanager 是什么? 2 | 3 | ![架构图](https://raw.githubusercontent.com/prometheus/alertmanager/4e6695682acd2580773a904e4aa2e3b927ee27b7/doc/arch.jpg) 4 | 5 | Alertmanager 主要用于接收 Prometheus 发送的告警信息,它支持丰富的告警通知渠道,而且很容易做到告警信息进行去重,降噪,分组,策略路由,是一款前卫的告警通知系统。 6 | 7 | ### 安装 8 | 9 | 使用 `wget` 下载按转包 10 | 11 | ``` 12 | cd ~/Download 13 | wget https://github.com/prometheus/alertmanager/releases/download/v0.14.0/alertmanager-0.14.0.linux-amd64.tar.gz 14 | cd Prometheus 15 | ``` 16 | 17 | 使用 `tar` 解压缩 alertmanager-0.14.0.linux-amd64.tar.gz 18 | 19 | ``` 20 | tar -xvzf ~/Download alertmanager-0.14.0.linux-amd64.tar.gz 21 | cd alertmanager-0.14.0.linux-amd64 22 | ``` 23 | 24 | 解压成功后,使用 `./alertmanager --version` 来检查是否安装成功 25 | 26 | ``` 27 | alertmanager, version 0.14.0 (branch: HEAD, revision: 30af4d051b37ce817ea7e35b56c57a0e2ec9dbb0) 28 | build user: root@37b6a49ebba9 29 | build date: 20180213-08:16:42 30 | go version: go1.9.2 31 | ``` 32 | 33 | ### 基本配置 34 | 35 | 执行命令 `mv simple.yml alertmanager.yml`,并修改 `alertmanager.yml` 配置: 36 | 37 | ``` 38 | global: 39 | resolve_timeout: 2h 40 | 41 | route: 42 | group_by: ['alertname'] 43 | group_wait: 5s 44 | group_interval: 10s 45 | repeat_interval: 1h 46 | receiver: 'webhook' 47 | 48 | receivers: 49 | - name: 'webhook' 50 | webhook_configs: 51 | - url: 'http://example.com/xxxx' 52 | send_resolved: true 53 | ``` 54 | 55 | 说明: 这里我们使用 Alertmanager 的 `webhook_configs` 选项来接收消息,当接收到新的告警信息,它会将消息转发到配置的 `url` 地址。 56 | -------------------------------------------------------------------------------- /application/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/application/README.md -------------------------------------------------------------------------------- /application/django.md: -------------------------------------------------------------------------------- 1 | # Prometheus 与 Django -------------------------------------------------------------------------------- /application/laravel.md: -------------------------------------------------------------------------------- 1 | # Prometheus 与 Laravel -------------------------------------------------------------------------------- /application/phoenix.md: -------------------------------------------------------------------------------- 1 | # Prometheus 与 Phoenix -------------------------------------------------------------------------------- /application/rails.md: -------------------------------------------------------------------------------- 1 | # Prometheus 与 Rails -------------------------------------------------------------------------------- /application/spring.md: -------------------------------------------------------------------------------- 1 | # Prometheus 与 Spring boot -------------------------------------------------------------------------------- /arrangement/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/arrangement/README.md -------------------------------------------------------------------------------- /arrangement/k8s.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/arrangement/k8s.md -------------------------------------------------------------------------------- /arrangement/swarm.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookieY/prometheus_practice/4b3c46bd5ff3a0f586ff3dab4079f333905ff524/arrangement/swarm.md -------------------------------------------------------------------------------- /concepts/README.md: -------------------------------------------------------------------------------- 1 | # 基础概念 2 | 3 | 本章将介绍 Prometheus 一些基础概念,包括: 4 | - 数据模型 5 | - 四种 Metric Type 6 | - 作业与实例 7 | -------------------------------------------------------------------------------- /concepts/data-model.md: -------------------------------------------------------------------------------- 1 | # 数据模型 2 | 3 | Prometheus 存储的是[时序数据](https://en.wikipedia.org/wiki/Time_series), 即按照相同时序(相同的名字和标签),以时间维度存储连续的数据的集合。 4 | 5 | ## 时序索引 6 | 7 | 时序(time series) 是由名字(Metric),以及一组 key/value 标签定义的,具有相同的名字以及标签属于相同时序。 8 | 9 | 时序的名字由 ASCII 字符,数字,下划线,以及冒号组成,它必须满足正则表达式 `[a-zA-Z_:][a-zA-Z0-9_:]* `, 其名字应该具有语义化,一般表示一个可以度量的指标,例如: `http_requests_total`, 可以表示 http 请求的总数。 10 | 11 | 时序的标签可以使 Prometheus 的数据更加丰富,能够区分具体不同的实例,例如 `http_requests_total{method="POST"}` 可以表示所有 http 中的 POST 请求。 12 | 13 | 标签名称由 ASCII 字符,数字,以及下划线组成, 其中 `__` 开头属于 Prometheus 保留,标签的值可以是任何 Unicode 字符,支持中文。 14 | 15 | ## 时序样本 16 | 17 | 按照某个时序以时间维度采集的数据,称之为样本,其值包含: 18 | 19 | * 一个 float64 值 20 | * 一个毫秒级的 unix 时间戳 21 | 22 | ## 格式 23 | 24 | Prometheus 时序格式与 [OpenTSDB](http://opentsdb.net/) 相似: 25 | 26 | ``` 27 | {