Android 性能优化 APM 平台搭建(后端+运维+移动端)

由于答应微信群友分享 Android APM 平台分享,不拖欠了,今天开始分享,否则发红包,既然说了,就总结一下前阵子研究的 Android 性能监控平台

开发缘由

  1. 微信张绍文大佬 《Android开发高手课》中提到 性能优化章节提到过,优化70% 依赖监控性能,30%需要治理,比如App 启动时间第一次优化了 40%,期间升上来了,第二次又优化了40% ,所以需要性能监控平台
  2. 期间找到业内分享最多的就是 流利说APM性能平台大盘工程实践 这篇文章,我参考这篇文章,实现了以下的效果,如图下:
  3. 环境搭建可以参考这篇文章: Prometheus+Grafana搭建监控系统 (需要懂一些后端知识)
  4. 集成 腾讯开源Matrix 监控启动时间(最小版本为19)

最基础版效果图

运维工具:Promethues+Grafana 后端: SpringBoot + MySQL+ Mybaties 移动端:Matrix

Promethues 与 SpringBoot集成问题

Promethues 与 SpringBoot 集成上报比较及时的数据,本来以为就是拼接字符串即可,但是后来才发现需要集成 simpleclient_spring_boot 代码,按照约定俗成的方法上报才可以,如果大家做这方面,需要注册避免这个坑。

pom.xml 依赖:

		<dependency>
			<groupId>io.prometheus</groupId>
			<artifactId>simpleclient_spring_boot</artifactId>
			<version>0.1.0</version>
		</dependency>

		<dependency>
			<groupId>io.prometheus</groupId>
			<artifactId>simpleclient_hotspot</artifactId>
			<version>0.1.0</version>
		</dependency>
复制代码

上报接口:

    @Override
    public List<Collector.MetricFamilySamples> collect() {
        List<MetricFamilySamples> mfs = new ArrayList<>();

        String latestAppVersion = appMapper.getLatestAppVersion();

        // 当前上个版本应用大小
        GaugeMetricFamily pre_labeledGauge = new GaugeMetricFamily("app_pre_app_size", "previous android apk size", Collections.singletonList("labelname"));
        Integer preAppSize = appMapper.getPreAppSize(latestAppVersion);
        pre_labeledGauge.addMetric(Collections.singletonList("labelvalue"), preAppSize);

        // 当前当前版本应用大小
        GaugeMetricFamily labeledGauge = new GaugeMetricFamily("app_cur_app_size", "current android apk size", Collections.singletonList("labelname"));
        Integer curAppSize = appMapper.getCurAppSize(latestAppVersion);
        labeledGauge.addMetric(Collections.singletonList("labelvalue"), curAppSize);


        mfs.add(pre_labeledGauge);
        mfs.add(labeledGauge);
        return mfs;
    }
复制代码

然后是 Promethues 配置:

global:
  scrape_interval: 10s
  scrape_timeout: 10s
  evaluation_interval: 10m
scrape_configs:
  - job_name: app
    scrape_interval: 5s
    // 时间轮训查询
    scrape_timeout: 5s
    // 监听路径接口
    metrics_path: /prometheus
    scheme: http
    static_configs:
      - targets:  ['127.0.0.1:8887']
  - job_name: setuptime
    scrape_interval: 2s
    scrape_timeout: 2s
    metrics_path: /setuptime
    static_configs:
      - targets:  ['127.0.0.1:8887']

复制代码

Grafana 数据来源:

Grafana 数据源有两种形式,比较实时性非常强的 Crash、 ANR、 内存泄露、 冷/热启动耗时、 关键页面耗时 用 prometheus 上报,如果实时性比较弱的话,利用 Mysql 数据上报的形式来读取。

MySQL 数据源

直接集成 MySQL ,流利说采用的是 MariaDB 的记录,然后在 Grafana 配置如下:

配置 Promethues 的数据源:

首先通过命令行 prometheus 启动

./prometheus --config.file=prometheus.yml
复制代码

添加数据源:

然后在显示板配置显示模板,便可以显示出正常的数据,如果不熟悉可参考 环境搭建可以参考 Prometheus+Grafana搭建监控系统

ToDoList

  1. Matrix-ApkChecker + Jekins 扫描打包分享
  2. 后台源码整理开源道Github
  3. ....

转载于:https://juejin.im/post/5cbd25c75188250a7c4c8a60

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值