Tutorial 2 Obtain TOKEN index value based on HTTP protocol for subsequent collection and authentication
Through this tutorial, we will describe step by step how to modify on the basis of tutorial 1, add metrics, first call the authentication interface to obtain the TOKEN, and use the TOKEN as a parameter for the subsequent metrics collection and authentication.
Before reading this tutorial, we hope that you are familiar with how to customize types, metrics, protocols, etc. from Custom Monitoring and http Protocol Customization.
Request process
【Authentication information metrics (highest priority)】【HTTP interface carries account password call】->【Response data analysis】->【Analysis and issuance of TOKEN-accessToken as an metric] -> [Assign accessToken as a variable parameter to other collection index groups]
Here we still use the hertzbeat monitoring example of Tutorial 1! The hertzbeat background interface not only supports the basic direct account password authentication used in Tutorial 1, but also supports token authentication.
We need POST to call the login interface /api/account/auth/form to get accessToken, the request body (json format) is as follows:
{
"credential": "hertzbeat",
"identifier": "admin"
}
The response structure data is as follows:
{
"data": {
"token": "xxxx",
"refreshToken": "xxxx"
},
"msg": null,
"code": 0
}