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

Specify a dt.extension.host for custom metrics different to the one added automatically by the OneAgent

MarianneR
Frequent Guest

I have developed a Python extension using the 2.0 framework that connects to a Microsoft SQL Server, executes a stored procedure, and reports custom metrics to Dynatrace. I am trying to specify the dt.entity.host dimension for my metrics because the host on which the extension runs is not necessarily the one that should be associated with the metric. The metric does appear in Dynatrace, but it seems as though the dt.entity.host dimension is being overriden by the OneAgent and it always shows host from the endpoint specified in the monitoring configuration.

So far, I have tried hard-coding the dimension as dt.entity.host = HOST-XXXXXXX, where HOST-XXXXXXX is another host's id as written on Dynatrace:

 

 

dimensions = {'job_id':'XXX',
              'name': 'XXX',
                  ...
              'dt.entity.host': 'HOST-XXXXXXXXXXXXXX' 
              }
self.report_metric("metric.name", 1, dimensions)

 

 

 

I have also created a host entity in my topology, since I want to specify a "RUNS_ON" relationship for my other entities. Here is the code for the extension.yaml file:

 

 

name: custom:foo-extension
version: 0.0.14
minDynatraceVersion: "1.253"
author:
  name: "Name"

python:
  runtime:
    module: foo_extension
    version:
      min: "3.9"

  activation:
    remote:
      path: activationSchema.json
    local:
      path: activationSchema.json

  featureSets:
    - featureSet: Job
      metrics:
        - key: mssql.job.status
    - featureSet: Job Step
      metrics:
        - key: mssql.jobstep.status


metrics:
  - key: mssql.job.status
    metadata:
      description: last run outcome of the job
      displayName: mssql job status
      unit: gauge
      dimensions:
        - key: job_id
          displayName: Job ID
        - key: job_name
          displayName: Job Name
        - key: category
          displayName: Category
        - key: type
          displayName: Type
        - key: owner
          displayName: Owner
        - key: current_execution_status
          displayName: Current Execution Status
        - key: has_step
          displayName: Total Number of Steps Per Job
        - key: current_execution_step
          displayName: Current Execution Step's Name
        - key: step_id
          displayName: This Step's ID
  - key: mssql.jobstep.status
    metadata:
      description: last run outcome of the job step
      displayName: mssql job step status
      unit: gauge
      dimensions:
        - key: job_id
          displayName: This Job's ID
        - key: job_name
          displayName: This Job's Name
        - key: step_id
          displayName: This Step's ID
        - key: step_name
          displayName: Step Name

topology:
  types:
    - enabled: true
      name: foo-extension:host
      displayName: Host
      rules:
        - idPattern: "{dt.entity.host}"
          instanceNamePattern: "{dt.entity.host}"
          iconPattern: azure
          attributes:
            - key: job_id
              displayName: Job ID
              pattern: "{job_id}"
            - key: name
              displayName: Job Name
              pattern: "{job_name}"
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.job.)
            - sourceType: Metrics
              condition: $prefix(mssql.jobstep.)
          role: default

    - enabled: true
      name: foo-extension:job
      displayName: Job
      rules:
        - idPattern: "{job_id}"
          instanceNamePattern: "{job_name}"
          iconPattern: mssql
          attributes:
          - key: type
            displayName: Type
            pattern: "{type}"
          - key: owner
            displayName: Owner
            pattern: "{owner}"
          - key: category
            displayName: Category
            pattern: "{category}"
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.job.)
          role: default

    - enabled: true
      name: foo-extension:jobstep
      displayName: Job step
      rules:
        - idPattern: "{job_id}-{step_id}"
          instanceNamePattern: "{step_name}"
          iconPattern: mssql
          attributes:
            - key: job_id
              displayName: this job's id
              pattern: "{job_id}"
            - key: job
              displayName: this job's name
              pattern: "{job_name}"
            - key: step_id
              displayName: this step's id
              pattern: "{step_id}"
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.jobstep.)
          role: default

  relationships:
    - enabled: true
      sources:
        - sourceType: Metrics
          condition: $prefix(mssql.job.)
        - sourceType: Metrics
          condition: $prefix(mssql.jobstep.)
      fromType: foo-extension:jobstep
      typeOfRelation: CHILD_OF
      toType: foo-extension:job

    - enabled: true
      sources:
        - sourceType: Metrics
          condition: $prefix(mssql.job.)
        - sourceType: Metrics
          condition: $prefix(mssql.jobstep.)
      fromType: foo-extension:job
      typeOfRelation: RUNS_ON
      toType: foo-extension:host

 

 

 

