阿里云
阿里云多端小程序中小企业获客首选
发表主题 回复主题
  • 1223阅读
  • 0回复

[云安全技术和产品专区 ]云监控中上报事件数据

级别: 论坛粉丝
发帖
1227
云币
2325
事件监控功能为您提供上报事件的接口,方便您将业务产生的异常事件采集上报到云监控,通过对上报的事件配置报警规则来接收报警通知。 a4%`"  
云监控为您提供 OpenAPI、Java SDK 和阿里命令行工具(CLI) 三种方式上报数据 ex.+'m<g  
使用限制 '-`O. 4u  
  • 单云账号QPS限制为20
  • 单次最多上报100个事件
  • 单次最多上报500KB数据
+IvNyj|  
OpenAPI上报数据 R_maNfS]Z  
服务地址 ]GcV0&|  
https://metrichub-cms-cn-hangzhou.aliyuncs.com YFG-U-t3  
请求语法 jz|VF,l  
  1. [backcolor=transparent]POST [backcolor=transparent]/[backcolor=transparent]event[backcolor=transparent]/[backcolor=transparent]custom[backcolor=transparent]/[backcolor=transparent]upload HTTP[backcolor=transparent]/[backcolor=transparent]1.1[backcolor=transparent]
  2. [backcolor=transparent]Authorization[backcolor=transparent]:<[backcolor=transparent]AuthorizationString[backcolor=transparent]>
  3. [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]Length[backcolor=transparent]:<[backcolor=transparent]Content[backcolor=transparent] [backcolor=transparent]Length[backcolor=transparent]>
  4. [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]MD5[backcolor=transparent]:<[backcolor=transparent]Content[backcolor=transparent] MD5[backcolor=transparent]>
  5. [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]Type[backcolor=transparent]:[backcolor=transparent]application[backcolor=transparent]/[backcolor=transparent]json
  6. [backcolor=transparent]Date[backcolor=transparent]:<[backcolor=transparent]GMT [backcolor=transparent]Date[backcolor=transparent]>
  7. [backcolor=transparent]Host[backcolor=transparent]:[backcolor=transparent] metrichub[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]cn[backcolor=transparent]-[backcolor=transparent]hangzhou[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]com
  8. [backcolor=transparent]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]signature[backcolor=transparent]:[backcolor=transparent]hmac[backcolor=transparent]-[backcolor=transparent]sha1
  9. [backcolor=transparent]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]api[backcolor=transparent]-[backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent]1.0
  10. [backcolor=transparent]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]ip[backcolor=transparent]:[backcolor=transparent]30.27[backcolor=transparent].[backcolor=transparent]84.196
  11. [backcolor=transparent]User[backcolor=transparent]-[backcolor=transparent]Agent[backcolor=transparent]:[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]java[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]v[backcolor=transparent]-[backcolor=transparent]1.0
  12. [backcolor=transparent][{[backcolor=transparent]"content"[backcolor=transparent]:[backcolor=transparent]"EventContent"[backcolor=transparent],[backcolor=transparent]"groupId"[backcolor=transparent]:[backcolor=transparent]GroupId[backcolor=transparent],[backcolor=transparent]"name"[backcolor=transparent]:[backcolor=transparent]"EventName"[backcolor=transparent],[backcolor=transparent]"time"[backcolor=transparent]:[backcolor=transparent]"20171023T144439.948+0800"[backcolor=transparent]}]
