Thursday 23 June 2022

Atlas client: Get the metrics of the service instance that client is pointing to

Using ‘getAtlasMetrics()’ method, you can get the metrics of the service instance the client is pointing to.

 

Example

AtlasMetrics atlasMetrics = atlasClient.getAtlasMetrics();
Map<String, Map<String, Object>> metrics = atlasMetrics.getData();

 

Find the below working application.

 

Step 1: Define atlas-application.properties file under src/main/resources folder.

 

atlas-application.properties

 

atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

 

Step 2: Define JsonUtil class.

 

JsonUtil.java

 

package com.sample.app.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtil {
  public static String marshal(Object obj) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(obj);
  }

  public static <T> T unmarshal(Class<T> clazz, String json)
      throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    return (T) mapper.readValue(json, clazz);
  }

  public static String prettyPrintJson(Object obj) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    return mapper.writeValueAsString(obj);
  }
}

 

Step 3: Define AtlasServerMetrics class.

 

AtlasServerMetrics.java

 

package com.sample.app.server;

import java.util.Map;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.metrics.AtlasMetrics;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

public class AtlasServerMetrics {
  public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
    AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
        new String[] { "admin", "admin" });

    AtlasMetrics atlasMetrics = atlasClient.getAtlasMetrics();

    Map<String, Map<String, Object>> metrics = atlasMetrics.getData();
    String json = JsonUtil.prettyPrintJson(metrics);
    System.out.println(json);

  }
}

Output

{
  "general" : {
    "collectionTime" : 1644490987100,
    "entityCount" : 11,
    "stats" : {
      "Notification:lastMessageProcessedTime" : 0,
      "Notification:currentDayEntityUpdates" : 0,
      "Notification:currentDayFailed" : 0,
      "Notification:topicDetails" : { },
      "Notification:currentHourStartTime" : 1644490800000,
      "Notification:previousDayEntityCreates" : 0,
      "Notification:currentHourAvgTime" : 0,
      "Notification:previousHour" : 0,
      "Notification:totalUpdates" : 0,
      "Notification:previousHourEntityUpdates" : 0,
      "Server:statusIndexStore" : "connected",
      "Notification:totalAvgTime" : 0,
      "Notification:currentDayEntityDeletes" : 0,
      "Notification:currentHourEntityCreates" : 0,
      "Notification:totalDeletes" : 0,
      "Notification:previousHourEntityDeletes" : 0,
      "Server:startTimeStamp" : 1644488314006,
      "Notification:previousHourEntityCreates" : 0,
      "Notification:currentDayStartTime" : 1644451200000,
      "Server:upTime" : "44 min 33 sec",
      "Notification:currentDay" : 0,
      "Notification:currentHourEntityUpdates" : 0,
      "Notification:currentHour" : 0,
      "Notification:totalFailed" : 0,
      "Notification:currentDayEntityCreates" : 0,
      "Notification:currentHourEntityDeletes" : 0,
      "Server:statusBackendStore" : "connected",
      "Notification:totalCreates" : 0,
      "Notification:previousDayEntityUpdates" : 0,
      "Notification:currentHourFailed" : 0,
      "Notification:currentDayAvgTime" : 0,
      "Notification:previousHourFailed" : 0,
      "Notification:total" : 0,
      "Notification:previousDayEntityDeletes" : 0,
      "Server:activeTimeStamp" : 1644488314006,
      "Notification:previousDay" : 0,
      "Notification:previousHourAvgTime" : 0,
      "Notification:previousDayFailed" : 0,
      "Notification:previousDayAvgTime" : 0
    },
    "tagCount" : 1,
    "typeUnusedCount" : 100,
    "typeCount" : 215
  },
  "system" : {
    "memory" : {
      "heapInit" : "268435456",
      "heapMax" : "954728448",
      "heapCommitted" : "764411904",
      "heapUsed" : "466154992",
      "nonHeapInit" : "2555904",
      "nonHeapMax" : "-1",
      "nonHeapCommitted" : "192962560",
      "nonHeapUsed" : "187031184",
      "memory_pool_usages" : {
        "PS Eden Space" : {
          "init" : 67108864,
          "used" : 265412240,
          "committed" : 277348352,
          "max" : 284688384
        },
        "PS Survivor Space" : {
          "init" : 11010048,
          "used" : 14350776,
          "committed" : 37224448,
          "max" : 37224448
        },
        "PS Old Gen" : {
          "init" : 179306496,
          "used" : 186391976,
          "committed" : 449839104,
          "max" : 716177408
        }
      }
    },
    "os" : {
      "os.spec" : "Mac OS X, x86_64, 10.16",
      "os.vcpus" : "16"
    },
    "runtime" : {
      "name" : "Java HotSpot(TM) 64-Bit Server VM",
      "version" : "1.8.0_311"
    }
  },
  "tag" : {
    "tagEntities" : {
      "classified" : 2
    }
  },
  "entity" : {
    "entityDeleted-typeAndSubTypes" : { },
    "entityActive-typeAndSubTypes" : {
      "Referenceable" : 11,
      "DataSet" : 10,
      "merger_process" : 1,
      "jdbc_table" : 1,
      "Asset" : 11,
      "Process" : 1,
      "jdbc_column" : 3,
      "jdbc_db" : 1
    },
    "entityActive" : {
      "DataSet" : 5,
      "merger_process" : 1,
      "jdbc_table" : 1,
      "jdbc_column" : 3,
      "jdbc_db" : 1
    },
    "entityShell" : { },
    "entityShell-typeAndSubTypes" : { },
    "entityDeleted" : { }
  }
}



 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment