只需要一个选项:在只用自己的Windows PC上体验Prometheus和Grafana,并仅花费15分钟
这篇文章针对那些时间有限但希望能迅速吸收新技术的人。我们的目标是让用户通过在自己的Windows PC上运行服务器监控工具Prometheus+Grafana,来体验这项技术,并且做到简单方便。
目标

环境
・操作系统:Windows10专业版(1803) x64 (日本语版)
・Prometheus:v2.3.2 (windows-amd64)
・WMI导出器:v0.3.4 (amd64)
・Grafana:v5.2.2 (windows-amd64)
作业的步骤
-
- 安装 WMI exporter
-
- 安装 Prometheus
- 安装 Grafana
WMI导出器的安装
请下载
从以下网站中下载并解压缩”wmi_exporter-amd64.zip”。

启动 WMI 导出器。
从资源管理器中双击执行「wmi_exporter.exe」。

在路上,出现错误提示,但是暂时先忽略它。
Prometheus的引入
下载 (xià
前往以下网站:
https://prometheus.io/download/
在下拉菜单中选择以下值:
– 操作系统:Windows
– 架构:amd64
请下载并解压名为“prometheus-2.3.2.windows-amd64.tar.gz”的文件。

启动 Prometheus
修改配置文件
把「prometheus.yml」中的「scrape_configs > static_configs > targets」更改如下:
更改前:[‘localhost:9090’]
更改后:[‘localhost:9182’]
这似乎是要将监控对象更改为WMI exporter。
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
# - targets: ['localhost:9090']
- targets: ['localhost:9182']
开机
在资源管理器中双击「prometheus.exe」进行执行。

如果看到「服务器已准备好接收网页请求」的输出,我认为一切都没问题。
请确认 Prometheus 的执行情况。
当您在浏览器中打开”http://localhost:9090″时,将会看到如下的页面。



Grafana 的安装
下载
请从以下链接下载并解压缩文件「grafana-5.2.2.windows-amd64.zip」。

将「wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.2.windows-amd64.zip」中的URL部分设置在浏览器中,并直接下载并解压。
创建”数据”文件夹
在合适的地方创建一个名为”data”的文件夹。
以下将以在”c:\grafana-5.2.2\data”中创建文件夹为例来进行说明。
更改配置文件
将「conf/sample.ini」复制到「conf/custom.ini」,并进行以下三个地方的更改。
更改前
[paths]
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
;data = /var/lib/grafana
# Directory where grafana can store logs
;logs = /var/log/grafana
# Directory where grafana will automatically scan and look for plugins
;plugins = /var/lib/grafana/plugins
[更改后]
[paths]
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
# ;data = /var/lib/grafana
;data = C:\grafana-5.2.2\data
# Directory where grafana can store logs
# ;logs = /var/log/grafana
;logs = C:\grafana-5.2.2\data\log
# Directory where grafana will automatically scan and look for plugins
# ;plugins = /var/lib/grafana/plugins
;plugins = C:\grafana-5.2.2\data\plugins
启动Grafana。
在命令提示符中,转到“grafana-5.2.2\bin”目录,并执行以下操作。
grafana-server.exe --config ..\conf\custom.ini
然后,首次启动时会显示以下对话框,请选择“允许访问”。

确认 Grafana 是否正在运行。


创建数据源
点击「添加数据源」。
会出现设置数据源的界面。

在此处,点击「保存并测试」按钮。
如果显示为「数据源正常工作」,则表示一切正常。
仪表盘的下载

在”筛选>在此列表中搜索”中,输入”wmi_exporter”,然后选择显示出来的”Windows Node”。

导入仪表板和显示仪表板

请选择「上传 .json 文件」,然后指定先前下载的 JSON 文件。


最终
当Grafana仪表盘成功显示后,您可以尽情玩耍,比如移动仪表盘的盒子,最大化显示等等。
嗯,到目前为止你用了15分钟完成了吗?
如果你能告诉我实际花了多长时间,我会参考一下。