TS1pR"6l  
请求参数 B i'd5B5  
名称类型必选描述
name字符串事件名称
groupId数值事件所属的应用分组Id
time字符串事件发生时间
content字符串事件详情
yGRR8F5>(  
关于API的请求头,请参考请求头定义 j]AekI4I  
响应元素 iM8sX B  
HTTP 状态码返回 200。 8IeI0f"l)  
示例 aUA cR W  
请求示例 J l\'V  
  1. [backcolor=transparent]POST [backcolor=transparent]/[backcolor=transparent]event[backcolor=transparent]/[backcolor=transparent]custom[backcolor=transparent]/[backcolor=transparent]upload HTTP[backcolor=transparent]/[backcolor=transparent]1.1[backcolor=transparent]
  2. [backcolor=transparent]Host[backcolor=transparent]:[backcolor=transparent] metrichub[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]cn[backcolor=transparent]-[backcolor=transparent]hangzhou[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]com
  3. [backcolor=transparent]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]api[backcolor=transparent]-[backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent]1.0
  4. [backcolor=transparent]Authorization[backcolor=transparent]:[backcolor=transparent]YourAccKey[backcolor=transparent]:[backcolor=transparent]YourAccSecret[backcolor=transparent]
  5. [backcolor=transparent]Host[backcolor=transparent]:[backcolor=transparent]metrichub[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]cn[backcolor=transparent]-[backcolor=transparent]hangzhou[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]com[backcolor=transparent]"
  6. [backcolor=transparent]Date:Mon, 23 Oct 2017 06:51:11 GMT
  7. [backcolor=transparent]Content-Length:180
  8. [backcolor=transparent]x-cms-signature:hmac-sha1
  9. [backcolor=transparent]Content-MD5:E9EF574D1AEAAA370860FE37856995CD
  10. [backcolor=transparent]x-cms-ip:30.27.84.196
  11. [backcolor=transparent]User-Agent:cms-java-sdk-v-1.0
  12. [backcolor=transparent]Content-Type:application/json
  13. [backcolor=transparent][{"[backcolor=transparent]content[backcolor=transparent]":"[backcolor=transparent]123[backcolor=transparent],[backcolor=transparent]abc[backcolor=transparent]","[backcolor=transparent]groupId[backcolor=transparent]":100,"[backcolor=transparent]name[backcolor=transparent]":"[backcolor=transparent]Event_0[backcolor=transparent]","[backcolor=transparent]time[backcolor=transparent]":"[backcolor=transparent]20171023T144439.948[backcolor=transparent]+[backcolor=transparent]0800[backcolor=transparent]"}]
