Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter

安装启动Grafana

brew install Grafana brew services start grafana

启动后,通过http://localhost:3000/访问,用户名和密码都是admin,如图:

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Grafana
安装启动Prometheus
brew install prometheus brew services start prometheus

安装启动node_exporter
brew install node_exporter brew services start node_exporter

启动后,可以通过http://localhost:9100/查看,如图:

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
node_exporter
安装启动mysqld_exporter
docker pull prom/mysqld-exporter docker run -d -p 9104:9104 -e DATA_SOURCE_NAME="username:passwd@(localhost:3306)/dbname" prom/mysqld-exporter

安装启动cadvisor
#安装 docker pull google/cadvisor:latest #启动 docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/dev/disk/:/dev/disk:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ google/cadvisor:latest

启动后,访问http://localhost:8080/metrics,查看暴露给Prometheus的数据。
访问http://localhost:8080/containers/,查看各个container的数据,如图:

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
containers
配置Prometheus 配置文件默认放在/usr/local/etc/prometheus.yml,重启服务生效
scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] labels: instance: prometheus - job_name: "node_exporter" static_configs: - targets: ["localhost:9100"] labels: instance: node_exporter - job_name: mysqld_exporter static_configs: - targets: ['localhost:9104'] labels: instance: mysqld_exporter - job_name: 'cadvisor' static_configs: - targets: ['127.0.0.1:8080'] labels: instance: cadvisor

启动后,可以通过http://localhost:9090/打开,查询go_threads语句,如图:

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Prometheus
配置Grafana的Prometheus数据源 首先找到Configuration的Data Sources,

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Configuration
然后Add data source,添加Prometheus

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Add data source
设置Prometheus的URL,Save&Test,添加完成。
Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Prometheus 添加dashboard 直接import Prometheus Stats等dashboard

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
dashboard
【Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter】点击进入Prometheus Stats,如图:

Mac搭建Grafana+Prometheus+NodeExporter+mysqld-exporter
文章图片
Prometheus Stats

    推荐阅读