下载镜像包
    docker pull prom/node-exporter docker pull prom/prometheus
    docker pull prom/alertmanager docker pull grafana/grafana

    启动node-exporter
    docker run -d -p 9100:9100 -v “/proc:/host/proc:ro” -v “/sys:/host/sys:ro” -v “/:/rootfs:ro” —net=”host” prom/node-exporter

    访问node-exporter
    http://ip:9100/metrics

    启动prometheus
    新建目录prometheus,编辑配置文件prometheus.yml
    mkdir /opt/prometheus cd /opt/prometheus/
    vim prometheus.yml
    global:
    scrape_interval: 60s
    evaluation_interval: 60s

    scrape_configs:
    - job_name: prometheus
    static_configs:
    - targets: [‘localhost:9090’]
    labels:
    instance: prometheus

    • job_name: linux
      static_configs:
      - targets: [‘ip:9100’]
      labels:
      instance: localhost

    docker run -d -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

    访问url:
    http://ip:9090/graph

    启动grafana
    新建空文件夹grafana-storage,用来存储数据
    mkdir /opt/grafana-storage
    设置权限
    chmod 777 -R /opt/grafana-storage

    docker run -d -p 3000:3000 —name=gragana -v /opt/grafana-storage:/var/lib/grafana grafana/grafana

    监控mysqld_exporter
    windows:通过git下载msyqld_exproter
    linux:通过git下载或者docker拉取

    添加授权用户
    GRANT PROCESS, REPLICATION CLIENT ON . TO ‘pron’@’localhost’ IDENTIFIED BY ‘Prometh.123’ WITH MAX_USER_CONNECTIONS 3;

    使用环境变量启动
    export DATA_SOURCE_NAME=’user:password@(hostname:3306)/‘ # 通过socket连接 export DATA_SOURCE_NAME=pron:Prometh.123@unix(/mysql_pxc/mysql-smy.sock)/ nohup ./mysqld_exporter &
    使用配置文件 ~/.my.cnf 启动
    cat < ~/.my.cnf [client] user=pron password=Prometh.123 EOF # 启动 nohup ./mysqld_exporter —config.my-cnf=~/.my.cnf &
    curl localhost:9104/metrics 即可访问到数据

    监控springboot
    引用Micrometer Registry Prometheus ,micrometer-core依赖文件

    application.properties
    spring.application.name=springboot2demo # 打开所有 Actuator 服务 management.endpoints.web.exposure.include=* # 将应用名称添加到计量器的 tag 中去 # 以便 Prometheus 根据应用名区分不同服务 management.metrics.tags.application=${spring.application.name}

    启动类
    @Bean
    MeterRegistryCustomizer configurer(
    @Value(‘${spring.application.name}’) String applicationName) {
    return { registry -> registry.config().commonTags(“application”, applicationName) };
    }

    prometheus.yml配置
    - job_name: windows_application
    scrape_interval: 5s
    metrics_path: ‘/actuator/prometheus’
    static_configs:
    - targets: [‘192.168.100.73:4000’]
    labels:
    instance: windows_application

    alert报警
    docker run -d —name alertmanager -p 9093:9093 -v /opt/prometheus/alertmanager.yml:/etc/alertmanager/alertmanager.yml prom/alertmanager:latest