How to Report Custom Advanced Functions with Local Func¶
If you want to use configured local functions in Time Series > Advanced Functions, you need to create a local function script in Local Func after setting up the TrueWatch connector. Once published, you can use the custom advanced functions.
Specific Steps¶
Step 1: Create the TrueWatch Connector¶
Step 2: Write the Advanced Function¶
Create a local function script in Func. An example algorithm is as follows:
'''
Example Algorithm for Advanced Functions
Example processing content:
1. Data is passed into the DQL statement
2. Return the result after algorithm processing
Note:
The entry function for the detection algorithm is fixed as `AlgorithmScriptName(data,**kwargs)`
data is the structure of 'series' after querying data with DQL, as shown below:
[
{
'name': 'cpu',
'tags': {'image': 'nginx'},
'columns': ['usage_total', 'last'],
'values': [[1681200000000, 8],[1681202880000, 23],......]
}
...
]
**kwargs are optional parameters for the algorithm
Entry function: DBSCAN(data,eps)
Example output:
[
{
'status' : "abnormal_series",
# Mark whether this time series data is normal or an outlier. Outliers are marked as "abnormal_series", normal data as "normal_series"
'name' : 'cpu',
"tags" : {'image': 'nginx'},
'colums' : ['usage_total', 'last'],
"values" : [[1681274880000,8],[1681277760000,20],……],
},
...
]
'''
After writing the function, add the category type. The user category is written as follows:
Warning
After writing the code, do not forget to publish it!!!
Step 3: Use the Local Function¶
After completing the above steps, the custom advanced function will be added to the TrueWatch workspace. In TrueWatch Scenarios, Create a Dashboard, add Time Series, and you can see the local function under Advanced Functions, as shown:
Step 4: Display Styles¶
- Effect after configuring outliers:
- If there are no outliers, the original data is displayed: