1. 程式人生 > >02.友盟項目--原始日誌數據生成

02.友盟項目--原始日誌數據生成

ali 服務 throw 當前頁 anroid response app imp 應用

友盟架構圖1

技術分享圖片

友盟架構圖2

技術分享圖片

日誌生成類

技術分享圖片

技術分享圖片
package com.star.umeng.phone.domain;

/**
 * App日誌的公共屬性
 */
public class AppBaseLog {
    private Long createdAtMs;           //日誌創建時間
    private String appId;               //應用唯一標識
    private String tenantId;            //租戶唯一標識,企業用戶
    private String deviceId;            //
設備唯一標識 private String appVersion; //版本 private String appChannel; //渠道,安裝時就在清單中制定了,appStore等。 private String appPlatform; //平臺 private String osType; //操作系統 private String deviceStyle; //機型 public Long getCreatedAtMs() { return createdAtMs; }
public void setCreatedAtMs(Long createdAtMs) { this.createdAtMs = createdAtMs; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getTenantId() { return tenantId; }
public void setTenantId(String tenantId) { this.tenantId = tenantId; } public String getDeviceId() { return deviceId; } public void setDeviceId(String deviceId) { this.deviceId = deviceId; } public String getAppVersion() { return appVersion; } public void setAppVersion(String appVersion) { this.appVersion = appVersion; } public String getAppChannel() { return appChannel; } public void setAppChannel(String appChannel) { this.appChannel = appChannel; } public String getAppPlatform() { return appPlatform; } public void setAppPlatform(String appPlatform) { this.appPlatform = appPlatform; } public String getOsType() { return osType; } public void setOsType(String osType) { this.osType = osType; } public String getDeviceStyle() { return deviceStyle; } public void setDeviceStyle(String deviceStyle) { this.deviceStyle = deviceStyle; } }
AppBaseLog-App日誌的公共屬性 技術分享圖片
package com.star.umeng.phone.domain;

/**
 * 錯誤日誌
 */
public class AppErrorLog extends AppBaseLog {
    private String errorBrief;        //錯誤摘要
    private String errorDetail;       //錯誤詳情

    public String getErrorBrief() {
        return errorBrief;
    }

    public void setErrorBrief(String errorBrief) {
        this.errorBrief = errorBrief;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }
}
AppErrorLog-錯誤日誌 技術分享圖片
package com.star.umeng.phone.domain;

import java.util.Map;

/**
 * 事件日誌
 */
public class AppEventLog extends AppBaseLog {
    private String eventId;                                //事件唯一標識
    private Long eventDurationSecs;                        //事件持續時長
    private Map<String, String> paramKeyValueMap;        //參數名/值對

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public Long getEventDurationSecs() {
        return eventDurationSecs;
    }

    public void setEventDurationSecs(Long eventDurationSecs) {
        this.eventDurationSecs = eventDurationSecs;
    }

    public Map<String, String> getParamKeyValueMap() {
        return paramKeyValueMap;
    }

    public void setParamKeyValueMap(Map<String, String> paramKeyValueMap) {
        this.paramKeyValueMap = paramKeyValueMap;
    }
    //getter/setter
}
AppEventLog-事件日誌 技術分享圖片
package com.star.umeng.phone.domain;

/**
 * 頁面日誌
 */
public class AppPageLog extends AppBaseLog {
    private int pageViewCntInSession = 0;
    private String pageId;                        //頁面id
    private int visitIndex = 0;                    //訪問順序號,0為第一個頁面
    private String nextPage;                    //下一個訪問頁面,空表示為退出應用的頁面
    private Long stayDurationSecs = (long) 0;     //當前頁面停留時長

    public int getPageViewCntInSession() {
        return pageViewCntInSession;
    }

    public void setPageViewCntInSession(int pageViewCntInSession) {
        this.pageViewCntInSession = pageViewCntInSession;
    }

    public String getPageId() {
        return pageId;
    }

    public void setPageId(String pageId) {
        this.pageId = pageId;
    }

    public int getVisitIndex() {
        return visitIndex;
    }

    public void setVisitIndex(int visitIndex) {
        this.visitIndex = visitIndex;
    }

