Project: HertzBeat (Observability and Analysis / Observability)
File: extend-tutorial.md

id: extend-tutorial title: Quick Tutorial Customize and adapt a monitoring based on HTTP protocol sidebar_label: Tutorial Case Through this tutorial, we describe step by step how to customize and adapt a monitoring type based on the http protocol under the hertzbeat monitoring tool. Before reading this tutorial, we hope that you are familiar with how to customize types, metrics, protocols, etc. from and . 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. ``` { "code": 200, "msg": "success", "data": {} } ``` 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 hertzbeat, and monitor and collect its system summary statistics API `http://localhost:1157/api/summary`, the response data is: ``` { "msg": null, "code": 0, "data": { "apps": [ { "category": "service", "app": "jvm", "status": 0, "size": 2, "availableSize": 0, "unManageSize": 2, "unAvailableSize": 0, "unReachableSize": 0 }, { "category": "service", "app": "website", "status": 0, "size": 2, "availableSize": 0, "unManageSize": 2, "unAvailableSize": 0, "unReachableSize": 0 } ] } } ``` This time we get the metrics data such as `category`, `app`, `status`, `size`, `availableSize` under the app. HertzBeat Dashboard -> Monitoring Templates -> New Template -> Config Monitoring Template Yml -> Save and Apply -> Add A Monitoring with The New Monitoring Type We define all monitoring collection types (mysql,jvm,k8s) as yml monitoring templates, and users can import these templates to support corresponding types of monitoring. Monitoring template is used to define the name of monitoring type(international), request parameter mapping, index information, collection protocol configuration information, etc. Here we define a custom monitoring type `app` named `hertzbeat` which use the HTTP protocol to collect

Monitoring Templates -> Config New Monitoring Template Yml -> Save and Apply ```yaml category: custom app: hertzbeat name: zh-CN: HertzBeat en-US: HertzBeat Monitor params: field: host name: zh-CN: Host en-US: Host type: host required: true field: port name: zh-CN: en-US: Port type: number range: '[0,65535]' required: true defaultValue: 1157 field: ssl name: zh-CN: HTTPS en-US: HTTPS type: boolean required: true field: timeout name: zh-CN: (ms) en-US: Timeout(ms) type: number required: false hide: true field: authType name: zh-CN: en-US: Auth Type type: radio required: false hide: true options: label: Basic Auth value: Basic Auth label: Digest Auth value: Digest Auth field: username name: zh-CN: en-US: Username type: text limit: 20 required: false hide: true field: password name: zh-CN: en-US: Password type: password required: false hide: true metrics: name: summary priority: 0 fields: field: app type: 1 label: true field: category type: 1 field: status type: 0 field: size type: 0 field: availableSize type: 0 protocol: http http: host: ^^host^^ port: ^^port^^ url: /api/summary timeout: ^^timeout^^ method: GET ssl: ^^ssl^^ authorization: type: ^^authType^^ basicAuthUsername: ^^username^^ basicAuthPassword: ^^password^^ digestAuthUsername: ^^username^^ digestAuthPassword: ^^password^^ parseType: jsonPath parseScript: '$.data.apps.*' ``` The addition is complete, now we restart the hertzbeat system. We can see that the system page has added a `hertzbeat` monitoring type. We click Add `HertzBeat Monitoring Tool`, configure monitoring IP, port, collection cycle, account password in advanced settings, etc., click OK to add monitoring. 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! Next, we can set the threshold normally. After the alarm is triggered, we can view it in the alarm center, add a new recipient, set alarm notification, etc. Have Fun!!! 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! 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! github: https://github.com/apache/hertzbeat gitee: https://gitee.com/hertzbeat/hertzbeat