123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- -- 服务端埋点日志工具文件
- local skynet = require "skynet"
- local timeUtil = require "utils.timeUtil"
- local lib_game_redis = require("lib_game_redis")
- local redisUtil = require("utils.redisUtil")
- local root = {}
- local function writeServerLog(key, date, data)
- assert(key and date)
- skynet.send("statisticLog", "lua", "add_file_log", key, date, data)
- end
- function root.getActiveKey(date)
- return "active:uid:" .. date
- end
- function root.formatData(data)
- return table.concat(data, ";")
- end
- function root.formatContent(data)
- return table.concat(data, ",")
- end
- -- 新增活跃天玩家
- local function l_add_active_user(uid)
- local currTime = timeUtil.currentTime()
- local date = timeUtil.toDate(currTime)
- local key = root.getActiveKey(date)
- -- log.info("l_add_active_user key[%s] uid[%s]", tostring(key), tostring(uid))
- lib_game_redis:sadd(key, uid)
- end
- -- 服务端事件埋点
- function root.logEvent(uid, bandShareCode, version, channel, eventId, extraParams)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local cnt =
- string.format(
- "%s;%s;%s;%s;%s;%s;%s;%s",
- tostring(date),
- tostring(dateStr),
- tostring(uid or ""),
- tostring(bandShareCode or ""),
- tostring(channel or 0),
- tostring(version or ""),
- tostring(eventId or ""),
- tostring(extraParams or "")
- )
- writeServerLog("event", date, cnt)
- end
- -- 服务端资源埋点
- function root.logResource(uid, eventId, itemId, resChgs, resResult, channel, bandShareCode)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local cnt =
- string.format(
- "%s;%s;%s;%s;%s;%s;%s;%s;%s",
- tostring(date),
- tostring(dateStr),
- tostring(uid),
- tostring(bandShareCode or ""),
- tostring(channel),
- tostring(eventId),
- tostring(itemId),
- tostring(resChgs or 0),
- tostring(resResult or 0)
- )
- writeServerLog("resource", date, cnt)
- end
- -- 服务端注册埋点
- function root.logRegister(uid, bandShareCode, channel, version, machineType, uuid, udid, ip)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or "",
- bandShareCode or "",
- channel or "",
- version or "",
- machineType or "",
- uuid or "",
- udid or "",
- ip or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("register", date, dataStr)
- end
- -- 服务端登录埋点
- function root.logLogin(uid, bandShareCode, channel, version, machineType, operator, network, uuid, udid, ip)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or 0,
- bandShareCode or "",
- channel or "",
- version or "",
- machineType or "",
- operator or "",
- network or "",
- uuid or "",
- udid or "",
- ip or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("login", date, dataStr)
- end
- -- 服务端登出埋点
- function root.logLogout(uid, bandShareCode, channel, version, runTimes)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or "",
- bandShareCode or "",
- channel or "",
- version or "",
- runTimes or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("logout", date, dataStr)
- end
- -- 服务端支付埋点
- function root.logPay(playerInfo, orderInfo)
- if is_empty(playerInfo) or is_empty(orderInfo) then
- return
- end
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- playerInfo.uid or "",
- playerInfo.bandShareCode or "",
- playerInfo.channel or "",
- playerInfo.version or "",
- orderInfo.orderNo or "",
- orderInfo.pay or "",
- orderInfo.itemId or "",
- orderInfo.amount or "",
- orderInfo.status or "",
- orderInfo.retmsg or ""
- }
- local dataStr = root.formatData(data)
- writeServerLog("pay", date, dataStr)
- end
- -- 绑定推广码
- function root.logBandShareCode(uid, bandShareCode, channel, version)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or "",
- bandShareCode or "",
- channel or "",
- version or ""
- }
- local dataStr = root.formatData(data)
- writeServerLog("banding", date, dataStr)
- end
- -- 在线人数
- function root.logOnlineCount()
- local mapCount = redisUtil.hgetall("online:count")
- log.info("logOnlineCount mapCount[%s]", tostring(mapCount))
- if is_empty(mapCount) then
- return
- end
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- -- 全服
- if mapCount["all"] then
- local data = {
- date,
- dateStr,
- "",
- "",
- mapCount["all"]
- }
- local dataStr = root.formatData(data)
- writeServerLog("onlinecount", date, dataStr)
- end
- -- 主播
- for k, v in pairs(mapCount) do
- if string.match(k, "bandShareCode") and tonumber(v) > 0 then
- local arr = string.split(k, ":")
- local data = {
- date,
- dateStr,
- arr[2],
- "",
- v
- }
- local dataStr = root.formatData(data)
- writeServerLog("onlinecount", date, dataStr)
- end
- end
- end
- return root
|