Mac 基于Grafana + Promthues + Pushgateway 实现的Android端APM监控实践(1)
随着公司业务不断增加,各个业务不断壮大,每个业务对于app的一些性能指标越来越关注,基于公司目前没有一套完整的APM系统,只能自己去搭建一套完整APM系统
-
环境搭建
-
基于Grafana 安装
brew install grafana
默认安装路径:
/usr/local/Cellar/grafana
启动:
grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana --packaging=brew cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
启动完成之后,在浏览器输入http://localhost:3000/回车进入首页,默认用户名/密码,都是admin,
输入账号和密码后(都是admin),便进去首页
到这里General已经成功安装和启动了,但是General对于我们来说只是一个UI展示界面,具体数据来源需要自己添加,如下图,General目前之前很多数据来源
本文选择的数据源是Promthues
-
Promthues 安装
brew install prometheus
默认的安装路径为:
/usr/local/Cellar/prometheus
同时还会生成一个默认配置文件:/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
顺利的话,应该能正常启动成功,在浏览器输入http://localhost:9090回车进入首页
这样Promthues便安装成功了
-
Pushgateway 安装
从官网prometheus.io/download/上选择最新的pushgateway-1.4.1.darwin-amd64.tar.gz进行下载
下载完成后解压到本地,然后进入解压后的目录输入
./pushgateway
启动正常的话,浏览http://localhost:9091 可以看到,为什么要安装Pushgateway呢,如下是Pushgateway和Promthues工作流程图
客户端(不管是写代码,还是直接终端敲命令行)把数据push到网关(pushgateway),然后prometheus从网关pull数据。
安装好之后,还要修改/usr/local/etc/prometheus.yml 不然prometheus感知不到网关的存在
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# 加入下面这几行
- job_name: "push-metrics"
static_configs:
- targets: ["localhost:9091"]
honor_labels: true
加入最后这几行即可,改完后最好把prometheus重启一下,以便让配置文件生效。
到这里General,Promthues,Pushgateway环境安装已经完成,下一期将给大家介绍怎么上传数据到Promthues和General配置Promthues为数据源的展示