diff --git a/README.md b/README.md index b2ee765..43ff82a 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,11 @@ Prometheus操作指南:云原生监控之道 * [自定义Prometheus告警规则](./alert/prometheus-alert-rule.md) * [部署AlertManager](./alert/install-alert-manager.md) * [基于Label的动态告警处理](./alert/alert-manager-routes.md) - * [内置告警接收器Receiver](./alert/alert-manager-with-smtp.md) + * [使用内置告警接收器Receiver](./alert/alert-manager-with-smtp.md) * [使用Webhook扩展Alertmanager](./alert/alert-manager-extension-with-webhook.md) * [屏蔽告警通知](./alert/alert-manager-inhibit.md) * [使用Recoding Rules优化性能](./alert/prometheus-recoding-rules.md) + * 通知模板详解 * [小结](./alert/SUMMARY.md) ## Part II - Prometheus进阶 diff --git a/alert/alert-manager-with-smtp.md b/alert/alert-manager-with-smtp.md index b274813..a9affb2 100644 --- a/alert/alert-manager-with-smtp.md +++ b/alert/alert-manager-with-smtp.md @@ -108,6 +108,14 @@ receivers: ![告警](http://p2n2em8ut.bkt.clouddn.com/mail-alert-page.png) +## 与Slack集成 + +> TODO + +## 与微信集成 + +> + ## 自定义模板 默认情况下Alertmanager使用了系统自带的默认通知模板,模板源码可以从[https://github.com/prometheus/alertmanager/blob/master/template/default.tmpl](https://github.com/prometheus/alertmanager/blob/master/template/default.tmpl)获得。Alertmanager的通知模板基于[Go的模板系统](http://golang.org/pkg/text/template)。Alertmanager也支持用户定义和使用自己的模板,一般来说有两种方式可以选择。 diff --git a/quickstart/prometheus-quick-start.md b/quickstart/prometheus-quick-start.md index b511558..57ea814 100644 --- a/quickstart/prometheus-quick-start.md +++ b/quickstart/prometheus-quick-start.md @@ -73,7 +73,7 @@ level=info ts=2018-03-11T13:38:06.317679086Z caller=manager.go:59 component="scr 启动完成后,可以通过[http://localhost:9090](http://localhost:9090)访问Prometheus的UI界面。 -![Prometheus UI](http://p2n2em8ut.bkt.clouddn.com/prometheus-ui-graph.png) +![Prometheus UI](./static/prometheus-ui-graph.png) ##### 运行node exporter @@ -117,13 +117,13 @@ INFO[0000] Listening on :9100 source="node_exporter.g 访问[http://localhost:9100/](http://localhost:9100/)可以看到以下页面: -![node exporter页面](http://p2n2em8ut.bkt.clouddn.com/node_exporter_home_page.png) +![node exporter页面](./static/node_exporter_home_page.png) ## Node Exporter监控指标 访问[http://localhost:9100/metrics](http://localhost:9100/metrics),可以看到当前node exporter获取到的当前主机的所有监控数据,如下所示: -![主机监控指标](http://p2n2em8ut.bkt.clouddn.com/node_exporter_metrics_page.png) +![主机监控指标](./static/node_exporter_metrics_page.png) 每一个监控指标之前都会有一段类似于如下形式的信息: @@ -168,7 +168,7 @@ scrape_configs: 访问[http://localhost:9090](http://localhost:9090),进入到Prometheus Server。如果输入“up”并且点击执行按钮以后,可以看到如下结果: -![Expression Browser](http://p2n2em8ut.bkt.clouddn.com/prometheus_ui_up_query.png) +![Expression Browser](./static/prometheus_ui_up_query.png) 如果Prometheus能够正常从node exporter获取数据,则会看到以下结果: @@ -185,7 +185,7 @@ up{instance="localhost:9100",job="node"} 1 通过Prometheus UI用户可以利用PromQL实时查询监控数据,并且支持一些基本的数据可视化能力。进入到Prometheus UI,切换到Graph标签 -![Graph Query](http://p2n2em8ut.bkt.clouddn.com/prometheus_ui_graph_query.png) +![Graph Query](./static/prometheus_ui_graph_query.png) 通过PromQL则可以直接以可视化的形式显示查询到的数据。例如,查询主机负载变化情况,可以使用: @@ -193,7 +193,7 @@ up{instance="localhost:9100",job="node"} 1 node_load1 ``` -![主机负载情况](http://p2n2em8ut.bkt.clouddn.com/node_node1_graph.png) +![主机负载情况](./static/node_node1_graph.png) 查询主机CPU的使用率,由于node_cpu的数据类型是Counter,计算使用率需要使用rate()函数: @@ -201,7 +201,7 @@ node_load1 rate(node_cpu[2m]) ``` -![系统进程的CPU使用率](http://p2n2em8ut.bkt.clouddn.com/node_cpu_usage_by_cpu_and_mode.png) +![系统进程的CPU使用率](./static/node_cpu_usage_by_cpu_and_mode.png) 这时如果要忽略是哪一个CPU的,只需要使用without表达式,将标签CPU去除后聚合数据即可: @@ -209,7 +209,7 @@ rate(node_cpu[2m]) avg without(cpu) (rate(node_cpu[2m])) ``` -![系统各mode的CPU使用率](http://p2n2em8ut.bkt.clouddn.com/node_cpu_usage_by_mode.png) +![系统各mode的CPU使用率](./static/node_cpu_usage_by_mode.png) 那如果需要计算系统CPU的总体使用率,通过排除系统闲置的CPU使用率即可获得: @@ -217,7 +217,7 @@ avg without(cpu) (rate(node_cpu[2m])) 1 - avg without(cpu) (rate(node_cpu{mode="idle"}[2m])) ``` -![系统CPU使用率](http://p2n2em8ut.bkt.clouddn.com/node_cpu_usage_total.png) +![系统CPU使用率](./static/node_cpu_usage_total.png) 从上面这些例子中可以看出,根据样本中的标签可以很方便地对数据进行查询,过滤以及聚合等操作。同时PromQL中还提供了大量的诸如rate()这样的函数可以实现对数据的更多个性化的处理。 @@ -231,20 +231,20 @@ docker run -d -p 3000:3000 grafana/grafana 访问[http://localhost:3000](http://localhost:3000)就可以进入到Grafana的界面中,默认情况下使用账户admin/admin进行登录。在Grafana首页中显示默认的使用向导,包括:安装、添加数据源、创建Dashboard、邀请成员、以及安装应用和插件等主要流程: -![Grafana向导](http://p2n2em8ut.bkt.clouddn.com/get_start_with_grafana2.png) +![Grafana向导](./static/get_start_with_grafana2.png) 这里将添加Prometheus作为默认的数据源,如下图所示,指定数据源类型为Prometheus并且设置Prometheus的访问地址即可,在配置正确的情况下点击“Add”按钮,会提示连接成功的信息: -![添加Prometheus作为数据源](http://p2n2em8ut.bkt.clouddn.com/add_default_prometheus_datasource.png) +![添加Prometheus作为数据源](./static/add_default_prometheus_datasource.png) 在完成数据源的添加之后就可以在Grafana中创建我们可视化Dashboard了。Grafana提供了对PromQL的完整支持,如下所示,通过Grafana添加Dashboard并且为该Dashboard添加一个类型为“Graph”的面板。 并在该面板的“Metrics”选项下通过PromQL查询需要可视化的数据: -![第一个可视化面板](http://p2n2em8ut.bkt.clouddn.com/first_grafana_dashboard.png) +![第一个可视化面板](./static/first_grafana_dashboard.png) 点击界面中的保存选项,就创建了我们的第一个可视化Dashboard了。 当然作为开源软件,Grafana社区鼓励用户分享Dashboard通过[https://grafana.com/dashboards](https://grafana.com/dashboards)网站,可以找到大量可直接使用的Dashboard: -![用户共享的Dashboard](http://p2n2em8ut.bkt.clouddn.com/grafana_dashboards.png) +![用户共享的Dashboard](./static/grafana_dashboards.png) Grafana中所有的Dashboard通过JSON进行共享,下载并且导入这些JSON文件,就可以直接使用这些已经定义好的Dashboard: -![Host Stats Dashboard](http://p2n2em8ut.bkt.clouddn.com/node_exporter_dashboard.png) \ No newline at end of file +![Host Stats Dashboard](./static/node_exporter_dashboard.png) \ No newline at end of file diff --git a/quickstart/static/add_default_prometheus_datasource.png b/quickstart/static/add_default_prometheus_datasource.png new file mode 100644 index 0000000..3a0c465 Binary files /dev/null and b/quickstart/static/add_default_prometheus_datasource.png differ diff --git a/quickstart/static/first_grafana_dashboard.png b/quickstart/static/first_grafana_dashboard.png new file mode 100644 index 0000000..3e44e23 Binary files /dev/null and b/quickstart/static/first_grafana_dashboard.png differ diff --git a/quickstart/static/get_start_with_grafana2.png b/quickstart/static/get_start_with_grafana2.png new file mode 100644 index 0000000..6085f76 Binary files /dev/null and b/quickstart/static/get_start_with_grafana2.png differ diff --git a/quickstart/static/grafana_dashboards.png.crdownload b/quickstart/static/grafana_dashboards.png.crdownload new file mode 100644 index 0000000..af6aa39 Binary files /dev/null and b/quickstart/static/grafana_dashboards.png.crdownload differ diff --git a/quickstart/static/image049.jpg b/quickstart/static/image049.jpg new file mode 100644 index 0000000..81de6cb Binary files /dev/null and b/quickstart/static/image049.jpg differ diff --git a/quickstart/static/nagios-platform.png b/quickstart/static/nagios-platform.png new file mode 100644 index 0000000..d80d7a0 Binary files /dev/null and b/quickstart/static/nagios-platform.png differ diff --git a/quickstart/static/node_cpu_usage_by_cpu_and_mode.png b/quickstart/static/node_cpu_usage_by_cpu_and_mode.png new file mode 100644 index 0000000..f197dc3 Binary files /dev/null and b/quickstart/static/node_cpu_usage_by_cpu_and_mode.png differ diff --git a/quickstart/static/node_cpu_usage_by_mode.png b/quickstart/static/node_cpu_usage_by_mode.png new file mode 100644 index 0000000..57a0657 Binary files /dev/null and b/quickstart/static/node_cpu_usage_by_mode.png differ diff --git a/quickstart/static/node_cpu_usage_total.png b/quickstart/static/node_cpu_usage_total.png new file mode 100644 index 0000000..574e988 Binary files /dev/null and b/quickstart/static/node_cpu_usage_total.png differ diff --git a/quickstart/static/node_exporter_dashboard.png b/quickstart/static/node_exporter_dashboard.png new file mode 100644 index 0000000..609589e Binary files /dev/null and b/quickstart/static/node_exporter_dashboard.png differ diff --git a/quickstart/static/node_exporter_home_page.png b/quickstart/static/node_exporter_home_page.png new file mode 100644 index 0000000..abea54c Binary files /dev/null and b/quickstart/static/node_exporter_home_page.png differ diff --git a/quickstart/static/node_exporter_metrics_page.png b/quickstart/static/node_exporter_metrics_page.png new file mode 100644 index 0000000..6c2ea1d Binary files /dev/null and b/quickstart/static/node_exporter_metrics_page.png differ diff --git a/quickstart/static/node_node1_graph.png b/quickstart/static/node_node1_graph.png new file mode 100644 index 0000000..8bb3394 Binary files /dev/null and b/quickstart/static/node_node1_graph.png differ diff --git a/quickstart/static/prometheus-release-roadmaps.png b/quickstart/static/prometheus-release-roadmaps.png new file mode 100644 index 0000000..fe4fc2d Binary files /dev/null and b/quickstart/static/prometheus-release-roadmaps.png differ diff --git a/quickstart/static/prometheus-ui-graph.png b/quickstart/static/prometheus-ui-graph.png new file mode 100644 index 0000000..637820f Binary files /dev/null and b/quickstart/static/prometheus-ui-graph.png differ diff --git a/quickstart/static/prometheus_ui_graph_query.png b/quickstart/static/prometheus_ui_graph_query.png new file mode 100644 index 0000000..ccbfe8f Binary files /dev/null and b/quickstart/static/prometheus_ui_graph_query.png differ diff --git a/quickstart/static/prometheus_ui_up_query.png b/quickstart/static/prometheus_ui_up_query.png new file mode 100644 index 0000000..561b429 Binary files /dev/null and b/quickstart/static/prometheus_ui_up_query.png differ diff --git a/quickstart/static/pullvspush.png b/quickstart/static/pullvspush.png new file mode 100644 index 0000000..060c6c0 Binary files /dev/null and b/quickstart/static/pullvspush.png differ diff --git a/quickstart/why-monitor.md b/quickstart/why-monitor.md index a8df67e..36d12da 100644 --- a/quickstart/why-monitor.md +++ b/quickstart/why-monitor.md @@ -2,7 +2,7 @@ Prometheus受启发于Google的Brogmon监控系统(相似的Kubernetes是从Google的Brog系统演变而来),从2012年开始由前Google工程师在Soundcloud以开源软件的形式进行研发,并且于2015年早期对外发布早期版本。2016年5月继Kubernetes之后成为第二个正式加入CNCF基金会的项目,同年6月正式发布1.0版本。2017年底发布了基于全新存储层的2.0版本,能更好地与容器平台、云平台配合。 -![Prometheus简史](http://p2n2em8ut.bkt.clouddn.com/prometheus-release-roadmaps.png) +![Prometheus简史](./static/prometheus-release-roadmaps.png) Prometheus作为新一代的云原生监控系统,目前已经有超过650+位贡献者参与到Prometheus的研发工作上,并且超过120+项的第三方集成。 @@ -20,11 +20,11 @@ Prometheus作为新一代的云原生监控系统,目前已经有超过650+位 对于常用的监控系统,如Nagios、Zabbix的用户而言,往往并不能很好的解决上述问题。这里以Nagios为例,如下图所示是Nagios监控系统的基本架构: -![Nagios监控系统](http://p2n2em8ut.bkt.clouddn.com/nagios-platform.png) +![Nagios监控系统](./static/nagios-platform.png) Nagios的主要功能是监控服务和主机。Nagios软件需要安装在一台独立的服务器上运行,该服务器称为监控中心。每一台被监控的硬件主机或者服务都需要运行一个与监控中心服务器进行通信的Nagios软件后台程序,可以理解为Agent或者插件。 -![Nagios主机监控页面](https://www.ibm.com/developerworks/cn/linux/1309_luojun_nagios/image049.jpg) +![Nagios主机监控页面](./static/image049.jpg) 首先对于Nagios而言,大部分的监控能力都是围绕系统的一些边缘性的问题,主要针对系统服务和资源的状态以及应用程序的可用性。 例如:Nagios通过check_disk插件可以用于检查磁盘空间,check_load用于检查CPU负载等。这些插件会返回4种Nagios可识别的状态,0(OK)表示正常,1(WARNING)表示警告,2(CRITTCAL)表示错误,3(UNKNOWN)表示未知错误,并通过Web UI显示出来。 @@ -49,7 +49,7 @@ Prometheus基于Pull模型的架构方式,可以在任何地方(本地电脑 Pometheus鼓励用户监控服务的内部状态,基于Prometheus丰富的Client库,用户可以轻松的在应用程序中添加对Prometheus的支持,从而让用户可以获取服务和应用内部真正的运行状态。 -![监控服务内部运行状态](http://p2n2em8ut.bkt.clouddn.com/pull%20vspush.png) +![监控服务内部运行状态](./static/pullvspush.png) ##### 强大的数据模型