Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom metrics does not show


Hi Everyone,

I'm writing a custom pluggin allowing me to monitor the host units used by my tenant. The pluggin works well on the simulator, the custom metrics is displayed in the custom chart window but there is no data in the chart. Does someone know where the problem can be ?

Here are the code of the plugin and the json, considering the token ID and env ID are well informed :

from requests import get as rg import json from ruxit.api.base_plugin import BasePlugin from ruxit.api.snapshot import pgi_name # Calculate the licence number for a given environement def calcHostUnits(envID, token):     #initialize values     hostUnits = 0     dynatraceBaseUrl = "https://XXXXXXXXXXXXX/e/" + envID + "/api/v1/entity/infrastructure/hosts"     headers = {         "api-token": token     }     #API call     response = rg(dynatraceBaseUrl, params = headers)     response = response.json()     #If response not empty, get consumedHostUnits for each host     if len(response) != 0:         for entry in response:             hostUnits += entry['consumedHostUnits']     return hostUnits class DemoPlugin(BasePlugin):     def query(self, **kwargs):         hostUnits = 0         token = self.config["Token"]         ID = self.config["EnvID"]         hostUnits = calcHostUnits(ID, token)         print("On consomme ", hostUnits)         self.results_builder.absolute(key='hostUnits', value=hostUnits)
{     "name": "custom.python.totalhostunits",     "version": "0.3",     "type": "python",     "entity": "HOST",     "metricGroup": "My_Metrics.plugins",     "favicon": "./favicon.jpg",     "source": {         "package": "demo_plugin",         "className": "DemoPlugin",         "install_requires": [             "requests>=2.6.0"         ],         "activation": "Singleton"     },     "metrics": [         {             "timeseries": {                 "key": "hostUnits",                 "unit": "PerMinute",                 "displayname": "Host Units consumed"             }         }     ],     "configUI": {         "displayName": "API calls configuration",         "properties": [             {                 "key": "Token",                 "displayName": "Token",                 "displayHint": "Use a Token authorized on this tenant"             },             {               "key": "EnvID",               "displayName": "Environment ID",               "displayHint": "Enter yout environment ID, can be find in the URL"             }         ]     },     "ui": {       "charts":[{         "group": "Dynatrace Informations",         "title": "Host Unit Consumption",         "series":[{                 "key": "hostUnits",                 "aggregation": "SUM",                 "displayname": "Host Units consumed",                 "seriestype": "line"               }]       }],         "keymetrics": [             {                 "key": "hostUnits",                 "aggregation": "count",                 "mergeaggregation": "avg",                 "displayname": "Host Unit Counter"             }         ],         "keycharts": [           {             "group": "Dynatrace Informations",             "title": "Host Unit Consumption",             "series": [               {                 "key": "hostUnits",                 "aggregation": "SUM",                 "displayname": "Host Units consumed",                 "seriestype": "line"               }             ]           }         ]     },     "properties": [       {         "key": "Token",         "type": "String",         "default_value": "XXXXXXXXXXXXX"       },       {         "key": "EnvID",         "type": "String",         "default_value": "XXXXXXXXX"       }     ] } 

Dynatrace Pro
Dynatrace Pro

I think that an ActiveGate plugin makes more sense for the use case. If you want to do it as a host plugin I'd go with something like this as the last line of your Python script:

self.results_builder.add_absolute_result(PluginMeasurement(key="hostUnits", value=hostUnits, entity_selector=HostSelector()))

I'm not sure it's required, but my host extensions always have this line in them as well in the root of the plugin.json:

"processTypes": [0],