Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[JIRA JWS3-21] Allow multiple httpd per agent when using mod_bmx.
Browse files Browse the repository at this point in the history
(cherry picked from commit 4cc84b7)
Signed-off-by: Libor Zoubek <lzoubek@redhat.com>
  • Loading branch information
jfclere authored and Libor Zoubek committed Mar 24, 2015
1 parent 70b4716 commit 62103f1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 68 deletions.
Expand Up @@ -176,10 +176,8 @@ public class ApacheServerComponent implements AugeasRHQComponent, ResourceCompon
private static final String[] CONTROL_SCRIPT_PATHS = { "bin/apachectl", "sbin/apachectl", "bin/apachectl2",
"sbin/apachectl2" };

private static final String DEFAULT_BMX_HANDLER_URL = "http://localhost:8000/bmx";

private static String bmxUrl;
private static boolean useBMX = false;
private String bmxUrl;
private boolean useBMX = false;
static Pattern typePattern = Pattern.compile(".*Type=([\\w-]+),.*");

private ResourceContext<PlatformComponent> resourceContext;
Expand Down Expand Up @@ -351,11 +349,11 @@ public void stop() {
this.lastKnownAvailability = null;
}

public static String getBMXUrl() {
public String getBMXUrl() {
return bmxUrl;
}

public static boolean getUseBMX() {
public boolean getUseBMX() {
return useBMX;
}

Expand Down Expand Up @@ -467,7 +465,7 @@ private void getSNMPValues(MeasurementReport report, Set<MeasurementScheduleRequ
}
}
private void getBMXValues(MeasurementReport report, Set<MeasurementScheduleRequest> schedules) throws Exception {
Map<String,String> values = parseBMXInput(null);
Map<String,String> values = parseBMXInput(null, this.getBMXUrl());
if (LOG.isDebugEnabled()) {
LOG.debug("BMX map: " + values);
}
Expand Down Expand Up @@ -530,7 +528,7 @@ public static String convertStringToBMX(String string) {
return string;
}

public static Map<String, String> parseBMXInput(String vHost) throws Exception {
public static Map<String, String> parseBMXInput(String vHost, String bmxUrl) throws Exception {
Map<String,String> ret = new HashMap<String, String>();
// TODO do some clever caching of data here, so that we won't hammer mod_bmx
URL url = new URL(bmxUrl);
Expand All @@ -540,67 +538,77 @@ public static Map<String, String> parseBMXInput(String vHost) throws Exception {

String line;

while ((line = reader.readLine())!=null) {
try {
while ((line = reader.readLine())!=null) {

if (!line.startsWith("Name: mod_bmx_"))
continue;
if (!line.startsWith("Name: mod_bmx_"))
continue;

// Skip over sample data - this is no real module
if (line.contains("mod_bmx_example"))
continue;
// Skip over sample data - this is no real module
if (line.contains("mod_bmx_example"))
continue;

// Now we have a modules output
// Now we have a modules output

// check for the status module
if (line.contains("mod_bmx_status")) {
slurpSection(ret,reader,"global");
continue;
}
// check for the status module
if (line.contains("mod_bmx_status")) {
slurpSection(ret,reader,"global");
continue;
}


// If the section does not match our vhost, ignore it.
// RHQ will do 3 kinds of vHost:
// null = Guessing Host=_GLOBAL_
// MainServer = ignore the Host and use Port=_ANY_
// |*:6666 = ignore the Host and use Port=6666
// neo4|*:7777 = Use the Host and ignore the Port.
if (vHost == null) {
if (!line.contains("Host=_GLOBAL_,"))
continue;
} else if (vHost.startsWith("|")) {
if (line.contains("Host=_GLOBAL_,"))
continue;
String port = vHost.substring(vHost.indexOf(':')+1);
if (!line.endsWith("Port=" + port))
continue;
} else if (vHost.equals("MainServer")) {
if (line.contains("Host=_GLOBAL_,"))
continue;
if (!line.endsWith("Port=_ANY_"))
continue;
} else {
if (line.contains("Host=_GLOBAL_,"))
continue;
String host = vHost.substring(0,vHost.indexOf('|'));
if (!line.contains("Host=" + host + ","))
continue;
}
// If the section does not match our vhost, ignore it.
// RHQ will do 3 kinds of vHost:
// null = Guessing Host=_GLOBAL_
// MainServer = ignore the Host and use Port=_ANY_
// |*:6666 = ignore the Host and use Port=6666
// neo4|*:7777 = Use the Host and ignore the Port.
if (vHost == null) {
if (!line.contains("Host=_GLOBAL_,"))
continue;
} else if (vHost.startsWith("|")) {
if (line.contains("Host=_GLOBAL_,"))
continue;
String port = vHost.substring(vHost.indexOf(':')+1);
if (!line.endsWith("Port=" + port))
continue;
} else if (vHost.equals("MainServer")) {
if (line.contains("Host=_GLOBAL_,"))
continue;
if (!line.endsWith("Port=_ANY_"))
continue;
} else {
if (line.contains("Host=_GLOBAL_,"))
continue;
String host = vHost.substring(0,vHost.indexOf('|'));
if (!line.contains("Host=" + host + ","))
continue;
}

// Now some global data
Matcher m = typePattern.matcher(line);
// Now some global data
Matcher m = typePattern.matcher(line);

if (m.matches()) {
String type = m.group(1);
if (type.contains("-"))
type= type.substring(type.indexOf("-")+1);
if (m.matches()) {
String type = m.group(1);
if (type.contains("-"))
type= type.substring(type.indexOf("-")+1);

slurpSection(ret, reader, type);
slurpSection(ret, reader, type);
}
if (line.contains("Type=info,"))
break; // We are done with the VirtualHost.
}
} catch (Exception e) {
LOG.warn("parseBMXInput failed" + e);
throw e;
} finally {
try {
in.close();
} catch (Exception e) {
// Ignore it.
}
if (line.contains("Type=info,"))
break; // We are done with the VirtualHost.
}

in.close();
return ret;
}

Expand Down
Expand Up @@ -151,7 +151,7 @@ public void stop() {
}

public AvailabilityType getAvailability() {
if (ApacheServerComponent.getUseBMX())
if (resourceContext.getParentResourceComponent().getUseBMX())
lastKnownAvailability = getAvailabilityBMXInternal();
else
lastKnownAvailability = getAvailabilityInternal();
Expand All @@ -160,23 +160,32 @@ public AvailabilityType getAvailability() {

public AvailabilityType getAvailabilityBMXInternal() {
boolean availability = false;


HttpURLConnection urlConn = null;
try {
URL url = new URL(ApacheServerComponent.getBMXUrl());
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
URL url = new URL(resourceContext.getParentResourceComponent().getBMXUrl());
urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();

if(urlConn.getResponseCode() == HttpURLConnection.HTTP_OK)
availability = true;
else
availability = false;
}catch (ConnectException e) {
} catch (ConnectException e) {
LOG.info("The Apache server is down !");
} catch (MalformedURLException e) {
LOG.error("Malformed URL : " + ApacheServerComponent.getBMXUrl());
LOG.error("Malformed URL : " + resourceContext.getParentResourceComponent().getBMXUrl());
} catch (IOException e) {
e.printStackTrace();
}
LOG.error("IO Error on : " + resourceContext.getParentResourceComponent().getBMXUrl());
} finally {
if (urlConn != null) {
try {
urlConn.disconnect();
} catch (Exception e) {
// Ignored it.
}
}
}

if(!availability)
return AvailabilityType.DOWN;
Expand Down Expand Up @@ -319,7 +328,7 @@ public void deleteResource() throws Exception {
}

public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> schedules) throws Exception {
if (ApacheServerComponent.getUseBMX())
if (resourceContext.getParentResourceComponent().getUseBMX())
getBMXValues(report, schedules);
else
getSNMPValues(report, schedules);
Expand Down Expand Up @@ -364,7 +373,6 @@ private void getSNMPValues(MeasurementReport report, Set<MeasurementScheduleRequ
} catch (SNMPException e) {
LOG.error("An error occurred while attempting to collect an SNMP metric.", e);
}
/* TODO: we need to convert the name like mod_snmp */
}
}
}
Expand All @@ -373,7 +381,7 @@ private void getSNMPValues(MeasurementReport report, Set<MeasurementScheduleRequ
+ this.resourceContext.getResourceKey() + ".");
}
private void getBMXValues(MeasurementReport report, Set<MeasurementScheduleRequest> schedules) throws Exception {
Map<String,String> values = ApacheServerComponent.parseBMXInput(this.resourceContext.getResourceKey());
Map<String,String> values = ApacheServerComponent.parseBMXInput(this.resourceContext.getResourceKey(), resourceContext.getParentResourceComponent().getBMXUrl());
if (LOG.isDebugEnabled()) {
LOG.debug("Collecting BMX metrics");
}
Expand Down

0 comments on commit 62103f1

Please sign in to comment.