public ProcessExecutionResults executeProcess(ProcessExecution processExecution) { // TODO: doesn't look like SIGAR has an API to fork/execute processes? fallback to using the Java way return SystemInfoFactory.createJavaSystemInfo().executeProcess(processExecution); }
private boolean isWindows() { return this.systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS; }
private List<ProcessInfo> getProcessInfos() { SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); log.debug("Retrieving process table..."); long startTime = System.currentTimeMillis(); List<ProcessInfo> processInfos = null; try { processInfos = systemInfo.getAllProcesses(); } catch (UnsupportedOperationException uoe) { log.debug("Cannot perform process scan - not supported on this platform. (" + systemInfo.getClass() + ")"); } long elapsedTime = System.currentTimeMillis() - startTime; if (log.isDebugEnabled()) { log.debug("Retrieval of process table took " + elapsedTime + " ms."); } return processInfos; }
tokens.put(TOKEN_PREFIX + "hostname", systemInfo.getHostname()); tokens.put(TOKEN_PREFIX + "os.name", systemInfo.getOperatingSystemName()); tokens.put(TOKEN_PREFIX + "os.version", systemInfo.getOperatingSystemVersion()); tokens.put(TOKEN_PREFIX + "os.type", systemInfo.getOperatingSystemType().toString()); tokens.put(TOKEN_PREFIX + "architecture", systemInfo.getSystemArchitecture()); try { tokens.put(TOKEN_PREFIX + "cpu.count", Integer.toString(systemInfo.getNumberOfCpus())); } catch (Exception e) { tokens.put(TOKEN_PREFIX + "cpu.count", "?"); allNetworkAdapters = systemInfo.getAllNetworkAdapters(); } catch (Exception e) { try { tokens.put(TOKEN_PREFIX + "interfaces.java.address", InetAddress .getByName(systemInfo.getHostname()).getHostAddress()); } catch (Exception e) { tokens.put(TOKEN_PREFIX + "interfaces.java.address", InetAddress.getLocalHost().getHostAddress());
private ProcessExecutionResults startNode(File basedir) { if (log.isDebugEnabled()) { log.debug("Starting node at " + basedir); } File binDir = new File(basedir, "bin"); File startScript; SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); ProcessExecution startScriptExe; if (systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS) { startScript = new File(binDir, "cassandra.bat"); startScriptExe = createProcessExecution(null, startScript); } else { startScript = new File(binDir, "cassandra"); startScriptExe = createProcessExecution(null, startScript); startScriptExe.addArguments(Arrays.asList("-p", "cassandra.pid")); } startScriptExe.setWaitForCompletion(0); ProcessExecutionResults results = systemInfo.executeProcess(startScriptExe); if (log.isDebugEnabled()) { log.debug(startScript + " returned with exit code [" + results.getExitCode() + "]"); } return results; }
JvmResourceKey.Type oldKeyType = oldKey.getType(); if (oldKeyType == JvmResourceKey.Type.Legacy || oldKeyType == JvmResourceKey.Type.JmxRemotingPort) { if (!inventoriedResource.getSystemInformation().isNative()) { log.warn("Cannot attempt to upgrade Resource key [" + inventoriedResource.getResourceKey() + "] of JVM Resource, because this Agent is not running with native system info support (i.e. SIGAR)."); List<ProcessInfo> processes = inventoriedResource.getSystemInformation().getProcesses( "process|pid|match=" + pid); if (processes.size() != 1) {
public void stopLogFileEventPollers() { boolean sigarAvailable = this.resourceContext.getSystemInformation().isNative(); if (!sigarAvailable) { return; } for (Iterator<PropertyMap> iterator = this.startedEventSources.iterator(); iterator.hasNext(); ) { PropertyMap logEventSource = iterator.next(); EventContext eventContext = this.resourceContext.getEventContext(); String logFilePath = logEventSource.getSimpleValue(LogEventSourcePropertyNames.LOG_FILE_PATH, null); eventContext.unregisterEventPoller(LOG_ENTRY_EVENT_TYPE, logFilePath); iterator.remove(); } }
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context) { Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(1); String name = ParentDefinedJMXServerNamingUtility.getJVMName(context); String version = System.getProperty("java.version"); DiscoveredResourceDetails localVM = new DiscoveredResourceDetails(context.getResourceType(), RESOURCE_KEY, name, version, DEFAULT_RESOURCE_DESCRIPTION, context.getDefaultPluginConfiguration(), context.getSystemInformation().getThisProcess()); Configuration configuration = localVM.getPluginConfiguration(); configuration.put(new PropertySimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY, "Local Connection")); configuration.put(new PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE, InternalVMTypeDescriptor.class .getName())); discoveredResources.add(localVM); return discoveredResources; }
String hostname = systemInfo.getHostname(); String version = UNKNOWN_VERSION; String port = UNKNOWN_PORT;
tokens.put(TOKEN_PREFIX + "hostname", systemInfo.getHostname()); tokens.put(TOKEN_PREFIX + "os.name", systemInfo.getOperatingSystemName()); tokens.put(TOKEN_PREFIX + "os.version", systemInfo.getOperatingSystemVersion()); tokens.put(TOKEN_PREFIX + "os.type", systemInfo.getOperatingSystemType().toString()); tokens.put(TOKEN_PREFIX + "architecture", systemInfo.getSystemArchitecture()); try { tokens.put(TOKEN_PREFIX + "cpu.count", Integer.toString(systemInfo.getNumberOfCpus())); } catch (Exception e) { tokens.put(TOKEN_PREFIX + "cpu.count", "?"); allNetworkAdapters = systemInfo.getAllNetworkAdapters(); } catch (Exception e) { try { tokens.put(TOKEN_PREFIX + "interfaces.java.address", InetAddress .getByName(systemInfo.getHostname()).getHostAddress()); } catch (Exception e) { tokens.put(TOKEN_PREFIX + "interfaces.java.address", InetAddress.getLocalHost().getHostAddress());
boolean sigarAvailable = this.resourceContext.getSystemInformation().isNative(); if (!sigarAvailable && !enabledEventSources.isEmpty()) { boolean nativeSystemInfoDisabled = SystemInfoFactory.isNativeSystemInfoDisabled();
pluginConfig.setSimpleValue("hostXmlFileName", getHostXmlFileName(commandLine)); ProcessInfo agentProcess = discoveryContext.getSystemInformation().getThisProcess(); setStartScriptPluginConfigProps(process, commandLine, pluginConfig, agentProcess); setUserAndPasswordPluginConfigProps(serverPluginConfig, hostConfig);
String hostname = systemInfo.getHostname(); TomcatConfig tomcatConfig = parseTomcatConfig(catalinaBase); tomcatConfig = applySystemProperties(tomcatConfig, commandLine);
Cli() { // When running the CLI on Windows, make sure no "pause" message is shown after script execution // Otherwise the CLI process will just keep running so we'll never get the exit code if (systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS) { startScriptEnv.put("NOPAUSE", "1"); } }
public ProcessExecutionResults executeProcess(ProcessExecution processExecution) { // TODO: doesn't look like SIGAR has an API to fork/execute processes? fallback to using the Java way return SystemInfoFactory.createJavaSystemInfo().executeProcess(processExecution); }
Set<ProcessScan> processScans = this.resource.getResourceType().getProcessScans(); if (processScans != null && !processScans.isEmpty()) { ProcessInfoQuery piq = new ProcessInfoQuery(systemInfo.getAllProcesses()); for (ProcessScan processScan : processScans) { List<ProcessInfo> queryResults = piq.query(processScan.getQuery());
private boolean isWindows(ResourceDiscoveryContext context) { return context.getSystemInformation().getOperatingSystemType() == OperatingSystemType.WINDOWS; }
processExecution.setKillOnTimeout(true); ProcessExecutionResults results = systemInfo.executeProcess(processExecution); String versionOutput = results.getCapturedOutput();
public Map<String, String> getEnvironmentVariables() { if (this.procEnv == null) { return Collections.emptyMap(); } if (this.environmentVariables == null) { this.environmentVariables = new HashMap<String, String>(this.procEnv.size()); SystemInfo systemInfo = SystemInfoFactory.createJavaSystemInfo(); boolean isWindows = systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS; if (isWindows) { // Windows environment is case-insensitive so convert variable names to all-caps, // this way we will be able to do case-insensitive lookups from the map later for (Map.Entry<String, String> env : this.procEnv.entrySet()) { this.environmentVariables.put(env.getKey().toUpperCase(), env.getValue()); } } else { this.environmentVariables.putAll(procEnv); } } return this.environmentVariables; }
return systemInfo.executeProcess(processExecution);