[TOC] ## 一、服务器监控 ### 1. 安装运行 node-exporter ~~~ docker run -d \ --name node-exporter \ -p 9100:9100 \ -v "/proc:/host/proc" \ -v "/sys:/host/sys" \ -v "/:/rootfs" \ --net="host" \ prom/node-exporter ~~~ ### 2. 修改prometheus的配置 ~~~ - job_name: 'node' static_configs: - targets: ['172.16.90.34:9100'] labels: env: test name: node1 instance: 172.16.90.34 ~~~ ## 二、MySQL监控 ### 1\. 安装运行 mysqld-exporter ~~~ docker run -d \ --name mysqld-exporter \ -p 9104:9104 \ -e DATA_SOURCE_NAME="root:123456@(172.16.90.9:3306)/nacos-test" \ prom/mysqld-exporter ~~~ ### 2\. 修改prometheus的配置 ~~~ - job_name: 'mysqld' static_configs: - targets: ['172.16.90.34:9104'] labels: env: test name: mysql-5.7 instance: 172.16.90.9:3306 ~~~ ## 三、Redis监控 ### 1\. 安装运行 redis-exporter ~~~ docker run -d \ --name redis_exporter \ -p 9121:9121 \ oliver006/redis_exporter \ --redis.addr redis://172.16.90.9:6379 \ --redis.password 123456 ~~~ ### 2\. 修改prometheus的配置 ~~~ - job_name: redis static_configs: - targets: ['172.16.90.34:9121'] labels: env: test name: redis instance: 172.16.90.34:6379 ~~~ ## 四、Nacos监控 ### 1\. 配置nacos的application.properties文件,暴露metrics数据 ~~~ management.endpoints.web.exposure.include=* ~~~ ### 2\. 修改prometheus的配置 ~~~ - job_name: nacos metrics_path: "/nacos/actuator/prometheus" static_configs: - targets: ['172.16.90.34:8848'] labels: env: test name: nacos instance: 172.16.90.34:8848 ~~~ ## 五、Elasticsearch监控 ### 1\. 安装 elasticsearch-exporter 插件 ~~~ cd elasticsearch-6.6.1 ./bin/elasticsearch-plugin install -b https://distfiles.compuscene.net/elasticsearch/elasticsearch-prometheus-exporter-6.6.1.0.zip ~~~ ### 2\. 修改prometheus的配置 ~~~ - job_name: elasticsearch scrape_interval: 10s metrics_path: "/_prometheus/metrics" static_configs: - targets: ['172.16.90.34:9200'] labels: env: test name: elasticsearch ~~~ ## 六、微服务监控 通过file_sd_configs进行服务发现的配置,每次json文件的内容发生变更,Prometheus会自动刷新target列表 保存到/docker/prometheus/conf/file_sd_configs目录下 >[danger]注意路径,如果没有在prometheus中发现http://172.16.90.33:9090/targets有对应的jon_name,可以查看log日志查询是否是找不到路径 ### 1\. 配置服务的json文件 ~~~ [ { "targets": [ "192.168.20.89:9000" ], "labels": { "job":"spring-cloud-service", "env":"test", "application":"spring-cloud-service-test", "instance":"192.168.20.89:9000" } }, { "targets": [ "192.168.20.89:9001" ], "labels": { "job":"spring-cloud-service", "env":"test", "application":"spring-cloud-service-test1", "instance":"192.168.20.89:9001" } } ] ~~~ ### 2\. 修改prometheus的配置 ~~~ - job_name: spring-cloud-service metrics_path: "/actuator/prometheus" file_sd_configs: - files: - file_sd_configs/springcloud/*.json refresh_interval: 10s ~~~