本文共 4721 字,大约阅读时间需要 15 分钟。
共享电动车企业使用函数服务搭建服务端。在函数服务中开启日志,把程序日志写到日志服务,同时在函数代码中使用SDK把运营日志写入到日志服务,使用日志服务进行日志分析。
在日志服务中,用户可以:
首先需要开通函数计算、日志服务,开通步骤和准备工作见文档:。
打开
可以看到华东2已经创建了一个project,以yunqi-demo-开头,这个project是在函数服务的代码里创建的。(注:如果已经在华东2创建了project,会使用用户创建的第一个project)
在logstore列表,我们能看到两个logstore,分别是fc-debug-log程序日志和ebike业务日志:
打开,选择刚刚创建的project和logstore, 选择AliyunLogFullAccess权限,点击保存:
进入 lock 这个函数:
点击触发事件,输入事件的json,并且保存。然后点击执行:
事件样例:
{ "Uid" : "abc", "DeviceId" : "abcdef", "Mobile" : "18612345678", "SessionId" : 23456, "Logitude": 120.0776645, "Latitude": 30.131852}
同样可以尝试下unlock方法,事件样例:
{ "Mobile" : "18612345678", "DeviceId" : 123456, "Logitude": 120.0776645, "Latitude": 30.131852 }
此外,可以在ebike logstore中,查询op:unlock 或op:un* 或者unlock。
可以通过Request到其他系统中去找具体原因
query No. 1:
op : unlock| select count(1) as pv ,userid group by userid, __time__ - __time__% 600 order by pv desc
点击查询,然后右上角点击『另存为快速查询』:
然后点击『添加到dashboard』,选择新建dashboard,名称为ebike-monitor:
右上角添加报警,选择刚刚保存的快速查询,输入相关参数和手机号码:
查看开锁和关锁的延时情况,修改query为:
query No. 2:
op:lock or op : unlock | select date_format(from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time, avg(latency)as avg_latency, approx_percentile(latency,0.9) as top_10_percent_latency ,approx_percentile(latency,0.8) as top_20_percent_latency group by time order by time limit 10000
点击保存到dashboard,选择已经存在的dashboard: ebike_monitor:
为了快速查看延时的分布情况,我们把所有的延时均匀的划分到是个桶里,看每个桶中的均值是多少,以及对应的日志条数是多少?
查看函数服务每分钟的请求pv:
query No. 3:
op:lock or op : unlock | select date_format(from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time,count(1) as pv group by time order by time limit 10000
点击保存到dashboad,图表名称命名为ebike_pv
查看电池使用情况:
query No. 4:
op:lock | select sum(used_battery) as hourly_used_battery , date_format (from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time group by time order by time limit 25
query No. 5:
* | select sum(case when op = 'lock' then 1 else 0 end) as lock_pv, sum(case when op = 'unlock' then 1 else 0 end) as unlock_pv , date_format(from_unixtime(__time__ - __time__ % 3600),'%m-%d %H:%i') as time group by time order by time limit 100
点击保存到dashboard,参考上文步骤,新建一个dashboard名称为ebike_dashboard:
输入更多query,保存到dashboard中:
查看不同省份的占比:
query No. 6:
* | select count(1) as count, ip_to_province(ip) as province group by province
查看不同城市的占比:
query No.7:
* | select count(1) as count, ip_to_city(ip) as city group by city
查看不同网路运营商的占比:
query No.8:
* | select count(1) as count, ip_to_provider(ip) as provider group by provider
一天内的总收入:
query No. 9:
op : lock | select sum(money) as income
用户的支付手段占比:
query No. 10:
op:lock | select count(1) as pv , pay_channel group by pay_channel
左侧选择新建标签:
在右侧弹出窗口中,选择刚刚创建的dashboard:
如果需要修改图表,点击每张图右上角的箭头;如果需要刷新页面,可以点击刷新按钮:
欢迎添加VIP钉钉群进行咨询:
函数触发事件:
{ "Uid" : "abc", "DeviceId" : "abcdef", "Mobile" : "18612345678", "SessionId" : 23456, "Logitude": 120.0776645, "Latitude": 30.131852}
本文所使用全部query:
op : unlock| select count(1) as pv ,userid group by userid, __time__ - __time__% 600 order by pv desc
2.
op:lock or op : unlock | select date_format(from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time, avg(latency)as avg_latency, approx_percentile(latency,0.9) as top_10_percent_latency ,approx_percentile(latency,0.8) as top_20_percent_latency group by time order by time limit 10000
3.
op:lock or op : unlock | select date_format(from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time,count(1) as pv group by time order by time limit 10000
4.
op:lock | select sum(used_battery) as hourly_used_battery , date_format (from_unixtime(__time__ - __time__% 3600),'%m-%d %H:%i') as time group by time order by time limit 25
5.
* | select sum(case when op = 'lock' then 1 else 0 end) as lock_pv, sum(case when op = 'unlock' then 1 else 0 end) as unlock_pv , date_format(from_unixtime(__time__ - __time__ % 3600),'%m-%d %H:%i') as time group by time order by time limit 100
6.
* | select count(1) as count, ip_to_province(ip) as province group by province
7.
* | select count(1) as count, ip_to_city(ip) as city group by city
8.
* | select count(1) as count, ip_to_provider(ip) as provider group by provider
9.
op : lock | select sum(money) as income
10.
op:lock | select count(1) as pv , pay_channel group by pay_channel
转载地址:http://exkul.baihongyu.com/