>A<Df  
)GK+  
返回示例 ;;M"hI3@  
2bkJ /u`i  
  1. [backcolor=transparent]{
  2. [backcolor=transparent]   [backcolor=transparent]"code"[backcolor=transparent]:[backcolor=transparent]"200"[backcolor=transparent],
  3. [backcolor=transparent]   [backcolor=transparent]"msg"[backcolor=transparent]:[backcolor=transparent]""[backcolor=transparent]//正常上报时返回msg为空
  4. [backcolor=transparent]}
C B6A}m  
Java SDK上报数据 : g 5(HH  
maven依赖 ka/nQ~_#<  
  1. [backcolor=transparent]<dependency>
  2. [backcolor=transparent]    [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun.openservices[backcolor=transparent]</groupId>
  3. [backcolor=transparent]    [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-cms[backcolor=transparent]</artifactId>
  4. [backcolor=transparent]    [backcolor=transparent]<version>[backcolor=transparent]0.1.2[backcolor=transparent]</version>
  5. [backcolor=transparent]</dependency>
^1R"7h  
示例代码 kY=rz&?U  
  1. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] uploadEvent[backcolor=transparent]()[backcolor=transparent] [backcolor=transparent]throws[backcolor=transparent] [backcolor=transparent]CMSException[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]InterruptedException[backcolor=transparent] [backcolor=transparent]{
  2. [backcolor=transparent]        [backcolor=transparent]//初始化客户端
  3. [backcolor=transparent]        [backcolor=transparent]CMSClient[backcolor=transparent] cmsClient [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]CMSClient[backcolor=transparent]([backcolor=transparent]endpoint[backcolor=transparent],[backcolor=transparent] accKey[backcolor=transparent],[backcolor=transparent] secret[backcolor=transparent]);
  4. [backcolor=transparent]       [backcolor=transparent]//构建2个事件上报
  5. [backcolor=transparent]         [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  6. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]append[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  7. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abc,123"[backcolor=transparent])
  8. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
  9. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event001"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]())
  10. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]append[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  11. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abc,123"[backcolor=transparent])
  12. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
  13. [backcolor=transparent]                            [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event002"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]())
  14. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]build[backcolor=transparent]();
  15. [backcolor=transparent]            [backcolor=transparent]CustomEventUploadResponse[backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] cmsClient[backcolor=transparent].[backcolor=transparent]putCustomEvent[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
  16. [backcolor=transparent]            [backcolor=transparent]List[backcolor=transparent]<[backcolor=transparent]CustomEvent[backcolor=transparent]>[backcolor=transparent] eventList [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]ArrayList[backcolor=transparent]<[backcolor=transparent]CustomEvent[backcolor=transparent]>();
  17. [backcolor=transparent]            eventList[backcolor=transparent].[backcolor=transparent]add[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  18. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abcd,1234"[backcolor=transparent])
  19. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
  20. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event001"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]());
  21. [backcolor=transparent]            eventList[backcolor=transparent].[backcolor=transparent]add[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  22. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abcd,1234"[backcolor=transparent])
  23. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
  24. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event002"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]());
  25. [backcolor=transparent]            request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
  26. [backcolor=transparent]                    [backcolor=transparent].[backcolor=transparent]setEventList[backcolor=transparent]([backcolor=transparent]eventList[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]();
  27. [backcolor=transparent]            response [backcolor=transparent]=[backcolor=transparent] cmsClient[backcolor=transparent].[backcolor=transparent]putCustomEvent[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
  28. [backcolor=transparent]    [backcolor=transparent]}
0',[J  
阿里云命令行(CLI)方式上报数据 D'<$ g  
第一步: 安装阿里云CLI,安装文档  e#1.T  
第二步:安装CmsSDK W8y$ Ve8m  
Windows安装方式:在命令行窗口输入如下命令
  1. [backcolor=transparent]cd C[backcolor=transparent]:[backcolor=transparent]\Python27\Scripts
  2. [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
S.1( 3j*  
如果需要更新SDK,则使用如下命令:
  1. [backcolor=transparent]pip install [backcolor=transparent]--[backcolor=transparent]upgrade aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
w=|py>%  
Linux 安装方式:
  1. [backcolor=transparent]sudo pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
;>8kPG  
如果需要升级SDK,则使用如下命令:
  1. [backcolor=transparent]sudo pip install [backcolor=transparent][backcolor=transparent]upgrade aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]rds
RB IOdz  
第三步:上报监控数据 Y KY2Cw  
使用PutEvent接口。 *Z >  
Windows上报示例:
  1. [backcolor=transparent]aliyuncli[backcolor=transparent].[backcolor=transparent]exe cms [backcolor=transparent]PutEvent[backcolor=transparent] [backcolor=transparent]--[backcolor=transparent]EventInfo[backcolor=transparent] [backcolor=transparent]"[{'content':'helloworld','time':'20171013T170923.456+0800','name':'ErrorEvent','groupId':'27147'}]"
7|Xe&o<n  
Linux 上报示例:
  1. [backcolor=transparent]aliyuncli cms [backcolor=transparent]PutEvent[backcolor=transparent] [backcolor=transparent]--[backcolor=transparent]EventInfo[backcolor=transparent] [backcolor=transparent]"[{'content':'helloworld','time':'20171023T180923.456+0800','name':'ErrorEvent','groupId':'27147'}]"
UoHd-  
上报成功后,返回200状态码
  1. [backcolor=transparent]{
  2. [backcolor=transparent]"Code"[backcolor=transparent]:[backcolor=transparent]"200"
  3. [backcolor=transparent]}
i*'Z3Z)  
错误编码 j|mv+O  
[tr=rgb(239, 251, 255)][td]400
错误代码含义
200正常
客户端请求中的语法错误
403校验失败、限速、没有授权
500服务器内部错误
*Z; r B  
[ 此帖被反向一觉在2017-10-31 10:42重新编辑 ]
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
验证问题: ECS是阿里云提供的什么服务? 正确答案:云服务器
上一个 下一个
      ×
      全新阿里云开发者社区, 去探索开发者的新世界吧!
      一站式的体验,更多的精彩!
      通过下面领域大门,一起探索新的技术世界吧~ (点击图标进入)