事件监控功能为您提供上报事件的接口,方便您将业务产生的异常事件采集上报到云监控,通过对上报的事件配置报警规则来接收报警通知。
云监控为您提供 OpenAPI、Java SDK 和阿里云命令行工具(CLI) 三种方式上报数据。
使用限制
- 单云账号QPS限制为20
- 单次最多上报100个事件
- 单次最多上报500KB数据
OpenAPI上报数据
服务地址
https://metrichub-cms-cn-hangzhou.aliyuncs.com
请求语法
- [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]
- [backcolor=transparent]Authorization[backcolor=transparent]:<[backcolor=transparent]AuthorizationString[backcolor=transparent]>
- [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]Length[backcolor=transparent]:<[backcolor=transparent]Content[backcolor=transparent] [backcolor=transparent]Length[backcolor=transparent]>
- [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]MD5[backcolor=transparent]:<[backcolor=transparent]Content[backcolor=transparent] MD5[backcolor=transparent]>
- [backcolor=transparent]Content[backcolor=transparent]-[backcolor=transparent]Type[backcolor=transparent]:[backcolor=transparent]application[backcolor=transparent]/[backcolor=transparent]json
- [backcolor=transparent]Date[backcolor=transparent]:<[backcolor=transparent]GMT [backcolor=transparent]Date[backcolor=transparent]>
- [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]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]signature[backcolor=transparent]:[backcolor=transparent]hmac[backcolor=transparent]-[backcolor=transparent]sha1
- [backcolor=transparent]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]api[backcolor=transparent]-[backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent]1.0
- [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
- [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
- [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]}]
请求参数
关于API的请求头,请参考
请求头定义。
响应元素
HTTP 状态码返回 200。
示例
请求示例
- [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]
- [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]x[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]-[backcolor=transparent]api[backcolor=transparent]-[backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent]1.0
- [backcolor=transparent]Authorization[backcolor=transparent]:[backcolor=transparent]YourAccKey[backcolor=transparent]:[backcolor=transparent]YourAccSecret[backcolor=transparent]
- [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]"
- [backcolor=transparent]Date:Mon, 23 Oct 2017 06:51:11 GMT
- [backcolor=transparent]Content-Length:180
- [backcolor=transparent]x-cms-signature:hmac-sha1
- [backcolor=transparent]Content-MD5:E9EF574D1AEAAA370860FE37856995CD
- [backcolor=transparent]x-cms-ip:30.27.84.196
- [backcolor=transparent]User-Agent:cms-java-sdk-v-1.0
- [backcolor=transparent]Content-Type:application/json
- [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]"}]
返回示例
- [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]"code"[backcolor=transparent]:[backcolor=transparent]"200"[backcolor=transparent],
- [backcolor=transparent] [backcolor=transparent]"msg"[backcolor=transparent]:[backcolor=transparent]""[backcolor=transparent]//正常上报时返回msg为空
- [backcolor=transparent]}
Java SDK上报数据
maven依赖
- [backcolor=transparent]<dependency>
- [backcolor=transparent] [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun.openservices[backcolor=transparent]</groupId>
- [backcolor=transparent] [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-cms[backcolor=transparent]</artifactId>
- [backcolor=transparent] [backcolor=transparent]<version>[backcolor=transparent]0.1.2[backcolor=transparent]</version>
- [backcolor=transparent]</dependency>
示例代码
- [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]{
- [backcolor=transparent] [backcolor=transparent]//初始化客户端
- [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]);
- [backcolor=transparent] [backcolor=transparent]//构建2个事件上报
- [backcolor=transparent] [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]append[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abc,123"[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event001"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]())
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]append[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abc,123"[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event002"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]())
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]build[backcolor=transparent]();
- [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]);
- [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]>();
- [backcolor=transparent] eventList[backcolor=transparent].[backcolor=transparent]add[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abcd,1234"[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event001"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]());
- [backcolor=transparent] eventList[backcolor=transparent].[backcolor=transparent]add[backcolor=transparent]([backcolor=transparent]CustomEvent[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setContent[backcolor=transparent]([backcolor=transparent]"abcd,1234"[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setGroupId[backcolor=transparent]([backcolor=transparent]101l[backcolor=transparent])
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setName[backcolor=transparent]([backcolor=transparent]"Event002"[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]());
- [backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]CustomEventUploadRequest[backcolor=transparent].[backcolor=transparent]builder[backcolor=transparent]()
- [backcolor=transparent] [backcolor=transparent].[backcolor=transparent]setEventList[backcolor=transparent]([backcolor=transparent]eventList[backcolor=transparent]).[backcolor=transparent]build[backcolor=transparent]();
- [backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] cmsClient[backcolor=transparent].[backcolor=transparent]putCustomEvent[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
阿里云命令行(CLI)方式上报数据
第一步: 安装阿里云CLI,
安装文档。
第二步:安装CmsSDK
Windows安装方式:在命令行窗口输入如下命令
- [backcolor=transparent]cd C[backcolor=transparent]:[backcolor=transparent]\Python27\Scripts
- [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
如果需要更新SDK,则使用如下命令:
- [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
Linux 安装方式:
- [backcolor=transparent]sudo pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
如果需要升级SDK,则使用如下命令:
- [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
第三步:上报监控数据
使用PutEvent接口。
Windows上报示例:
- [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'}]"
Linux 上报示例:
- [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'}]"
上报成功后,返回200状态码
- [backcolor=transparent]{
- [backcolor=transparent]"Code"[backcolor=transparent]:[backcolor=transparent]"200"
- [backcolor=transparent]}
错误编码
[tr=rgb(239, 251, 255)][td]400
客户端请求中的语法错误 |
403 | 校验失败、限速、没有授权 |
500 | 服务器内部错误 |