上传监控数据

<p class="shortdesc">自定义监控为您提供了自由定义监控项的功能。平安云自定义监控功能采用API方式进行监控数据的上报。</p> <section class="section" id="repot__section_i5v_w2w_mjb"><h2 class="doc-tairway">请求参数 </h2> <table class="table frame-all" id="repot__table_q1r_kxw_mjb"><caption></caption><colgroup><col style="width:10.959885386819483%"><col style="width:8.595988538681947%"><col style="width:7.163323782234957%"><col style="width:9.455587392550143%"><col style="width:63.825214899713465%"></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="repot__table_q1r_kxw_mjb__entry__1">参数名称</th> <th class="entry" id="repot__table_q1r_kxw_mjb__entry__2">位置</th> <th class="entry" id="repot__table_q1r_kxw_mjb__entry__3">必须</th> <th class="entry" id="repot__table_q1r_kxw_mjb__entry__4">类型</th> <th class="entry" id="repot__table_q1r_kxw_mjb__entry__5">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-AppId </p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">AppId为调用API的身份标识。</p> <p class="p">当您第一次使用该功能时,需要在<a class="xref" href="https://pinganyun.com/console/argus/overview" target="_blank">云监控Argus控制台</a>上,单击左侧导航栏中的<span class="ph uicontrol">自定义监控</span>,然后单击<span class="ph uicontrol">开通自定义监控</span>按钮。开通后,系统将为您自动分配调用接口所需的AppId。</p> <div class="note note note_note"><span class="note__title">说明:</span> <p class="p">本API安全认证使用Access Key ID & Access Key Secret认证模式,还需要提供Access Key ID 和 Access Key Secret。</p> </div> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-OAC-AccessKeyId</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">平安云API调用的身份认证。</p> <p class="p">您可以在平安云官网右上角的<span class="ph menucascade"><span class="ph uicontrol">账号信息</span><abbr> > </abbr><span class="ph uicontrol">Access Key</span></span>中获取<span class="ph uicontrol">Access Key ID </span> 。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-Signature</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">签名字符串,参考<a class="xref" href="dc_argus_cfg_0035.html#repot__section_wnx_lkx_mjb">签名算法</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-Timestamp</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">Int</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">毫秒级时间戳,有效期为15分钟。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-GroupId </p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">分组ID。固定值:1f009720-19d7-4433-9372-642a39c1f14e 。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-Content-Digest </p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">请求Body的MD5值,当请求Body不为空时将Body的MD5值上传进行校验。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__1 "> <p class="p">PA-AG-RequestId</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__2 "> <p class="p">Header</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__3 "> <p class="p">否</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__4 "> <p class="p">String</p> </td> <td class="entry" headers="repot__table_q1r_kxw_mjb__entry__5 "> <p class="p">调用者自己可以使用请求的UUID进行上传,如果不上传系统会自己生成,主要用于帮助定位错误。</p> </td> </tr> </tbody></table> </section> <section class="section" id="repot__section_wnx_lkx_mjb"><h2 class="doc-tairway">签名算法</h2> <p class="p" id="repot__p_j51_1hz_zjb"><strong class="ph b">1.构建待签名字符串 </strong></p> <p class="p" id="repot__p_m51_1hz_zjb">API签名字符串构建公式如下,其中<code class="ph codeph">\n</code>表示换行转义字符,<code class="ph codeph">+</code>表示字符串连接操作,其他各部说明请参考下表。</p> <pre class="pre codeblock" id="repot__codeblock_l51_1hz_zjb"><code>String strToSign = HttpMethod + "\n" + URI + "\n" + Headers + "\n" + ContentDigest</code></pre> <table class="table frame-all" id="repot__table_xcm_rkx_dkb"><caption></caption><colgroup><col style="width:40.4040404040404%"><col style="width:59.5959595959596%"></colgroup><thead class="thead"> <tr class="row"> <th class="entry align-left" id="repot__table_xcm_rkx_dkb__entry__1">名称</th> <th class="entry" id="repot__table_xcm_rkx_dkb__entry__2">说明</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry align-left" headers="repot__table_xcm_rkx_dkb__entry__1 "> <p class="p">HttpMethod</p> </td> <td class="entry" headers="repot__table_xcm_rkx_dkb__entry__2 "> <p class="p">HTTP请求的方法名称,如PUT、GET、POST等。</p> </td> </tr> <tr class="row"> <td class="entry align-left" headers="repot__table_xcm_rkx_dkb__entry__1 "> <p class="p"> URI</p> </td> <td class="entry" headers="repot__table_xcm_rkx_dkb__entry__2 "> <p class="p">统一资源标识符,此处填写“/api/v1/global_push”。</p> </td> </tr> <tr class="row"> <td class="entry align-left" headers="repot__table_xcm_rkx_dkb__entry__1 "> <p class="p"> Headers</p> </td> <td class="entry" headers="repot__table_xcm_rkx_dkb__entry__2 "> <p class="p">Headers是指参与签名计算的请求头的Key、Value拼接的字符串。参与签名计算的请求头包括 <span class="ph uicontrol">PA-AG-Timestamp</span> 和<span class="ph uicontrol"> PA-AG-Signature-Headers </span>中填写的需要校验的其他请求头。请求头大小写不敏感。</p> <p class="p"><strong class="ph b">Headers拼接方式</strong></p> <p class="p">先对参与签名计算的 Header 的 Key 按照字典排序后使用如下方式拼接,如果某个 Header 的 Value 为空,则使用 HeaderKey.toLowercase() + ":" 参与签名,需要保留 Key 和英文冒号 :,并且 Key 和 Value 左右两边不能有空白字符。Header的 Value 可能有多个,多个的时候根据 Value 的字典顺序进行排序参与签名计算。</p> <pre class="pre codeblock"><code>String headers = HeaderKey1.toLowercase() + ":" + HeaderValue1.toLowercase() + "\n"\+ HeaderKey2.toLowercase() + ":" + HeaderValue2.toLowercase() + "\n"\+ ... HeaderKeyN.toLowercase() + ":" + HeaderValueN.toLowercase() + "\n"</code></pre> </td> </tr> <tr class="row"> <td class="entry align-left" headers="repot__table_xcm_rkx_dkb__entry__1 "> <p class="p">ContentDigest</p> </td> <td class="entry" headers="repot__table_xcm_rkx_dkb__entry__2 "> <p class="p">Body 的 MD5 值,只有当请求Body存在时才需要进行计算。计算方式为:</p> <pre class="pre codeblock"><code>String contentDigest = Base64.encodeBase64(MD5(requestBody.getbytes("UTF-8")));</code></pre> </td> </tr> </tbody></table> <p class="p" id="repot__p_w3n_mhz_zjb"><strong class="ph b">2.计算签名</strong></p> <p class="p" id="repot__p_y3n_mhz_zjb">计算签名的公式如下:</p> <pre class="pre codeblock"><code>Mac hmacSha256 = Mac.getInstance("HmacSHA256"); byte[] keyBytes = secret.getBytes("UTF-8"); hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA1")); String sign = new String(Base64.encodeBase64(hmacSha256.doFinal(strToSign.getBytes("UTF-8")),"UTF-8"));</code></pre> <div class="note note note_note" id="repot__note_z3n_mhz_zjb"><span class="note__title">说明:</span> <ol class="ol" id="repot__ol_lwh_24r_njb"> <li class="li">签名算法为HmacSHA1</li> <li class="li">secret为Access Key Secret,用于平安云API调用的身份认证。您可以在平安云官网右上角的<span class="ph menucascade"><span class="ph uicontrol">账号信息</span><abbr> > </abbr><span class="ph uicontrol">Access Key</span></span>中获取<span class="ph uicontrol">Access Key Secret</span> 。</li> </ol> </div> <p class="p" id="repot__p_bjn_mhz_zjb"><strong class="ph b">3.传递签名</strong></p> <p class="p" id="repot__p_cjn_mhz_zjb">将计算的签名结果放到 Request 的 Header 中,Key为PA-AG-Signature。</p> <ul class="ul" id="repot__ul_bzq_l4r_njb"> <li class="li"> <p class="p">调用地址:<a class="xref" href="https://80109f51-b6e0-4e25-a23c-44d1baf5f644.apigw.fincloud.pinganyun.com/api/v1/global_push/" target="_blank">https://80109f51-b6e0-4e25-a23c-44d1baf5f644.apigw.fincloud.pinganyun.com/api/v1/global_push/</a></p> </li> <li class="li"> <p class="p">请求协议:HTTPS</p> </li> <li class="li"> <p class="p">请求方式:POST</p> </li> </ul> <p class="p" id="repot__p_djn_mhz_zjb"><strong class="ph b">请求示例</strong></p> <pre class="pre codeblock" id="repot__codeblock_ejn_mhz_zjb"><code>{ "data": [{ "tags": "microservice=pay,bad_request=500" //监控项名称 "value": 100, //上报数值 "step": 60, //上报频率 "counterType": "GAUGE", //采集方式 "timestamp": 1537783931 //时间戳 }] }</code></pre> <table class="table" id="repot__table_vlv_q4r_njb"><caption><span class="table--title-label">表 1. </span><span class="title">请求示例参数说明</span></caption><colgroup><col style="width:16.69449081803005%"><col style="width:19.365609348914855%"><col style="width:19.69949916527546%"><col style="width:44.240400667779625%"></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="repot__table_vlv_q4r_njb__entry__1">参数名称</th> <th class="entry" id="repot__table_vlv_q4r_njb__entry__2">类型</th> <th class="entry" id="repot__table_vlv_q4r_njb__entry__3">必选</th> <th class="entry" id="repot__table_vlv_q4r_njb__entry__4">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">data</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">array</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <p class="p">键值对格式,支持批量上报数据。数组格式不超过1000,body传输大小不得超过2MB。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">tags</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">string</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <p class="p">监控项名称格式必须为一组以逗号分割的键值对,最大长度不得超过250个字符,如“microservice=pay,bad_request=500”,可表示命名为pay的微服务,返回码为500的次数”。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">value</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">float64</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <p class="p">监控项的值。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">step</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">int</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <p class="p">监控数据的上报频率,单位为秒。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">counterType</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">string</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <div class="p">可以选择COUNTER和GAUGE (注意大小写):<ul class="ul" id="repot__ul_hmk_dpr_njb"> <li class="li">COUNTER:表示该数据采集项为计时器类型,指标在存储和展现的时候,会被计算为speed,即(当前值 - 上次值)/ 时间间隔。</li> <li class="li">GAUGE:表示其为原值,即用户上传什么样的值,就原封不动的存储。</li> </ul></div> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__1 "> <p class="p">timestamp</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__2 "> <p class="p">long</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__3 "> <p class="p">是</p> </td> <td class="entry" headers="repot__table_vlv_q4r_njb__entry__4 "> <p class="p">表示上报该数据时的unix时间戳。</p> </td> </tr> </tbody></table> <p class="p" id="repot__p_w5b_nhz_zjb"><strong class="ph b">返回示例</strong></p> <pre class="pre codeblock" id="repot__codeblock_x5b_nhz_zjb"><code>{ "data": { "invalid": 0, "total": 1 }, "code": "0", "msg": "success" }</code></pre> <table class="table" id="repot__table_zds_lpr_njb"><caption><span class="table--title-label">表 2. </span><span class="title">返回示例参数说明</span></caption><colgroup><col style="width:33.33333333333333%"><col style="width:66.66666666666666%"></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="repot__table_zds_lpr_njb__entry__1">参数名称</th> <th class="entry" id="repot__table_zds_lpr_njb__entry__2">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="repot__table_zds_lpr_njb__entry__1 "> <p class="p">data.invalid</p> </td> <td class="entry" headers="repot__table_zds_lpr_njb__entry__2 "> <p class="p">上报失败的总数。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_zds_lpr_njb__entry__1 "> <p class="p">data.total</p> </td> <td class="entry" headers="repot__table_zds_lpr_njb__entry__2 "> <p class="p">总上报数量,上报成功量等于:data.total- data.invalid。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_zds_lpr_njb__entry__1 "> <p class="p">code</p> </td> <td class="entry" headers="repot__table_zds_lpr_njb__entry__2 "> <p class="p">code=0,表示接口调用成功。code=-1时表示接口调用失败。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_zds_lpr_njb__entry__1 "> <p class="p">msg</p> </td> <td class="entry" headers="repot__table_zds_lpr_njb__entry__2 "> <p class="p">返回信息。</p> </td> </tr> </tbody></table> <p class="p" id="repot__p_sym_nhz_zjb"><strong class="ph b">异常示例</strong></p> <pre class="pre codeblock" id="repot__codeblock_tym_nhz_zjb"><code>{ "code": "-1", "msg": "the length of upload data array is too large", "requestId":"AG-c3644612-f5c4-4881-864c-0e9f7203d1a9" } </code></pre> <table class="table" id="repot__table_uvy_spr_njb"><caption><span class="table--title-label">表 3. </span><span class="title">异常示例参数说明</span></caption><colgroup><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="repot__table_uvy_spr_njb__entry__1">错误码</th> <th class="entry" id="repot__table_uvy_spr_njb__entry__2">错误信息</th> <th class="entry" id="repot__table_uvy_spr_njb__entry__3">解决方案</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">-1</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">上报数据超长。</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">检查上报数据的长度是否超过1000。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-101</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">不能识别的请求 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请按照公共入参检查必选参数。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-102</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">请求参数错误 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请根据返回信息的msg检查参数。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-103</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">签名不正确 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请根据返回信息的strToSign检查签名原文是否拼接正确,并检查AppId。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-104 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">应用不存在</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请检查AppId是否存在。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-105 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">API未授权 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请检查调用的AppId是否有该API的权限。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-107 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">请求已过期 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请检查PA-AG-Timestamp是否已经过期。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">AG-110</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">用户已欠费 </p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请为平安云账号续费。</p> </td> </tr> <tr class="row"> <td class="entry" headers="repot__table_uvy_spr_njb__entry__1 "> <p class="p">其他错误</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__2 "> <p class="p">其他错误信息</p> </td> <td class="entry" headers="repot__table_uvy_spr_njb__entry__3 "> <p class="p">请联系管理员或者提交工单。</p> </td> </tr> </tbody></table> </section>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题