001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2010 Sun Microsystems, Inc. 015 * Portions Copyright 2012-2016 ForgeRock AS. 016 */ 017package org.opends.server.monitors; 018 019import static org.opends.server.util.ServerConstants.*; 020 021import java.lang.management.ManagementFactory; 022import java.lang.management.RuntimeMXBean; 023import java.net.InetAddress; 024import java.util.Arrays; 025import java.util.Collections; 026import java.util.List; 027 028import javax.net.ssl.SSLContext; 029import javax.net.ssl.SSLParameters; 030 031import org.forgerock.i18n.slf4j.LocalizedLogger; 032import org.forgerock.opendj.config.server.ConfigException; 033import org.opends.server.api.MonitorData; 034import org.forgerock.opendj.server.config.server.SystemInfoMonitorProviderCfg; 035import org.opends.server.api.MonitorProvider; 036import org.opends.server.core.DirectoryServer; 037import org.opends.server.types.InitializationException; 038 039/** 040 * This class defines a Directory Server monitor provider that can be used to 041 * collect information about the system and the JVM on which the Directory 042 * Server is running. 043 */ 044public class SystemInfoMonitorProvider 045 extends MonitorProvider<SystemInfoMonitorProviderCfg> 046{ 047 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 048 049 @Override 050 public void initializeMonitorProvider( 051 SystemInfoMonitorProviderCfg configuration) 052 throws ConfigException, InitializationException 053 { 054 // No initialization is required. 055 } 056 057 @Override 058 public String getMonitorInstanceName() 059 { 060 return "System Information"; 061 } 062 063 @Override 064 public MonitorData getMonitorData() 065 { 066 MonitorData attrs = new MonitorData(13); 067 068 attrs.add("javaVersion", System.getProperty("java.version")); 069 attrs.add("javaVendor", System.getProperty("java.vendor")); 070 attrs.add("jvmVersion", System.getProperty("java.vm.version")); 071 attrs.add("jvmVendor", System.getProperty("java.vm.vendor")); 072 attrs.add("javaHome", System.getProperty("java.home")); 073 attrs.add("classPath", System.getProperty("java.class.path")); 074 attrs.add("workingDirectory", System.getProperty("user.dir")); 075 076 String osInfo = System.getProperty("os.name") + " " + 077 System.getProperty("os.version") + " " + 078 System.getProperty("os.arch"); 079 attrs.add("operatingSystem", osInfo); 080 String sunOsArchDataModel = System.getProperty("sun.arch.data.model"); 081 if (sunOsArchDataModel != null) 082 { 083 String jvmArch = sunOsArchDataModel; 084 if (! sunOsArchDataModel.toLowerCase().equals("unknown")) 085 { 086 jvmArch += "-bit"; 087 } 088 attrs.add("jvmArchitecture", jvmArch); 089 } 090 else 091 { 092 attrs.add("jvmArchitecture", "unknown"); 093 } 094 095 try 096 { 097 attrs.add("systemName", InetAddress.getLocalHost().getCanonicalHostName()); 098 } 099 catch (Exception e) 100 { 101 logger.traceException(e); 102 } 103 104 105 Runtime runtime = Runtime.getRuntime(); 106 attrs.add("availableCPUs", runtime.availableProcessors()); 107 attrs.add("maxMemory", runtime.maxMemory()); 108 attrs.add("usedMemory", runtime.totalMemory()); 109 attrs.add("freeUsedMemory", runtime.freeMemory()); 110 String installPath = DirectoryServer.getServerRoot(); 111 if (installPath != null) 112 { 113 attrs.add("installPath", installPath); 114 } 115 String instancePath = DirectoryServer.getInstanceRoot(); 116 if (instancePath != null) 117 { 118 attrs.add("instancePath", instancePath); 119 } 120 121 // Get the JVM input arguments. 122 RuntimeMXBean rtBean = ManagementFactory.getRuntimeMXBean(); 123 List<String> jvmArguments = rtBean.getInputArguments(); 124 if (jvmArguments != null && ! jvmArguments.isEmpty()) 125 { 126 StringBuilder argList = new StringBuilder(); 127 for (String jvmArg : jvmArguments) 128 { 129 if (argList.length() > 0) 130 { 131 argList.append(" "); 132 } 133 134 argList.append("\""); 135 argList.append(jvmArg); 136 argList.append("\""); 137 } 138 139 attrs.add("jvmArguments", argList); 140 } 141 142 try 143 { 144 final SSLContext context = SSLContext.getDefault(); 145 final SSLParameters parameters = context.getSupportedSSLParameters(); 146 attrs.add(ATTR_SUPPORTED_TLS_PROTOCOLS, Arrays.asList(parameters.getProtocols())); 147 attrs.add(ATTR_SUPPORTED_TLS_CIPHERS, Arrays.asList(parameters.getCipherSuites())); 148 } 149 catch (Exception e) 150 { 151 // A default SSL context should always be available. 152 attrs.add(ATTR_SUPPORTED_TLS_PROTOCOLS, Collections.emptyList()); 153 attrs.add(ATTR_SUPPORTED_TLS_CIPHERS, Collections.emptyList()); 154 } 155 156 return attrs; 157 } 158}