Customizing Health Score Functions via Func¶
TrueWatch supports customizing the calculation logic for system health scores via the Func platform. You can write your own functions to freely calculate health scores using data such as DQL, components, events, etc., replacing the platform's default algorithm.
Writing the Function Script¶
Create a new function script in Func. The function name can be customized, but it must satisfy the following input and output constraints.
Input Parameters:
| Field | Required | Description |
|---|---|---|
entity |
Yes | The current system entity object for which to calculate the health score, containing basic information such as entity name, type, tags, etc. |
Output Parameters:
| Field | Required | Description |
|---|---|---|
health_status |
Yes | Health status. Fixed values: healthy, warning, critical, unknown |
health_score |
Yes | Health score from 0 to 100. Return null if calculation is not possible. |
Function Example:
'''
Example of a custom health score function
Notes:
1. The function name can be customized, but the input parameters must include entity.
2. entity is the current system entity object for which to calculate the health score.
3. Inside the function, you can freely query data via DQL, components, events, etc., and perform calculations.
4. The output must include health_status and health_score.
'''
@DFF.API('Custom System Health Score', category='dataPlatform.entityHealthFunc')
def myCustomHealth(entity):
# Query component entities, associated alerts, etc., based on the entity.
# Implement custom calculation logic...
result = {
'health_status': 'healthy',
'health_score': 95
}
return result
Adding Function Category¶
After writing the function, you must add a category tag to it. Otherwise, the function will not appear in the health score configuration selection list.
The category tag is fixed as:
Publishing the Function¶
After completing the code, click Publish. Unpublished functions will not be displayed in the health score configuration.
Using in Health Score Configuration¶
After successful publication, go to Unified Catalog > Manage Entity Types, click "Health Score Configuration" for the system type row, and select "Custom Function".
The dropdown list will now display all published functions with the category dataPlatform.entityHealthFunc. Select the function you created and save to apply.
FAQ¶
Why doesn't my function appear in the health score configuration dropdown list?
Please check the following three points:
- Whether the function has been published.
- Whether the
category='dataPlatform.entityHealthFunc'tag has been added. - Whether the function is correctly registered via the
@DFF.APIdecorator.
What happens if the function execution fails?
The platform validates the function output. If the output format does not meet the requirements or an execution exception occurs, the health score for that system will be displayed as "unknown".
What data can be used inside the function?
Inside the function, you can query data such as Metrics, LOGs, events, etc., via DQL, and you can also read the component entity information of the entity. For specific query methods, please refer to the Func platform documentation.