    public String getNextPage() {
        return nextPage;
    }

    public void setNextPage(String nextPage) {
        this.nextPage = nextPage;
    }

    public Long getStayDurationSecs() {
        return stayDurationSecs;
    }

    public void setStayDurationSecs(Long stayDurationSecs) {
        this.stayDurationSecs = stayDurationSecs;
    }
}
AppPageLog --頁面日誌 技術分享圖片
package com.star.umeng.phone.domain;

/**
 * 啟動日誌
 */
public class AppStartupLog extends AppBaseLog {
    private String country;           //國家,終端不用上報,服務器自動填充該屬性
    private String province;          //省份,終端不用上報,服務器自動填充該屬性
    private String ipAddress;         //ip地址

    private String network;           //網絡
    private String carrier;           //運營商

    private String brand;             //品牌
    private String screenSize;        //分辨率

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getNetwork() {
        return network;
    }

    public void setNetwork(String network) {
        this.network = network;
    }

    public String getCarrier() {
        return carrier;
    }

    public void setCarrier(String carrier) {
        this.carrier = carrier;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getScreenSize() {
        return screenSize;
    }

    public void setScreenSize(String screenSize) {
        this.screenSize = screenSize;
    }
}
AppStartupLog --啟動日誌 技術分享圖片
package com.star.umeng.phone.domain;

/**
 * 使用日誌
 */
public class AppUsageLog extends AppBaseLog {
    private Long singleUseDurationSecs;      //單次使用時長
    private Long singleUploadTraffic;        //單次使用過程中的上傳流量
    private Long singleDownloadTraffic;      //單次使用過程中的下載流量

    public Long getSingleUseDurationSecs() {
        return singleUseDurationSecs;
    }

    public void setSingleUseDurationSecs(Long singleUseDurationSecs) {
        this.singleUseDurationSecs = singleUseDurationSecs;
    }

    public Long getSingleUploadTraffic() {
        return singleUploadTraffic;
    }

    public void setSingleUploadTraffic(Long singleUploadTraffic) {
        this.singleUploadTraffic = singleUploadTraffic;
    }

    public Long getSingleDownloadTraffic() {
        return singleDownloadTraffic;
    }

    public void setSingleDownloadTraffic(Long singleDownloadTraffic) {
        this.singleDownloadTraffic = singleDownloadTraffic;
    }
}
AppUsageLog --使用日誌 技術分享圖片
package com.star.umeng.phone.domain;


import java.util.ArrayList;
import java.util.List;

/**
 * 日誌聚合體
 */
public class AppLogAggEntity {
    private String appId;               //應用唯一標識
    private String tenantId;            //租戶唯一標識,企業用戶
    private String deviceId;            //設備唯一標識
    private String appVersion;          //版本
    private String appChannel;          //渠道,安裝時就在清單中制定了,appStore等。
    private String appPlatform;         //平臺
    private String osType;              //操作系統
    private String deviceStyle;         //機型

    //5中類型的日誌集合
    private List<AppStartupLog> startupLogs = new ArrayList<AppStartupLog>();
    private List<AppErrorLog> errorLogs = new ArrayList<AppErrorLog>();
    private List<AppEventLog> eventLogs = new ArrayList<AppEventLog>();
    private List<AppUsageLog> usageLogs = new ArrayList<AppUsageLog>();
    private List<AppPageLog> pageLogs = new ArrayList<AppPageLog>();

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public void setAppVersion(String appVersion) {
        this.appVersion = appVersion;
    }

    public String getAppChannel() {
        return appChannel;
    }

    public void setAppChannel(String appChannel) {
        this.appChannel = appChannel;
    }

    public String getAppPlatform() {
        return appPlatform;
    }

    public void setAppPlatform(String appPlatform) {
        this.appPlatform = appPlatform;
    }

    public String getOsType() {
        return osType;
    }

    public void setOsType(String osType) {
        this.osType = osType;
    }

    public String getDeviceStyle() {
        return deviceStyle;
    }

    public void setDeviceStyle(String deviceStyle) {
        this.deviceStyle = deviceStyle;
    }

    public List<AppStartupLog> getStartupLogs() {
        return startupLogs;
    }

