use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.
the class ClusterMembersRGraphService method getPhysicalServerJson.
/**
* function used for getting all members details in format of JSON Object array defined under a
* cluster. This function create json based on the relation of physical host and members related
* to it.
*
* @param cluster
* @param host
* @param port
* @return Array list of JSON objects for required fields of members in cluster
*/
private ObjectNode getPhysicalServerJson(Cluster cluster, String host, String port) {
Map<String, List<Cluster.Member>> physicalToMember = cluster.getPhysicalToMember();
ObjectNode clusterTopologyJSON = mapper.createObjectNode();
clusterTopologyJSON.put(this.ID, cluster.getClusterId());
clusterTopologyJSON.put(this.NAME, cluster.getClusterId());
ObjectNode data1 = mapper.createObjectNode();
clusterTopologyJSON.put(this.DATA, data1);
ArrayNode childHostArray = mapper.createArrayNode();
DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN);
updateAlertLists(cluster);
for (Map.Entry<String, List<Cluster.Member>> physicalToMem : physicalToMember.entrySet()) {
String hostName = physicalToMem.getKey();
double hostCpuUsage = 0.0;
long hostMemoryUsage = 0;
double hostLoadAvg = 0.0;
int hostNumThreads = 0;
long hostSockets = 0;
boolean hostSevere = false;
boolean hostError = false;
boolean hostWarning = false;
String hostStatus;
ObjectNode childHostObject = mapper.createObjectNode();
childHostObject.put(this.ID, hostName);
childHostObject.put(this.NAME, hostName);
ArrayNode membersArray = mapper.createArrayNode();
List<Cluster.Member> memberList = physicalToMem.getValue();
for (Cluster.Member member : memberList) {
ObjectNode memberJSONObj = mapper.createObjectNode();
memberJSONObj.put(this.ID, member.getId());
memberJSONObj.put(this.NAME, member.getName());
ObjectNode memberData = mapper.createObjectNode();
memberData.put("gemfireVersion", member.getGemfireVersion());
Long currentHeap = member.getCurrentHeapSize();
Long usedHeapSize = cluster.getUsedHeapSize();
if (usedHeapSize > 0) {
double heapUsage = (currentHeap.doubleValue() / usedHeapSize.doubleValue()) * 100;
memberData.put(this.MEMORY_USAGE, Double.valueOf(df2.format(heapUsage)));
} else
memberData.put(this.MEMORY_USAGE, 0);
double currentCPUUsage = member.getCpuUsage();
memberData.put(this.CPU_USAGE, Double.valueOf(df2.format(currentCPUUsage)));
memberData.put(this.REGIONS, member.getMemberRegions().size());
memberData.put(this.HOST, member.getHost());
if ((member.getMemberPort() == null) || (member.getMemberPort().equals(""))) {
memberData.put(this.PORT, "-");
} else {
memberData.put(this.PORT, member.getMemberPort());
}
memberData.put(this.CLIENTS, member.getMemberClientsHMap().size());
memberData.put(this.GC_PAUSES, member.getGarbageCollectionCount());
memberData.put(this.NUM_THREADS, member.getNumThreads());
// Host CPU Usage is aggregate of all members cpu usage
// hostCpuUsage = hostCpuUsage + currentCPUUsage;
hostCpuUsage = member.getHostCpuUsage();
hostMemoryUsage = hostMemoryUsage + member.getCurrentHeapSize();
hostLoadAvg = member.getLoadAverage();
hostNumThreads = member.getNumThreads();
hostSockets = member.getTotalFileDescriptorOpen();
// defining the status of Member Icons for R Graph based on the alerts
// created for that member
String memberNodeType = "";
// for severe alert
if (severeAlertList.contains(member.getName())) {
memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_SEVERE);
if (!hostSevere) {
hostSevere = true;
}
} else if (errorAlertsList.contains(member.getName())) {
// for error alerts
memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_ERROR);
if (!hostError) {
hostError = true;
}
} else // for warning alerts
if (warningAlertsList.contains(member.getName())) {
memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_WARNING);
if (!hostWarning) {
hostWarning = true;
}
} else {
memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_NORMAL);
}
memberData.put("nodeType", memberNodeType);
memberData.put("$type", memberNodeType);
memberData.put(this.GATEWAY_SENDER, member.getGatewaySenderList().size());
if (member.getGatewayReceiver() != null) {
memberData.put(this.GATEWAY_RECEIVER, 1);
} else {
memberData.put(this.GATEWAY_RECEIVER, 0);
}
memberJSONObj.put(this.DATA, memberData);
memberJSONObj.put(this.CHILDREN, mapper.createArrayNode());
membersArray.add(memberJSONObj);
}
ObjectNode data = mapper.createObjectNode();
data.put(this.LOAD_AVG, Double.valueOf(df2.format(hostLoadAvg)));
data.put(this.SOCKETS, hostSockets);
data.put(this.THREADS, hostNumThreads);
data.put(this.CPU_USAGE, Double.valueOf(df2.format(hostCpuUsage)));
data.put(this.MEMORY_USAGE, hostMemoryUsage);
String hostNodeType;
// setting physical host status
if (hostSevere) {
hostStatus = this.MEMBER_NODE_TYPE_SEVERE;
hostNodeType = "hostSevereNode";
} else if (hostError) {
hostStatus = this.MEMBER_NODE_TYPE_ERROR;
hostNodeType = "hostErrorNode";
} else if (hostWarning) {
hostStatus = this.MEMBER_NODE_TYPE_WARNING;
hostNodeType = "hostWarningNode";
} else {
hostStatus = this.MEMBER_NODE_TYPE_NORMAL;
hostNodeType = "hostNormalNode";
}
data.put("hostStatus", hostStatus);
data.put("$type", hostNodeType);
childHostObject.put(this.DATA, data);
childHostObject.put(this.CHILDREN, membersArray);
childHostArray.add(childHostObject);
}
clusterTopologyJSON.put(this.CHILDREN, childHostArray);
return clusterTopologyJSON;
}
use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.
the class ClusterRegionService method execute.
@Override
public ObjectNode execute(final HttpServletRequest request) throws Exception {
String userName = request.getUserPrincipal().getName();
// get cluster object
Cluster cluster = Repository.get().getCluster();
// json object to be sent as response
ObjectNode responseJSON = mapper.createObjectNode();
// getting cluster's Regions
responseJSON.put("clusterName", cluster.getServerName());
responseJSON.put("userName", userName);
responseJSON.put("region", getRegionJson(cluster));
// Send json response
return responseJSON;
}
use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.
the class ClusterRegionsService method getRegionJson.
/**
* This method is used to get various regions associated with the given cluster and create json
* for each region fields and returns Array List for all the regions associated with given cluster
*
* @param cluster
* @return JSONObject Array List
*/
private ArrayNode getRegionJson(Cluster cluster) {
Long totalHeapSize = cluster.getTotalHeapSize();
Long totalDiskUsage = cluster.getTotalBytesOnDisk();
Map<String, Cluster.Region> clusterRegions = cluster.getClusterRegions();
List<Cluster.Region> clusterRegionsList = new ArrayList<Cluster.Region>();
clusterRegionsList.addAll(clusterRegions.values());
Collections.sort(clusterRegionsList, regionEntryCountComparator);
ArrayNode regionListJson = mapper.createArrayNode();
for (int count = 0; count < clusterRegionsList.size(); count++) {
Cluster.Region reg = clusterRegionsList.get(count);
ObjectNode regionJSON = mapper.createObjectNode();
regionJSON.put("name", reg.getName());
regionJSON.put("totalMemory", totalHeapSize);
regionJSON.put("systemRegionEntryCount", reg.getSystemRegionEntryCount());
regionJSON.put("memberCount", reg.getMemberCount());
final String regionType = reg.getRegionType();
regionJSON.put("type", regionType);
regionJSON.put("getsRate", reg.getGetsRate());
regionJSON.put("putsRate", reg.getPutsRate());
Cluster.Member[] clusterMembersList = cluster.getMembers();
ArrayNode memberNameArray = mapper.createArrayNode();
for (String memberName : reg.getMemberName()) {
for (Cluster.Member member : clusterMembersList) {
String name = member.getName();
name = name.replace(":", "-");
String id = member.getId();
id = id.replace(":", "-");
if ((memberName.equals(id)) || (memberName.equals(name))) {
ObjectNode regionMember = mapper.createObjectNode();
regionMember.put("id", member.getId());
regionMember.put("name", member.getName());
memberNameArray.add(regionMember);
break;
}
}
}
regionJSON.put("memberNames", memberNameArray);
regionJSON.put("entryCount", reg.getSystemRegionEntryCount());
Boolean persistent = reg.getPersistentEnabled();
if (persistent) {
regionJSON.put("persistence", this.VALUE_ON);
} else {
regionJSON.put("persistence", this.VALUE_OFF);
}
Boolean isEnableOffHeapMemory = reg.isEnableOffHeapMemory();
if (isEnableOffHeapMemory) {
regionJSON.put("isEnableOffHeapMemory", this.VALUE_ON);
} else {
regionJSON.put("isEnableOffHeapMemory", this.VALUE_OFF);
}
String regCompCodec = reg.getCompressionCodec();
if (StringUtils.isNotBlank(regCompCodec)) {
regionJSON.put("compressionCodec", reg.getCompressionCodec());
} else {
regionJSON.put("compressionCodec", this.VALUE_NA);
}
regionJSON.put("regionPath", reg.getFullPath());
regionJSON.put("id", reg.getFullPath());
regionJSON.put("memoryReadsTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_GETS_PER_SEC_TREND)));
regionJSON.put("memoryWritesTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_PUTS_PER_SEC_TREND)));
regionJSON.put("diskReadsTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_READS_PER_SEC_TREND)));
regionJSON.put("diskWritesTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_WRITES_PER_SEC_TREND)));
regionJSON.put("emptyNodes", reg.getEmptyNode());
Long entrySize = reg.getEntrySize();
DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2);
String entrySizeInMB = form.format(entrySize / (1024f * 1024f));
if (entrySize < 0) {
regionJSON.put(this.ENTRY_SIZE, VALUE_NA);
} else {
regionJSON.put(this.ENTRY_SIZE, entrySizeInMB);
}
regionJSON.put("dataUsage", reg.getDiskUsage());
regionJSON.put("wanEnabled", reg.getWanEnabled());
regionJSON.put("totalDataUsage", totalDiskUsage);
regionJSON.put("memoryUsage", entrySizeInMB);
regionListJson.add(regionJSON);
}
return regionListJson;
}
use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.
the class ClusterSelectedRegionService method getSelectedRegionJson.
/**
* Create JSON for selected cluster region
*
* @param cluster
* @return ObjectNode Array List
*/
private ObjectNode getSelectedRegionJson(Cluster cluster, String selectedRegionFullPath) {
Long totalHeapSize = cluster.getTotalHeapSize();
Long totalDiskUsage = cluster.getTotalBytesOnDisk();
Cluster.Region reg = cluster.getClusterRegion(selectedRegionFullPath);
if (reg != null) {
ObjectNode regionJSON = mapper.createObjectNode();
regionJSON.put("name", reg.getName());
regionJSON.put("path", reg.getFullPath());
regionJSON.put("totalMemory", totalHeapSize);
regionJSON.put("systemRegionEntryCount", reg.getSystemRegionEntryCount());
regionJSON.put("memberCount", reg.getMemberCount());
final String regionType = reg.getRegionType();
regionJSON.put("type", regionType);
regionJSON.put("getsRate", reg.getGetsRate());
regionJSON.put("putsRate", reg.getPutsRate());
regionJSON.put("lruEvictionRate", reg.getLruEvictionRate());
DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN);
Cluster.Member[] clusterMembersList = cluster.getMembers();
// collect members of this region
List<Cluster.Member> clusterMembersL = new ArrayList<Cluster.Member>();
for (String memberName : reg.getMemberName()) {
for (Cluster.Member member : clusterMembersList) {
String name = member.getName();
name = name.replace(":", "-");
String id = member.getId();
id = id.replace(":", "-");
if ((memberName.equals(id)) || (memberName.equals(name))) {
clusterMembersL.add(member);
}
}
}
// sort members of this region
Collections.sort(clusterMembersL, memberCurrentHeapUsageComparator);
// return sorted member list by heap usage
ArrayNode memberArray = mapper.createArrayNode();
for (Cluster.Member member : clusterMembersL) {
ObjectNode regionMember = mapper.createObjectNode();
regionMember.put("memberId", member.getId());
regionMember.put("name", member.getName());
regionMember.put("host", member.getHost());
long usedHeapSize = cluster.getUsedHeapSize();
long currentHeap = member.getCurrentHeapSize();
if (usedHeapSize > 0) {
double heapUsage = ((double) currentHeap / (double) usedHeapSize) * 100;
regionMember.put("heapUsage", Double.valueOf(df2.format(heapUsage)));
} else {
regionMember.put("heapUsage", 0);
}
double currentCPUUsage = member.getCpuUsage();
double loadAvg = member.getLoadAverage();
regionMember.put("cpuUsage", Double.valueOf(df2.format(currentCPUUsage)));
regionMember.put("currentHeapUsage", member.getCurrentHeapSize());
regionMember.put("isManager", member.isManager());
regionMember.put("uptime", TimeUtils.convertTimeSecondsToHMS(member.getUptime()));
regionMember.put("loadAvg", Double.valueOf(df2.format(loadAvg)));
regionMember.put("sockets", member.getTotalFileDescriptorOpen());
regionMember.put("threads", member.getNumThreads());
regionMember.put("clients", member.getMemberClientsHMap().size());
regionMember.put("queues", member.getQueueBacklog());
memberArray.add(regionMember);
}
regionJSON.put("members", memberArray);
regionJSON.put("entryCount", reg.getSystemRegionEntryCount());
regionJSON.put("persistence", reg.getPersistentEnabled() ? PulseService.VALUE_ON : PulseService.VALUE_OFF);
regionJSON.put("isEnableOffHeapMemory", reg.isEnableOffHeapMemory() ? PulseService.VALUE_ON : PulseService.VALUE_OFF);
String regCompCodec = reg.getCompressionCodec();
if (StringUtils.isNotBlank(regCompCodec)) {
regionJSON.put("compressionCodec", reg.getCompressionCodec());
} else {
regionJSON.put("compressionCodec", PulseService.VALUE_NA);
}
regionJSON.put("regionPath", reg.getFullPath());
regionJSON.put("memoryReadsTrend", mapper.<JsonNode>valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_GETS_PER_SEC_TREND)));
regionJSON.put("memoryWritesTrend", mapper.<JsonNode>valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_PUTS_PER_SEC_TREND)));
regionJSON.put("diskReadsTrend", mapper.<JsonNode>valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_READS_PER_SEC_TREND)));
regionJSON.put("diskWritesTrend", mapper.<JsonNode>valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_WRITES_PER_SEC_TREND)));
regionJSON.put("emptyNodes", reg.getEmptyNode());
Long entrySize = reg.getEntrySize();
DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2);
String entrySizeInMB = form.format(entrySize / (1024f * 1024f));
if (entrySize < 0) {
regionJSON.put(this.ENTRY_SIZE, PulseService.VALUE_NA);
} else {
regionJSON.put(this.ENTRY_SIZE, entrySizeInMB);
}
regionJSON.put("dataUsage", reg.getDiskUsage());
regionJSON.put("wanEnabled", reg.getWanEnabled());
regionJSON.put("totalDataUsage", totalDiskUsage);
regionJSON.put("memoryUsage", entrySizeInMB);
logger.debug("calling getSelectedRegionJson :: regionJSON = {}", regionJSON);
return regionJSON;
} else {
ObjectNode responseJSON = mapper.createObjectNode();
responseJSON.put("errorOnRegion", "Region [" + selectedRegionFullPath + "] is not available");
return responseJSON;
}
}
use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.
the class ClusterSelectedRegionsMemberService method execute.
@Override
public ObjectNode execute(final HttpServletRequest request) throws Exception {
String userName = request.getUserPrincipal().getName();
String pulseData = request.getParameter("pulseData");
JsonNode parameterMap = mapper.readTree(pulseData);
String selectedRegionFullPath = parameterMap.get("ClusterSelectedRegionsMember").get("regionFullPath").textValue();
logger.trace("ClusterSelectedRegionsMemberService selectedRegionFullPath = {}", selectedRegionFullPath);
// get cluster object
Cluster cluster = Repository.get().getCluster();
// json object to be sent as response
ObjectNode responseJSON = mapper.createObjectNode();
// getting cluster's Regions
responseJSON.put("clusterName", cluster.getServerName());
responseJSON.put("userName", userName);
responseJSON.put("selectedRegionsMembers", getSelectedRegionsMembersJson(cluster, selectedRegionFullPath));
// Send json response
return responseJSON;
}
Aggregations