protected List discoverServices(ConfigResponse config) throws PluginException { List<ServiceResource> services = new ArrayList<ServiceResource>(); try { String proto = config.getValue("protocol"); String hostname = config.getValue("hostname"); int port = Integer.parseInt(config.getValue("port")); String path = DEFAULT_BMX_PATH + QUERY_BMX + VHOST_QUERY + "*"; URL bmxUrl = new URL(proto, hostname, port, path); BmxQuery query = new BmxQuery(bmxUrl); BmxResult result = query.getResult(); List<String> names = result.parseForNames(); for (Iterator<String> it = names.iterator(); it.hasNext(); ) { String name = it.next(); String type = getTypeInfo().getName() + " " + VHOST_SERVICE_TYPE; ServiceResource service = new ServiceResource(); String[] ent = name.split(","); if (ent[0].equals("Type=since-start")) { String host = ent[1].split("=")[1]; String servicePort = ent[2].split("=")[1]; path = DEFAULT_BMX_PATH + QUERY_BMX + VHOST_QUERY + name; ConfigResponse cprops = new ConfigResponse(); cprops.setValue("protocol", proto); cprops.setValue("hostname", hostname); cprops.setValue("port", port); cprops.setValue("path", path); service.setProductConfig(cprops); service.setMeasurementConfig(); service.setType(type); service.setServiceName(host + ":" + servicePort); services.add(service); } } } catch (Exception e) { _log.debug("Exception" + e, e); return null; } return services; }
private List<ServerResource> getServers(List<String> ptqlQueries) { List<ServerResource> servers = new ArrayList<ServerResource>(); // Flag to track success Boolean success = false; for (final Iterator<String> it = ptqlQueries.iterator(); it.hasNext(); ) { String ptql = (String) it.next(); final long[] pids = getPids(ptql); if (null != pids && pids.length > 0) { for (int i = 0; i < pids.length; i++) { Long pid = pids[i]; String installPath = getInstallPath(pid); if (null == installPath) { _log.debug("Found pid " + pid + ", but couldn't identify installpath"); continue; } URL bmxUrl = findBmxUrl(installPath, HTTPD_CONF); if (bmxUrl == null) { _log.debug( "Parsing " + installPath + HTTPD_CONF + " failed to find " + "usable Listen directive."); continue; } URL bmxQueryUrl = getBmxQueryUrl(bmxUrl, QUERY_BMX + SERVER_STATUS); BmxQuery query = new BmxQuery(bmxQueryUrl); BmxResult result = query.getResult(); try { result.parseToProperties(); success = true; } catch (IOException e) { _log.debug("Unable to parse results", e); continue; } Properties serverStatus = result.getProperties(); ServerResource server = createServerResource(installPath); ConfigResponse cprop = new ConfigResponse(); String version = getVersion((String) serverStatus.get("ServerVersion")); if (!version.equals(getTypeInfo().getVersion())) { // Version not matched continue; } cprop.setValue("version", version); cprop.setValue("ServerVersion", (String) serverStatus.get("ServerVersion")); server.setCustomProperties(cprop); ConfigResponse productConfig = new ConfigResponse(); productConfig.setValue("process.query", getProcessQuery(ptql, installPath)); productConfig.setValue("protocol", bmxUrl.getProtocol()); productConfig.setValue("port", bmxUrl.getPort()); productConfig.setValue("hostname", bmxUrl.getHost()); productConfig.setValue("path", bmxUrl.getPath() + QUERY_BMX + SERVER_STATUS); setProductConfig(server, productConfig); // sets a default Measurement Config property with no values setMeasurementConfig(server, new ConfigResponse()); ConfigResponse controlConfig = getControlConfig(installPath); String instanceName = getInstanceName(installPath); setControlConfig(server, controlConfig); server.setName( getPlatformName() + " " + getServerName(RESOURCE_TYPE) + " " + version + " " + instanceName); server.setDescription(getServerDescription(server.getInstallPath())); servers.add(server); } if (!success) { _log.error( "[getServers] Found potential VFWS process however was unable to determine URL of mod_bmx"); _log.error( "[getServers] Make sure -d is specified on command line and that proxying or redirecting isn't including /bmx"); } } } return servers; }