    public void setStartupLogs(List<AppStartupLog> startupLogs) {
        this.startupLogs = startupLogs;
    }

    public List<AppErrorLog> getErrorLogs() {
        return errorLogs;
    }

    public void setErrorLogs(List<AppErrorLog> errorLogs) {
        this.errorLogs = errorLogs;
    }

    public List<AppEventLog> getEventLogs() {
        return eventLogs;
    }

    public void setEventLogs(List<AppEventLog> eventLogs) {
        this.eventLogs = eventLogs;
    }

    public List<AppUsageLog> getUsageLogs() {
        return usageLogs;
    }

    public void setUsageLogs(List<AppUsageLog> usageLogs) {
        this.usageLogs = usageLogs;
    }

    public List<AppPageLog> getPageLogs() {
        return pageLogs;
    }

    public void setPageLogs(List<AppPageLog> pageLogs) {
        this.pageLogs = pageLogs;
    }
}
AppLogAggEntity-- 日誌聚合體

測試生成

技術分享圖片
package com.star.umeng.phone;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 入口點程序
 */
public class Main {
    public static void main(String[] args) throws Exception {
        String strURL = "http://localhost/1.html" ;
        URL url = new URL(strURL) ;
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        //設置請求方式
        conn.setRequestMethod("POST");
        //設置發送的內容類型
        conn.setRequestProperty("Content-Type" , "application/json");
        //允許輸出到服務器
        conn.setDoOutput(true);
        OutputStream out = conn.getOutputStream() ;

        String json = "{\n" + "  \"appChannel\": \"anroid bus\",\n" + "  \"appId\": \"sohuvideo\",\n" + "  \"appPlatform\": \"ios\",\n" + "  \"appVersion\": \"1.1.0\",\n" + "  \"deviceStyle\": \"oppo 1\",\n" + "  \"errorLogs\": [\n" + "    {\n" + "      \"appChannel\": \"umeng\",\n" + "      \"appId\": \"gaodemap\",\n" + "      \"appPlatform\": \"blackberry\",\n" + "      \"appVersion\": \"1.1.0\",\n" + "      \"deviceStyle\": \"vivo 3\",\n" + "      \"errorBrief\": \"at cn.lift.dfdf.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)\",\n" + "      \"errorDetail\": \"at cn.lift.dfdfdf.control.CommandUtil.getInfo(CommandUtil.java:67) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606)\",\n" + "      \"osType\": \"android 4.0\",\n" + "      \"tenantId\": \"tnt023\"\n" + "    }\n" + "  ],\n" + "  \"eventLogs\": [\n" + "    {\n" + "      \"appChannel\": \"anroid bus\",\n" + "      \"appId\": \"tianya\",\n" + "      \"appPlatform\": \"android\",\n" + "      \"appVersion\": \"2.0.0\",\n" + "      \"deviceStyle\": \"紅米\",\n" + "      \"eventId\": \"popmenu\",\n" + "      \"osType\": \"ios11\",\n" + "      \"tenantId\": \"tnt009\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"appstore\",\n" + "      \"appId\": \"gaodemap\",\n" + "      \"appPlatform\": \"android\",\n" + "      \"appVersion\": \"1.1.0\",\n" + "      \"deviceStyle\": \"iphone 7 plus\",\n" + "      \"eventId\": \"popmenu\",\n" + "      \"osType\": \"android 4.0\",\n" + "      \"tenantId\": \"tnt009\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"appstore\",\n" + "      \"appId\": \"faobengplay\",\n" + "      \"appPlatform\": \"blackberry\",\n" + "      \"appVersion\": \"1.0.0\",\n" + "      \"deviceStyle\": \"vivo 3\",\n" + "      \"eventId\": \"autoImport\",\n" + "      \"osType\": \"ios11\",\n" + "      \"tenantId\": \"tnt009\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"anroid bus\",\n" + "      \"appId\": \"tianya\",\n" + "      \"appPlatform\": \"blackberry\",\n" + "      \"appVersion\": \"1.1.0\",\n" + "      \"deviceStyle\": \"iphone 7 plus\",\n" + "      \"eventId\": \"popmenu\",\n" + "      \"osType\": \"mi 5.5\",\n" + "      \"tenantId\": \"tnt009\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"anroid bus\",\n" + "      \"appId\": \"tianya\",\n" + "      \"appPlatform\": \"android\",\n" + "      \"appVersion\": \"1.2.0\",\n" + "      \"deviceStyle\": \"iphone 7\",\n" + "      \"eventId\": \"bookstore\",\n" + "      \"osType\": \"ios11\",\n" + "      \"tenantId\": \"tnt501\"\n" + "    }\n" + "  ],\n" + "  \"osType\": \"ios11\",\n" + "  \"pageLogs\": [\n" + "    null,\n" + "    null,\n" + "    null,\n" + "    null,\n" + "    null\n" + "  ],\n" + "  \"startupLogs\": [\n" + "    {\n" + "      \"appChannel\": \"anroid bus\",\n" + "      \"appId\": \"faobengplay\",\n" + "      \"appPlatform\": \"ios\",\n" + "      \"appVersion\": \"1.2.0\",\n" + "      \"brand\": \"魅族\",\n" + "      \"carrier\": \"中國鐵通\",\n" + "      \"country\": \"america\",\n" + "      \"deviceStyle\": \"vivo 3\",\n" + "      \"network\": \"wifi\",\n" + "      \"osType\": \"android 4.0\",\n" + "      \"province\": \"guangdong\",\n" + "      \"screenSize\": \"480 * 320\",\n" + "      \"tenantId\": \"tnt501\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"appstore\",\n" + "      \"appId\": \"sohuvideo\",\n" + "      \"appPlatform\": \"blackberry\",\n" + "      \"appVersion\": \"2.0.0\",\n" + "      \"brand\": \"Apple\",\n" + "      \"carrier\": \"中國鐵通\",\n" + "      \"country\": \"china\",\n" + "      \"deviceStyle\": \"iphone 7\",\n" + "      \"network\": \"3g\",\n" + "      \"osType\": \"ios11\",\n" + "      \"province\": \"guangxi\",\n" + "      \"screenSize\": \"1136 * 640\",\n" + "      \"tenantId\": \"tnt501\"\n" + "    }\n" + "  ],\n" + "  \"tenantId\": \"tnt009\",\n" + "  \"usageLogs\": [\n" + "    {\n" + "      \"appChannel\": \"umeng\",\n" + "      \"appId\": \"gaodemap\",\n" + "      \"appPlatform\": \"winphone\",\n" + "      \"appVersion\": \"1.1.0\",\n" + "      \"deviceStyle\": \"iphone 7\",\n" + "      \"osType\": \"ios11\",\n" + "      \"tenantId\": \"tnt009\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"anroid bus\",\n" + "      \"appId\": \"tianya\",\n" + "      \"appPlatform\": \"android\",\n" + "      \"appVersion\": \"1.2.0\",\n" + "      \"deviceStyle\": \"iphone 6\",\n" + "      \"osType\": \"android 4.0\",\n" + "      \"tenantId\": \"tnt501\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"umeng\",\n" + "      \"appId\": \"tianya\",\n" + "      \"appPlatform\": \"winphone\",\n" + "      \"appVersion\": \"1.0.0\",\n" + "      \"deviceStyle\": \"vivo 3\",\n" + "      \"osType\": \"mi 5.5\",\n" + "      \"tenantId\": \"tnt023\"\n" + "    },\n" + "    {\n" + "      \"appChannel\": \"umeng\",\n" + "      \"appId\": \"sohuvideo\",\n" + "      \"appPlatform\": \"android\",\n" + "      \"appVersion\": \"1.0.0\",\n" + "      \"deviceStyle\": \"iphone 6 plus\",\n" + "      \"osType\": \"mi 5.5\",\n" + "      \"tenantId\": \"tnt023\"\n" + "    }\n" + "  ]\n" + "}" ;
        out.write(json.getBytes());
        out.flush();
        out.close();
        int code = conn.getResponseCode() ;
        if(code == 200){
            System.out.println("發送ok!!");
        }
    }
}
測試代碼-生成數據

s102--s104查看生成的數據

技術分享圖片

02.友盟項目--原始日誌數據生成