What can I do to be able to specify a  dt.entity.host other than the one the extension is running on? Am I missing some information or is this simply not possible with the use of a OneAgent and I should use an ActiveGate instead?

 

Any help on the matter is greatly appreciated!

3 REPLIES 3

rudy_h
Helper

Hi,

Why don't you use sql_server_host instead?

rudy_h_0-1720154952900.png

Best Regards,

Rudy

Hi, thank you for your help!

I am still not able to get the RUNS_ON relationship to work for my entities. I have even tried defining the  sql:sql_server_instance instead.

This is what I have now:

 

 

topology:
  types:
    - name: sql:sql_server_instance
      displayName: MSSQLSERVER
      enabled: true
      rules:
        - idPattern: sql_server_instance_{originating_server}
          instanceNamePattern: "MSSQLSERVER on {originating_server} (via: {originating_server})"
          iconPattern: mssql
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.job.)
            - sourceType: Metrics
              condition: $prefix(mssql.jobstep.)
    
    - name: foo-extension:job
      displayName: Job
      enabled: true
      rules:
        - idPattern: "{job_id}"
          instanceNamePattern: "{job_name}"
          iconPattern: mssql
          attributes:
          - key: type
            displayName: Type
            pattern: "{type}"
          - key: owner
            displayName: Owner
            pattern: "{owner}"
          - key: category
            displayName: Category
            pattern: "{category}"
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.job.)
            - sourceType: Metrics
              condition: $prefix(mssql.jobstep.)
          role: default

    - name: foo-extension:jobstep
      displayName: Job Step
      enabled: true
      rules:
        - idPattern: "{job_id}-{step_id}"
          instanceNamePattern: "{step_name}"
          iconPattern: mssql
          attributes:
            - key: job_id
              displayName: this job's id
              pattern: "{job_id}"
            - key: job
              displayName: this job's name
              pattern: "{job_name}"
            - key: step_id
              displayName: this step's id
              pattern: "{step_id}"
          sources:
            - sourceType: Metrics
              condition: $prefix(mssql.jobstep.)
          role: default

  relationships:
    - enabled: true
      sources:
        - sourceType: Metrics
          condition: $prefix(mssql.job.)
        - sourceType: Metrics
          condition: $prefix(mssql.jobstep.)
      fromType: foo-extension:jobstep
      typeOfRelation: CHILD_OF
      toType: foo-extension:job

    - enabled: true
      sources:
        - sourceType: Entities
          mappingRules:
            - sourceProperty: originating_server
              sourceTransformation: To lower case
              destinationProperty: server
              destinationTransformation: To lower case
      fromType: foo-extension:job
      typeOfRelation: RUNS_ON
      toType: sql:sql_server_instance

    - enabled: true
      sources:
        - sourceType: Entities
          mappingRules:
            - sourceProperty: originating_server
              sourceTransformation: To lower case
              destinationProperty: server
              destinationTransformation: To lower case
      fromType: foo-extension:jobstep
      typeOfRelation: RUNS_ON
      toType: sql:sql_server_instance
    

 

 

 

The originating_server dimension is currently hard coded to a host that is already present in Dynatrace.

Is there something wrong with my mapping and why is it still showing null in Dynatrace in the runs_on field for my entities?

I moved the issue here and posted the code that ended up working: Solved: Defining a RUNS_ON relationship between custom entities and sql_server instance - Dynatrace ...

I defined the job as a child_of a sql_server_instance instead of defining a different dt.entity.host.

For those wondering, I was able to change that metric dimension by assigning its value to a host's id I found in Dynatrace, but it ended up not being the best fit for my particular case. The problem I had in the original post was due to the SAME_AS relationship I had previously defined, and not due to the way the dimension was defined. However, I'm still not sure how that change affected the relationships defined, as I made the change before I got any of my relationships to work.

Featured Posts