zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

macOS Grafana Prometheus

macos Prometheus Grafana
2023-09-14 09:09:52 时间

安装Grafana

╰─➤  brew update
╰─➤  brew install grafana

运行Grafana

╰─➤  brew services start grafana

停止Grafana

brew services stop grafana

升级Grafana

brew update
brew reinstall grafana
╰─➤  grafana-server -v                                                                                                                                                                                                                    
Version 7.0.0 (commit: unknown-dev, branch: master)
╰─➤  grafana-server -v
Version 7.2.0 (commit: unknown-dev, branch: master)

登陆Grafana

  • 默认用户名密码admin
http://localhost:3000/login

安装prometheus

brew install prometheus

运行prometheus

brew services start prometheus
╰─➤  prometheus --version
prometheus, version 2.21.0 (branch: non-git, revision: non-git)
╰─➤  cat /usr/local/etc/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
    - targets: ["localhost:9090"]
prometheus --config.file=/usr/local/etc/prometheus.yml
╰─➤  curl http://localhost:9090/metrics
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 5.0972e-05
go_gc_duration_seconds{quantile="0.25"} 7.9818e-05
go_gc_duration_seconds{quantile="0.5"} 0.000109628
go_gc_duration_seconds{quantile="0.75"} 0.000211169
go_gc_duration_seconds{quantile="1"} 0.000414874
go_gc_duration_seconds_sum 0.004110919
go_gc_duration_seconds_count 28
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 38
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.15.1"} 1
http://localhost:9090/graph

在这里插入图片描述

http://localhost:9090/metrics

在这里插入图片描述

  • 查看端口
lsof -i :9090

安装node_exporter

brew install node_exporter
brew services start node_exporter
╰─➤  node_exporter
level=info ts=2020-10-08T10:46:06.898Z caller=node_exporter.go:177 msg="Starting node_exporter" version="(version=1.0.1, branch=, revision=)"
level=info ts=2020-10-08T10:46:06.898Z caller=node_exporter.go:178 msg="Build context" build_context="(go=go1.14.3, user=Homebrew, date=)"
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:105 msg="Enabled collectors"
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=boottime
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=cpu
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=diskstats
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=filesystem
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=loadavg
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=meminfo
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=netdev
level=info ts=2020-10-08T10:46:06.899Z caller=node_exporter.go:112 collector=textfile
level=info ts=2020-10-08T10:46:06.901Z caller=node_exporter.go:112 collector=time
level=info ts=2020-10-08T10:46:06.901Z caller=node_exporter.go:112 collector=uname
level=info ts=2020-10-08T10:46:06.901Z caller=node_exporter.go:191 msg="Listening on" address=:9100
level=info ts=2020-10-08T10:46:06.901Z caller=tls_config.go:170 msg="TLS is disabled and it cannot be enabled on the fly." http2=false
level=error ts=2020-10-08T10:46:06.902Z caller=node_exporter.go:194 err="listen tcp :9100: bind: address already in use"
http://127.0.0.1:9100/metrics

在这里插入图片描述

╰─➤  vim /usr/local/etc/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
    - targets: ["localhost:9090"]

  - job_name: "node"
    static_configs:
      - targets: ["127.0.0.1:9100"]

参考:

  1. macOS安装Grafana
  2. Grafana教程
  3. prometheus下载
  4. Homebrew安装prometheus
  5. 1 Node Exporter for Prometheus Dashboard