From c084493c6518e71d043546f967dbbf5492e4e273 Mon Sep 17 00:00:00 2001 From: "zhenmu.zyl" Date: Mon, 22 Oct 2018 21:56:54 +0800 Subject: [PATCH] update quick start content --- README.md | 1 + SUMMARY.md | 1 + quickstart/install-prometheus-server.md | 6 +-- .../prometheus-architecture-and-components.md | 2 +- quickstart/prometheus-quick-start.md | 2 +- quickstart/promql_quickstart.md | 35 +++++++++++++++ quickstart/use-grafana-create-dashboard.md | 44 +------------------ quickstart/use-node-exporter.md | 8 +++- 8 files changed, 49 insertions(+), 50 deletions(-) create mode 100644 quickstart/promql_quickstart.md diff --git a/README.md b/README.md index daa239e..24627db 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ * [初识Prometheus](./quickstart/prometheus-quick-start.md) * [安装Prometheus Server](./quickstart/install-prometheus-server.md) * [使用Node Exporter采集主机数据](./quickstart/use-node-exporter.md) + * [使用PromQL查询监控数据](./quickstart/promql_quickstart.md) * [监控数据可视化](./quickstart/use-grafana-create-dashboard.md) * [任务和实例](./quickstart/prometheus-job-and-instance.md) * [Prometheus核心组件](./quickstart/prometheus-architecture-and-components.md) diff --git a/SUMMARY.md b/SUMMARY.md index daa239e..24627db 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -9,6 +9,7 @@ * [初识Prometheus](./quickstart/prometheus-quick-start.md) * [安装Prometheus Server](./quickstart/install-prometheus-server.md) * [使用Node Exporter采集主机数据](./quickstart/use-node-exporter.md) + * [使用PromQL查询监控数据](./quickstart/promql_quickstart.md) * [监控数据可视化](./quickstart/use-grafana-create-dashboard.md) * [任务和实例](./quickstart/prometheus-job-and-instance.md) * [Prometheus核心组件](./quickstart/prometheus-architecture-and-components.md) diff --git a/quickstart/install-prometheus-server.md b/quickstart/install-prometheus-server.md index 19cb84c..dba0582 100644 --- a/quickstart/install-prometheus-server.md +++ b/quickstart/install-prometheus-server.md @@ -1,8 +1,8 @@ -## 安装Prometheus Server +# 安装Prometheus Server Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖。用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server。 -### 从二进制包安装 +## 从二进制包安装 对于非Docker用户,可以从[https://prometheus.io/download/](https://prometheus.io/download/)找到最新版本的Prometheus Sevrer软件包: @@ -68,7 +68,7 @@ level=info ts=2018-03-11T13:38:06.317645234Z caller=main.go:486 msg="Server is r level=info ts=2018-03-11T13:38:06.317679086Z caller=manager.go:59 component="scrape manager" msg="Starting scrape manager..." ``` -### 使用容器安装 +## 使用容器安装 对于Docker用户,直接使用Prometheus的镜像即可启动Prometheus Server: diff --git a/quickstart/prometheus-architecture-and-components.md b/quickstart/prometheus-architecture-and-components.md index d5cff30..1c65d2d 100644 --- a/quickstart/prometheus-architecture-and-components.md +++ b/quickstart/prometheus-architecture-and-components.md @@ -1,4 +1,4 @@ -# Prometheus的核心组件 +# Prometheus组件 上一小节,通过部署Node Exporter我们成功的获取到了当前主机的资源使用情况。接下来我们将从Prometheus的架构角度详细介绍Prometheus生态中的各个组件。 diff --git a/quickstart/prometheus-quick-start.md b/quickstart/prometheus-quick-start.md index ef40c81..8c33b10 100644 --- a/quickstart/prometheus-quick-start.md +++ b/quickstart/prometheus-quick-start.md @@ -1,3 +1,3 @@ # 初识Prometheus -为了能够更加直观的了解Prometheus Server,接下来我们将在本地部署一个Prometheus Server实例,并且配合Node Exporter程序实现对本地主机指标的监控。 +Prometheus是一个开放性的监控解决方案,用户可以非常方便的安装和使用Prometheus并且能够非常方便的对其进行扩展。为了能够更加直观的了解Prometheus Server,接下来我们将在本地部署并运行一个Prometheus Server实例,通过Node Exporter采集当前主机的系统资源使用情况。 并通过Grafana创建一个简单的可视化仪表盘。 diff --git a/quickstart/promql_quickstart.md b/quickstart/promql_quickstart.md new file mode 100644 index 0000000..bec67dd --- /dev/null +++ b/quickstart/promql_quickstart.md @@ -0,0 +1,35 @@ +# 使用PromQL查询监控数据 + +Prometheus UI是Prometheus内置的一个可视化管理界面,通过Prometheus UI用户能够轻松的了解Prometheus当前的配置,监控任务运行状态等。 通过`Graph`面板,用户还能直接使用`PromQL`实时查询监控数据: + +![Graph Query](./static/prometheus_ui_graph_query.png) + +切换到`Graph`面板,用户可以使用PromQL表达式查询特定监控指标的监控数据。如下所示,查询主机负载变化情况,可以使用关键字`node_load1`可以查询出Prometheus采集到的主机负载的样本数据,这些样本数据按照时间先后顺序展示,形成了主机负载随时间变化的趋势图表: + +![主机负载情况](./static/node_node1_graph.png) + +PromQL是Prometheus自定义的一套强大的数据查询语言,除了使用监控指标作为查询关键字以为,还内置了大量的函数,帮助用户进一步对时序数据进行处理。例如使用`rate()`函数,可以计算在单位时间内样本数据的变化情况即增长率,因此通过该函数我们可以近似的通过CPU使用时间计算CPU的利用率: + +``` +rate(node_cpu[2m]) +``` + +![系统进程的CPU使用率](./static/node_cpu_usage_by_cpu_and_mode.png) + +这时如果要忽略是哪一个CPU的,只需要使用without表达式,将标签CPU去除后聚合数据即可: + +``` +avg without(cpu) (rate(node_cpu[2m])) +``` + +![系统各mode的CPU使用率](./static/node_cpu_usage_by_mode.png) + +那如果需要计算系统CPU的总体使用率,通过排除系统闲置的CPU使用率即可获得: + +``` +1 - avg without(cpu) (rate(node_cpu{mode="idle"}[2m])) +``` + +![系统CPU使用率](./static/node_cpu_usage_total.png) + +通过PromQL我们可以非常方便的对数据进行查询,过滤,以及聚合,计算等操作。通过这些丰富的表达书语句,监控指标不再是一个单独存在的个体,而是一个个能够表达出正式业务含义的语言。 \ No newline at end of file diff --git a/quickstart/use-grafana-create-dashboard.md b/quickstart/use-grafana-create-dashboard.md index 6ad39c2..6f43961 100644 --- a/quickstart/use-grafana-create-dashboard.md +++ b/quickstart/use-grafana-create-dashboard.md @@ -1,46 +1,4 @@ -## 监控数据可视化 - -### 使用Prometheus UI - -通过Prometheus UI用户可以利用PromQL实时查询监控数据,并且支持一些基本的数据可视化能力。进入到Prometheus UI,切换到Graph标签 - -![Graph Query](./static/prometheus_ui_graph_query.png) - -通过PromQL则可以直接以可视化的形式显示查询到的数据。例如,查询主机负载变化情况,可以使用: - -``` -node_load1 -``` - -![主机负载情况](./static/node_node1_graph.png) - -查询主机CPU的使用率,由于node_cpu的数据类型是Counter,计算使用率需要使用rate()函数: - -``` -rate(node_cpu[2m]) -``` - -![系统进程的CPU使用率](./static/node_cpu_usage_by_cpu_and_mode.png) - -这时如果要忽略是哪一个CPU的,只需要使用without表达式,将标签CPU去除后聚合数据即可: - -``` -avg without(cpu) (rate(node_cpu[2m])) -``` - -![系统各mode的CPU使用率](./static/node_cpu_usage_by_mode.png) - -那如果需要计算系统CPU的总体使用率,通过排除系统闲置的CPU使用率即可获得: - -``` -1 - avg without(cpu) (rate(node_cpu{mode="idle"}[2m])) -``` - -![系统CPU使用率](./static/node_cpu_usage_total.png) - -从上面这些例子中可以看出,根据样本中的标签可以很方便地对数据进行查询,过滤以及聚合等操作。同时PromQL中还提供了大量的诸如rate()这样的函数可以实现对数据的更多个性化的处理。 - -## 使用Grafana创建可视化Dashboard +# 使用Grafana创建可视化Dashboard Prometheus UI提供了快速验证PromQL以及临时可视化支持的能力,而在大多数场景下引入监控系统通常还需要构建可以长期使用的监控数据可视化面板(Dashboard)。这时用户可以考虑使用第三方的可视化工具如Grafana,Grafana是一个开源的可视化平台,并且提供了对Prometheus的完整支持。 diff --git a/quickstart/use-node-exporter.md b/quickstart/use-node-exporter.md index afcdfc5..c6fe471 100644 --- a/quickstart/use-node-exporter.md +++ b/quickstart/use-node-exporter.md @@ -1,4 +1,6 @@ -## 使用Node Exporter采集主机运行数据 +# 使用Node Exporter采集主机运行数据 + +## 安装Node Exporter 在Prometheus的架构设计中,Prometheus Server并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的CPU使用率,我们需要使用到Exporter。Prometheus周期性的从Exporter暴露的HTTP服务地址(通常是/metrics)拉取监控样本数据。 @@ -31,7 +33,7 @@ INFO[0000] Listening on :9100 source="node_exporter.g ![Node Exporter页面](./static/node_exporter_home_page.png) -### Node Exporter监控指标 +### 初始Node Exporter监控指标 访问[http://localhost:9100/metrics](http://localhost:9100/metrics),可以看到当前node exporter获取到的当前主机的所有监控数据,如下所示: @@ -63,6 +65,8 @@ node_load1 3.0703125 * go_*:node exporter中go相关指标 * process_*:node exporter自身进程相关运行指标 +## 从Node Exporter收集监控数据 + 为了能够让Prometheus Server能够从当前node exporter获取到监控数据,这里需要修改Prometheus配置文件。编辑prometheus.yml并在scrape_configs节点下添加以下内容: ```