blob: 688f9063fd3a6e1b68045fecff4c9d978d679e06 [file] [log] [blame]
"use strict";(self.webpackChunkhertzbeat=self.webpackChunkhertzbeat||[]).push([[79411],{15680:(e,t,n)=>{n.d(t,{xA:()=>d,yg:()=>h});var a=n(96540);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,a,o=function(e,t){if(null==e)return{};var n,a,o={},r=Object.keys(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=a.createContext({}),p=function(e){var t=a.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=p(e.components);return a.createElement(l.Provider,{value:t},e.children)},c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,o=e.mdxType,r=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),m=p(n),h=o,u=m["".concat(l,".").concat(h)]||m[h]||c[h]||r;return n?a.createElement(u,i(i({ref:t},d),{},{components:n})):a.createElement(u,i({ref:t},d))}));function h(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var r=n.length,i=new Array(r);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s.mdxType="string"==typeof e?e:o,i[1]=s;for(var p=2;p<r;p++)i[p]=n[p];return a.createElement.apply(null,i)}return a.createElement.apply(null,n)}m.displayName="MDXCreateElement"},21060:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>r,metadata:()=>s,toc:()=>p});var a=n(58168),o=(n(96540),n(15680));const r={id:"extend-http-example-hertzbeat",title:"Tutorial 1 Adapting a monitoring type based on HTTP protocol",sidebar_label:"Tutorial 1 Adapting an HTTP protocol monitoring"},i=void 0,s={unversionedId:"advanced/extend-http-example-hertzbeat",id:"version-v1.1.x/advanced/extend-http-example-hertzbeat",title:"Tutorial 1 Adapting a monitoring type based on HTTP protocol",description:"Through this tutorial, we describe step by step how to add a monitoring type based on the http protocol under the hertzbeat monitoring tool.",source:"@site/i18n/en/docusaurus-plugin-content-docs/version-v1.1.x/advanced/extend-http-example-hertzbeat.md",sourceDirName:"advanced",slug:"/advanced/extend-http-example-hertzbeat",permalink:"/docs/v1.1.x/advanced/extend-http-example-hertzbeat",draft:!1,editUrl:"https://github.com/dromara/hertzbeat/edit/master/home/i18n/en/docusaurus-plugin-content-docs/version-v1.1.x/advanced/extend-http-example-hertzbeat.md",tags:[],version:"v1.1.x",frontMatter:{id:"extend-http-example-hertzbeat",title:"Tutorial 1 Adapting a monitoring type based on HTTP protocol",sidebar_label:"Tutorial 1 Adapting an HTTP protocol monitoring"},sidebar:"docs",previous:{title:"JsonPath Parsing Method",permalink:"/docs/v1.1.x/advanced/extend-http-jsonpath"},next:{title:"Tutorial 2 Get TOKEN for subsequent authentication",permalink:"/docs/v1.1.x/advanced/extend-http-example-token"}},l={},p=[{value:"HTTP protocol parses the general response structure to obtain metric data",id:"http-protocol-parses-the-general-response-structure-to-obtain-metric-data",level:3},{value:"Add corresponding application definition YML and parameter definition YML",id:"add-corresponding-application-definition-yml-and-parameter-definition-yml",level:3},{value:"The system page adds the monitoring of <code>hertzbeat</code> monitoring type",id:"the-system-page-adds-the-monitoring-of-hertzbeat-monitoring-type",level:3},{value:"Set threshold alarm notification",id:"set-threshold-alarm-notification",level:3},{value:"over!",id:"over",level:4}],d={toc:p};function c(e){let{components:t,...r}=e;return(0,o.yg)("wrapper",(0,a.A)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.yg)("p",null,"Through this tutorial, we describe step by step how to add a monitoring type based on the http protocol under the hertzbeat monitoring tool."),(0,o.yg)("p",null,"Before reading this tutorial, we hope that you are familiar with how to customize types, metrics, protocols, etc. from ","[Custom Monitoring]"," (extend-point) and ","[http Protocol Customization]"," (extend-http)."),(0,o.yg)("h3",{id:"http-protocol-parses-the-general-response-structure-to-obtain-metric-data"},"HTTP protocol parses the general response structure to obtain metric data"),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"In many scenarios, we need to monitor the provided HTTP API interface and obtain the index value returned by the interface. In this article, we use the http custom protocol to parse our common http interface response structure, and obtain the fields in the returned body as metric data.")),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre"},'{\n "code": 200,\n "msg": "success",\n "data": {}\n}\n\n')),(0,o.yg)("p",null,"As above, usually our background API interface will design such a general return. The same is true for the background of the hertzbeat system. Today, we will use the hertzbeat API as an example, add a new monitoring type ",(0,o.yg)("strong",{parentName:"p"},"hertzbeat"),", and monitor and collect its system summary statistics API\n",(0,o.yg)("inlineCode",{parentName:"p"},"http://localhost:1157/api/summary"),", the response data is:"),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre"},'{\n "msg": null,\n "code": 0,\n "data": {\n "apps": [\n {\n "category": "service",\n "app": "jvm",\n "status": 0,\n "size": 2,\n "availableSize": 0,\n "unManageSize": 2,\n "unAvailableSize": 0,\n "unReachableSize": 0\n },\n {\n "category": "service",\n "app": "website",\n "status": 0,\n "size": 2,\n "availableSize": 0,\n "unManageSize": 2,\n "unAvailableSize": 0,\n "unReachableSize": 0\n }\n ]\n }\n}\n')),(0,o.yg)("p",null,(0,o.yg)("strong",{parentName:"p"},"This time we get the metric data such as ",(0,o.yg)("inlineCode",{parentName:"strong"},"category"),", ",(0,o.yg)("inlineCode",{parentName:"strong"},"app"),", ",(0,o.yg)("inlineCode",{parentName:"strong"},"status"),", ",(0,o.yg)("inlineCode",{parentName:"strong"},"size"),", ",(0,o.yg)("inlineCode",{parentName:"strong"},"availableSize")," under the app. ")),(0,o.yg)("h3",{id:"add-corresponding-application-definition-yml-and-parameter-definition-yml"},"Add corresponding application definition YML and parameter definition YML"),(0,o.yg)("ol",null,(0,o.yg)("li",{parentName:"ol"},"Custom monitoring type needs to add configuration YML file")),(0,o.yg)("p",null,"A monitoring configuration definition file named after the monitoring type - for example: app-hertzbeat.yml needs to be located in the installation directory /hertzbeat/define/"),(0,o.yg)("ol",{start:2},(0,o.yg)("li",{parentName:"ol"},"Configure the monitoring configuration definition file app-hertzbeat.yml")),(0,o.yg)("p",null,"The monitoring configuration definition file is used to define the collection type, which protocol collection method needs to be used, the collection metrics, protocol configuration parameters, etc. We directly reuse the definition content in app-api.yml and modify it to our current monitoring type ",(0,o.yg)("inlineCode",{parentName:"p"},"hertzbeat")," configuration parameters, as follows: Note\u26a0\ufe0fWe get ",(0,o.yg)("inlineCode",{parentName:"p"},"category"),", ",(0,o.yg)("inlineCode",{parentName:"p"},"app")," in the interface response data this time, Fields such as ",(0,o.yg)("inlineCode",{parentName:"p"},"status"),", ",(0,o.yg)("inlineCode",{parentName:"p"},"size"),", ",(0,o.yg)("inlineCode",{parentName:"p"},"availableSize")," are used as metric data."),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-yaml"},"# This monitoring type belongs to the category: service-application service monitoring db-database monitoring custom-custom monitoring os-operating system monitoring\ncategory: custom\n# Monitoring application type name (consistent with the file name) eg: linux windows tomcat mysql aws...\napp: hertzbeat\nname:\n en-GB: HertzBeat Monitoring Tool\n en-US: Hertz Beat Monitor\nparams:\n - field: host\n name:\n en-CN: Host Host\n en-US: Host\n type: host\n required: true\n - field: port\n name:\n en-CN: port\n en-US: Port\n type: number\n range: '[0,65535]'\n required: true\n defaultValue: 1157\n - field: ssl\n name:\n en-GB: Enable HTTPS\n en-US: HTTPS\n type: boolean\n required: true\n - field: timeout\n name:\n en-CN: Timeout (ms)\n en-US: Timeout(ms)\n type: number\n required: false\n hide: true\n - field: authType\n name:\n en-CN: Authentication method\n en-US: Auth Type\n type: radio\n required: false\n hide: true\n options:\n - label: Basic Auth\n value: Basic Auth\n - label: Digest Auth\n value: Digest Auth\n - field: username\n name:\n en-CN: username\n en-US: Username\n type: text\n limit: 20\n required: false\n hide: true\n - field: password\n name:\n en-CN: Password\n en-US: Password\n type: password\n required: false\n hide: true\n# List of metricss\nmetrics:\n # The first monitoring metrics summary\n # Note: Built-in monitoring metrics have (responseTime - response time)\n - name: summary\n priority: 0\n fields:\n # metric information includes field name type field type: 0-number, 1-string , label-if is metrics label, unit: metric unit\n - field: responseTime\n type: 0\n unit: ms\n - field: app\n type: 1\n instance: true\n - field: category\n type: 1\n - field: status\n type: 0\n - field: size\n type: 0\n - field: availableSize\n type: 0\n# Monitoring and collection protocol eg: sql, ssh, http, telnet, wmi, snmp, sdk, we use HTTP protocol here\n protocol: http\n# When the protocol is the http protocol, the specific collection configuration\n http:\n host: ^_^host^_^\n # port\n port: ^_^port^_^\n # url request interface path, we don\u2019t need to enter parameters here, it\u2019s written as /api/summary\n url: /api/summary\n timeout: ^_^timeout^_^\n # Request method GET POST PUT DELETE PATCH, hardcoded as\n method: GET\n # Whether to enable ssl/tls, that is, http or https, default false\n ssl: ^_^ssl^_^\n # authentication\n authorization:\n # Authentication methods: Basic Auth, Digest Auth, Bearer Token\n type: ^_^authType^_^\n basicAuthUsername: ^_^username^_^\n basicAuthPassword: ^_^password^_^\n digestAuthUsername: ^_^username^_^\n digestAuthPassword: ^_^password^_^\n # Response data parsing method: default-system rules, jsonPath-jsonPath script, website-website usability metric monitoring, we use jsonpath here to parse the response data\n parseType: jsonPath\n parseScript: '$.data.apps.*'\n\n")),(0,o.yg)("p",null,(0,o.yg)("strong",{parentName:"p"},"The addition is complete, now we restart the hertzbeat system. We can see that the system page has added a ",(0,o.yg)("inlineCode",{parentName:"strong"},"hertzbeat")," monitoring type. ")),(0,o.yg)("p",null,(0,o.yg)("img",{src:n(8393).A,width:"3840",height:"1724"})),(0,o.yg)("h3",{id:"the-system-page-adds-the-monitoring-of-hertzbeat-monitoring-type"},"The system page adds the monitoring of ",(0,o.yg)("inlineCode",{parentName:"h3"},"hertzbeat")," monitoring type"),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"We click Add ",(0,o.yg)("inlineCode",{parentName:"p"},"HertzBeat Monitoring Tool"),", configure monitoring IP, port, collection cycle, account password in advanced settings, etc., click OK to add monitoring.")),(0,o.yg)("p",null,(0,o.yg)("img",{src:n(43250).A,width:"1921",height:"860"})),(0,o.yg)("p",null,(0,o.yg)("img",{src:n(92251).A,width:"1922",height:"857"})),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"After a certain period of time (depending on the collection cycle), we can see the specific metric data and historical charts in the monitoring details!")),(0,o.yg)("p",null,(0,o.yg)("img",{src:n(82308).A,width:"1922",height:"860"})),(0,o.yg)("h3",{id:"set-threshold-alarm-notification"},"Set threshold alarm notification"),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"Next, we can set the threshold normally. After the alarm is triggered, we can view it in the alarm center, add recipients, set alarm notifications, etc. Have Fun!!!")),(0,o.yg)("hr",null),(0,o.yg)("h4",{id:"over"},"over!"),(0,o.yg)("p",null,"This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!"),(0,o.yg)("p",null,"If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!"),(0,o.yg)("p",null,(0,o.yg)("strong",{parentName:"p"},"github: ",(0,o.yg)("a",{parentName:"strong",href:"https://github.com/dromara/hertzbeat"},"https://github.com/dromara/hertzbeat"))),(0,o.yg)("p",null,(0,o.yg)("strong",{parentName:"p"},"gitee: ",(0,o.yg)("a",{parentName:"strong",href:"https://gitee.com/dromara/hertzbeat"},"https://gitee.com/dromara/hertzbeat"))))}c.isMDXComponent=!0},8393:(e,t,n)=>{n.d(t,{A:()=>a});const a=n.p+"assets/images/extend-http-example-1-2ef7a26379015bea268420811e822d18.png"},43250:(e,t,n)=>{n.d(t,{A:()=>a});const a=n.p+"assets/images/extend-http-example-2-cbd473f82a666e7562d932d8eeaccc57.png"},92251:(e,t,n)=>{n.d(t,{A:()=>a});const a=n.p+"assets/images/extend-http-example-3-8cdb9ddf2d9e2e7b469eb4082c0f9f13.png"},82308:(e,t,n)=>{n.d(t,{A:()=>a});const a=n.p+"assets/images/extend-http-example-4-5e7e7c30cdfbd310c653ede5ea72f622.png"}}]);