Skip to content

Custom Health Function via Func


Guance supports custom health calculation logic through the Func platform. You can write your own functions to freely compute health status based on DQL, composed entities, events, and other data, replacing the default platform algorithm.

Write the Function Script

Create a new function script in Func. The function name is customizable, but must satisfy the following input and output constraints.

Input Parameters:

Field Required Description
entity Yes The entity object for which health is to be calculated, containing basic information such as entity name, type, and tags

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. Returns null when the score cannot be calculated

Function Example:

'''
Custom health function example

Notes:
1. The function name is customizable; the input parameter must include entity
2. entity is the system entity object for which health is to be calculated
3. Inside the function, you can freely query data via DQL, components, events, etc. and compute accordingly
4. The output must include health_status and health_score
'''

@DFF.API('Custom System Health', category='dataPlatform.entityHealthFunc')
def myCustomHealth(entity):
    # Query composed entities, associated alerts, etc. based on entity
    # Custom calculation logic...

    result = {
        'health_status': 'healthy',
        'health_score': 95
    }

    return result

Add Function Category

After writing the function, you must add a category label to it; otherwise, the function will not appear in the health configuration selection list.

The category label is fixed as:

category='dataPlatform.entityHealthFunc'

Publish the Function

Once the code is written, click Publish. Functions that are not published will not be displayed in the health configuration.

Use in Health Configuration

After publishing, go to Unified Catalog > Manage Entity Types, click the "Health Configuration" in the action column, and select "Custom Function".

The dropdown list will then display all published functions categorized as dataPlatform.entityHealthFunc. Select the function you created and save to apply.

FAQ

Why isn't my function appearing in the health configuration dropdown list?

Please check the following three points:

  1. Whether the function has been published;
  2. Whether the category='dataPlatform.entityHealthFunc' label has been added;
  3. Whether the function has been correctly registered via the @DFF.API decorator.

What happens if the function execution fails?

The platform validates the function output. If the output format is incorrect or execution fails, the health status of that system will be displayed as "unknown".

What data can be used inside the function?

Inside the function, you can query metrics, logs, events, etc. via DQL, and also read the composed entity information of the entity. For specific query methods, refer to the Func platform documentation.

Feedback

Is this page helpful?