当前位置 主页 > 服务器问题 > win服务器问题汇总 >

    利用Prometheus与Grafana对Mysql服务器的性能监控详解

    栏目:win服务器问题汇总 时间:2019-12-05 14:42

    概述

    Prometheus是一个开源的服务监控系统,它通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。它提供了一个简单的网页界面、一个功能强大的查询语言以及HTTP接口等等。Prometheus通过安装在远程机器上的exporter来收集监控数据,这里用到了以下两个exporter:

    node_exporter – 用于机器系统数据 mysqld_exporter – 用于Mysql服务器数据

    Grafana是一个开源的功能丰富的数据可视化平台,通常用于时序数据的可视化。它内置了以下数据源的支持:

    并可以通过插件扩展支持的数据源。

    架构图

    下面是本次部署的架构图

    安装并运行Prometheus

    1.在 Monitor 上安装 Prometheus

    安装至/opt/prometheus

    $ wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz
    $ tar zxvf prometheus-1.5.2.linux-amd64.tar.gz
    $ mv prometheus-1.5.2.linux-amd64 /opt/prometheus

    2.在安装目下编辑配置文件 prometheus.yml

    vim /opt/prometheus/prometheus.yml
    # 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).
     # Attach these labels to any time series or alerts when communicating with
     # external systems (federation, remote storage, Alertmanager).
     external_labels:
     monitor: 'codelab-monitor'
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
     # - "first.rules"
     # - "second.rules"
    # 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']
     # 以下是添加的部分
     - job_name: linux
     static_configs:
     - targets: ['172.30.251.214:9100']
     labels:
     instance: db1
     - job_name: mysql
     static_configs:
     - targets: ['172.30.251.214:9104']
     labels:
     instance: db1

    其中:172.30.251.214是MySQL的IP,端口则是对应的exporter的监听端口。

    3.启动Prometheus

    [loya@centos6 prometheus]$ ./prometheus
    INFO[0000] Starting prometheus (version=1.5.2, branch=master, revision=bd1182d29f462c39544f94cc822830e1c64cf55b) source=main.go:75
    INFO[0000] Build context (go=go1.7.5, user=root@a8af9200f95d, date=20170210-14:41:22) source=main.go:76
    INFO[0000] Loading configuration file prometheus.yml source=main.go:248
    INFO[0000] Loading series map and head chunks... source=storage.go:373
    INFO[0000] 0 series loaded. source=storage.go:378
    INFO[0000] Starting target manager... source=targetmanager.go:61
    INFO[0000] Listening on :9090 source=web.go:259