As promised wechat group friends to share Android APM platform to share, not default, today began to share, otherwise send red envelopes, since said, summed up a while ago to study the Android performance monitoring platform

Development of reason

  1. Wechat zhang Shaowen “Android Development Master Class” mentioned in the performance optimization chapter mentioned that 70% of the optimization depends on monitoring performance, and 30% needs governance, for example, the App startup time was optimized for the first time by 40%, during the upgrade, and the second time by 40%, so the performance monitoring platform is needed
  2. During this period, I found that the most shared article in the industry was the article fluently describing APM performance platform large-scale engineering practice. I referred to this article and realized the following effects, as shown in the figure below:
  3. See this article for environment setup: Prometheus+Grafana Monitoring System setup (some back-end knowledge required)
  4. Integrated Tencent open source Matrix monitoring startup time (minimum version: 19)

Most basic version of the renderings

Operation and maintenance tool: Promethues+Grafana Back-end: SpringBoot + MySQL+ Mybaties Mobile terminal: Matrix

Promethues is not integrated with SpringBoot

Promethues and SpringBoot integrate to report timely data, which is thought to be a concatenated string. However, later I realized that simpleclient_Spring_boot code needs to be integrated to report timely data. If you do this, Registration is required to avoid this pit.

Pom. XML depends on:

< the dependency > < groupId > IO. Prometheus < / groupId > < artifactId > simpleclient_spring_boot < / artifactId > < version > 0.1.0 from < / version >  </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_hotspot</artifactId> The < version > 0.1.0 from < / version > < / dependency >Copy the code

Reporting interface:

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

        String latestAppVersion = appMapper.getLatestAppVersion();

        // The current application size of the previous version
        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);

        // Current Application size of the current version
        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;
    }
Copy the code

Then there is the Promethues configuration:

global:
  scrape_interval: 10s
  scrape_timeout: 10s
  evaluation_interval: 10m
scrape_configs:
  - job_name: app
    scrape_interval: 5s
    // time rotation query
    scrape_timeout: 5s
    // Listen on the path interface
    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']

Copy the code

Grafana data source:

Grafana data source has two forms. Compared with Crash, ANR, memory leak, cold/hot startup time, and key page time with strong real time, it is reported by Prometheus; if real time is weak, it is read by Mysql data.

MySQL data source

Grafana = MariaDB; Grafana = MariaDB; Grafana = MariaDB; Grafana = MariaDB;

Configure a data source for Promethues:

Start from the command line Prometheus

./prometheus --config.file=prometheus.yml
Copy the code

Adding a data source:

Prometheus+Grafana built the monitoring system

ToDoList

  1. Matrix-ApkChecker + Jekins scan package share
  2. Backstage source code collation open source way Github
  3. .