admin管理员组

文章数量:1570368

生产环境安装配置Prometheus+Grafana(windows版)

1.介绍

1.1.Prometheus是什么?

Prometheus(普罗米修斯)是一个最初在SoundCloud上构建的监控系统。自2012年成为社区开源项目,拥有非常活跃的开发人员和用户社区。为强调开源及独立维护,Prometheus于2016年加入云原生云计算基金会(CNCF),成为继Kubernetes之后的第二个托管项目。

https://prometheus.io

https://github/prometheus

作为新一代的监控框架,Prometheus 具有以下特点:

• 多维数据模型:由度量名称和键值对标识的时间序列数据

• PromSQL:一种灵活的查询语言,可以利用多维数据完成复杂的查询

• 不依赖分布式存储,单个服务器节点可直接工作

• 基于HTTP的pull方式采集时间序列数据

• 推送时间序列数据通过PushGateway组件支持

• 通过服务发现或静态配置发现目标

• 多种图形模式及仪表盘支持

Prometheus适用于以机器为中心的监控以及高度动态面向服务架构的监控。

1.2.Grafana是什么?

Grafana是一个开源的度量分析和可视化系统。

Grafana支持查询普罗米修斯。自Grafana 2.5.0(2015-10-28)以来,包含了Prometheus的Grafana数据源。

https://grafana/grafana/download

从Grafana导入预先构建的仪表板。

Grafana维护着一组共享仪表板 ,可以下载并与Grafana的独立实例一起使用。

https://grafana/dashboards/9276

简单来说:Grafana提供了比Prometheus更加友好美观的展示界面

2.前期准备

依赖:JDK1.8

安装包:

组件说明
prometheus-2.39.1.windows-amd64监控server端,用于汇总展示各收集器的资源情况(界面丑)
windows_exporter-0.20.0-386windows资源收集器,将宿主机的资源情况汇报给server端
blackbox_exporter-0.18.0.windows-amd64黑盒收集器,可配置tcp监听和http监听
grafana-8.1.2.windows-amd64度量分析可视化系统,仪表盘多,替换prometheus默认展示界面

3.部署配置Prometheus

  • 在全英文路径下解压prometheus-2.39.1.windows-amd64.zip

  • 修改prometheus.yml,将localhost改为127.0.0.1,避免出现莫名其妙的问题(其它涉及到localhost的配置,也是改为127.0.0.1)

  • 双击prometheus.exe启动prometheus,任务栏会新增一个黑窗口(不要关闭)
  • 浏览器打开http://127.0.0.1:9090/targets,prometheus状态为up,出现如下界面即成功

4.部署配置windows资源采集器

  • 用管理员身份运行windows_exporter-0.20.0-386.msi,运行成功后服务中可以看到windows_exporter服务

  • 将服务状态改为“自动(延迟启动)”

  • 浏览器访问http://127.0.0.1:9182/metrics,看到如下界面成功

  • 在prometheus端配置windows_exporter采集器地址,在prometheus.yml同级目录新建windows.yml

  • windows.yml输入如下内容 (注意缩进)

    - targets: ["127.0.0.1:9182"]
      labels:
        instance: 127.0.0.1
        serverName: '本地windows服务器'
    
  • prometheus.yml中添加如下内容 (注意缩进)

      - job_name: "windows"
        file_sd_configs:
        - refresh_interval: 15s
          files: 
          - ".\\windows.yml"
    

  • 重启prometheus端,打开http://127.0.0.1:9090/targets,windows状态为up即成功

5.部署配置黑盒采集器

  • 在全英文路径下解压blackbox_exporter-0.18.0.windows-amd64.zip,双击blackbox_exporter.exe,任务栏会新增一个黑窗口(不要关闭)

  • 浏览器访问http://127.0.0.1:9115,看到如下界面成功

  • 在prometheus端配置blackbox_exporter采集器地址,在prometheus.yml同级目录新建tcp.yml

  • tcp.yml输入如下内容 (注意缩进)

    - targets: ['127.0.0.1:3306']
      labels:
        group: 'app'
        appName: 'mysql'
        describe: 'mysql数据库'
    

    这里以采集mysql端口存活情况为例,我本机已提前启动mysql服务,端口3306,生产环境配置成具体服务即可,其中group取值app为中间件,group取值server为微服务,具体效果见最后一张图

  • prometheus.yml中添加如下内容 (注意缩进)

      - job_name: "telnet_port"
        metrics_path: /probe
        params:
          module: [tcp_connect]
        file_sd_configs:
        - refresh_interval: 15s
          files: 
          - ".\\tcp.yml"
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: 127.0.0.1:9115
    

  • 重启prometheus端,打开http://127.0.0.1:9090/targets,telnet_port状态为up即成功

6.部署配置Grafana

可以看到prometheus的默认界面比较单一,可看到的关键资源信息不多,下面使用Grafana展示具体资源状况

  • 在全英文路径下解压grafana-8.1.2.windows-amd64.zip,双击bin目录下grafana-server.exe,任务栏会新增一个黑窗户(不要关闭)

  • 浏览器打开http://127.0.0.1:3000(默认账号密码都是admin)

  • 创建数据源,关联prometheus端

    1、点击设置(小齿轮),选择Data sources

    2、点击Add data source,选择Prometheus

    3、全部使用默认配置, 这里一定要将localhost改为127.0.0.1,下拉,点击Save & test

  • 导入仪表盘

    1、打开Dashboards-Manage,点击import

    2、点击Upload JSON file,上传仪表盘json文件,一次上传一个,选择模板,点击import

  • 打开Dashboards,这里已经添加了[windows资源监控]、[中间件和微服务监控],两个仪表盘,选择对应的打开详情如下

完结!!!

如需仪表盘JSON模板请留言

本文标签: 环境prometheusWindowsGrafana