mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-02 17:19:37 +00:00
Global socket count not being evaluated correctly
This commit is contained in:
1 parent
eebbf08023
commit
d90b6456aa
2 files changed
+46
-48
No files matched your search
+14
-15
@@ -24,36 +24,35 @@ import com.sap.sailing.monitoring.sysinfo.SystemInformationImpl;
|
||||
/**
|
||||
* This monitor tries to restart registered services
|
||||
* on failure. It also sends out email to fixed recipients including system information.
|
||||
*
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 26, 2012
|
||||
*/
|
||||
public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
Logger log = Logger.getLogger(OSGiRestartingPortMonitor.class.getName());
|
||||
|
||||
|
||||
SystemInformation info = null;
|
||||
|
||||
|
||||
public OSGiRestartingPortMonitor(Properties properties) {
|
||||
super(properties);
|
||||
|
||||
|
||||
String[] props_bundles = properties.getProperty("monitor.bundles").split(",");
|
||||
|
||||
|
||||
for (int i=0; i<endpoints.length;i++) {
|
||||
endpoints[i].setBundleName(props_bundles[i].trim());
|
||||
}
|
||||
|
||||
this.info = SystemInformationImpl.getInstance();
|
||||
|
||||
this.info = SystemInformationImpl.getInstance();
|
||||
log.info("Started and initialized OSGi monitor. State of SIGAR sysstats library: " + (info == null ? "INACTIVE" : "ACTIVE") + " java.library.path: " + System.getProperty("java.library.path"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(Endpoint endpoint) {
|
||||
public void handleFailure(Endpoint endpoint) {
|
||||
boolean sysinfo_available = true;
|
||||
if (this.info == null) {
|
||||
sysinfo_available = false;
|
||||
}
|
||||
|
||||
|
||||
Bundle bundle = getBundleByName(endpoint.getBundleName());
|
||||
if (bundle == null) {
|
||||
log.severe("Couldn't find bundle "+endpoint.getBundleName()+". Cannot restart. Please check monitoring.properties file");
|
||||
@@ -86,7 +85,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
}
|
||||
final String subject = "Bundle " + endpoint.getBundleName() + " restarted";
|
||||
log.info(subject);
|
||||
|
||||
|
||||
/* only send mail if service has not failed before and mailing is enabled */
|
||||
if (!endpoint.hasFailed() /* before */ && this.properties.getProperty("mail.enabled", "true").equalsIgnoreCase("true")) {
|
||||
log.info("Sending mail to " + this.properties.getProperty("mail.to") + " saying that bundle "
|
||||
@@ -95,7 +94,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
String content = "The Bundle " + endpoint.getBundleName() + " has been restarted - check on "
|
||||
+ endpoint + " didn't respond!\n"
|
||||
+ "This Mail won't be sent again if service continues to fail.";
|
||||
|
||||
|
||||
if (sysinfo_available) {
|
||||
content += "\n\nSystem Information BEFORE restart:\n" + info_before_restart;
|
||||
content += "\n\nSystem information AFTER restart:\n" + info.toString();
|
||||
@@ -116,7 +115,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
Session session = Session.getInstance(this.properties, new SMTPAuthenticator());
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
msg.setFrom(new InternetAddress("root@sapsailing.com"));
|
||||
msg.setSubject(subject);
|
||||
msg.setSubject(subject);
|
||||
msg.setContent(content, "text/plain");
|
||||
for (String mailAddress : this.properties.getProperty("mail.to").split(",")) {
|
||||
msg.addRecipient(RecipientType.TO, new InternetAddress(mailAddress.trim()));
|
||||
@@ -126,7 +125,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
ts.sendMessage(msg, msg.getRecipients(RecipientType.TO));
|
||||
ts.close();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleConnection(Endpoint endpoint) {
|
||||
}
|
||||
@@ -136,10 +135,10 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
if (bundle.getSymbolicName().equalsIgnoreCase(name))
|
||||
return bundle;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private class SMTPAuthenticator extends javax.mail.Authenticator {
|
||||
public PasswordAuthentication getPasswordAuthentication() {
|
||||
String username = properties.getProperty("mail.smtp.user");
|
||||
|
||||
+32
-33
@@ -25,13 +25,13 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
|
||||
private Sigar sigar_manager;
|
||||
private OperatingSystemMXBean java_manager;
|
||||
|
||||
|
||||
private static SystemInformation singleton = null;
|
||||
|
||||
|
||||
private long used_sockets = -1;
|
||||
private long allocated_tcp_connections = -1;
|
||||
private long used_tcp_connections = -1;
|
||||
|
||||
|
||||
/**
|
||||
* @return An instance in case SIGAR can be activated. You always have to check
|
||||
* for a null value.
|
||||
@@ -44,17 +44,17 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
singleton = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
public SystemInformationImpl() throws SigarException {
|
||||
Sigar.load(); /* check if native libraries can be loaded */
|
||||
|
||||
this.sigar_manager = new Sigar();
|
||||
this.java_manager = ManagementFactory.getOperatingSystemMXBean();
|
||||
}
|
||||
|
||||
|
||||
protected String[] readProc(String path) {
|
||||
String line = ""; StringBuffer buf = new StringBuffer();
|
||||
BufferedReader reader = null;
|
||||
@@ -76,40 +76,39 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
}
|
||||
}
|
||||
return buf.toString().split("\\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void parseSockStat() {
|
||||
String[] sockstat = new String[]{};
|
||||
try {
|
||||
sockstat = readProc("/proc/" + getPid() + "/net/sockstat");
|
||||
} catch (Exception e) {
|
||||
/* seems that there are no local socket counts, try to use
|
||||
* global ones */
|
||||
try {
|
||||
sockstat = readProc("/proc/net/sockstat");
|
||||
} catch (Exception ex) {
|
||||
/* ok something went wrong */
|
||||
ex.printStackTrace();
|
||||
}
|
||||
/* ignore, something went wrong with PID extraction */
|
||||
}
|
||||
|
||||
|
||||
/* seems that there are no local socket counts,
|
||||
* try to use global ones */
|
||||
if (sockstat.length == 0) {
|
||||
sockstat = readProc("/proc/net/sockstat");
|
||||
}
|
||||
|
||||
for (String line : sockstat) {
|
||||
String[] parts = line.split(" ");
|
||||
if (parts[0].equalsIgnoreCase("sockets:"))
|
||||
this.used_sockets = Long.parseLong(parts[2].trim());
|
||||
|
||||
|
||||
if (parts[0].equalsIgnoreCase("TCP:")) {
|
||||
this.allocated_tcp_connections = Long.parseLong(parts[8].trim());
|
||||
this.used_tcp_connections = Long.parseLong(parts[2].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProcessInformation getProcessInformation(long pid) {
|
||||
return new ProcessInformationImpl(pid, sigar_manager);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getOutbundOpenConnectionCount() throws Exception {
|
||||
int flags = NetFlags.CONN_TCP | NetFlags.CONN_UDP | NetFlags.CONN_CLIENT;
|
||||
@@ -150,7 +149,7 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
@Override
|
||||
public long getOpenFiles() {
|
||||
String[] val = readProc("/proc/sys/fs/file-nr");
|
||||
|
||||
|
||||
if(val.length > 0)
|
||||
return Long.parseLong(val[0].split("\t| ")[0].trim());
|
||||
return -1;
|
||||
@@ -159,7 +158,7 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
@Override
|
||||
public long getMaxOpenFiles() throws Exception {
|
||||
String[] val = readProc("/proc/sys/fs/file-max");
|
||||
|
||||
|
||||
if (val.length > 0)
|
||||
return Long.parseLong(val[0].trim());
|
||||
return -1;
|
||||
@@ -168,7 +167,7 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
@Override
|
||||
public long getMaxInMemoryINodes() throws Exception {
|
||||
String[] val = readProc("/proc/sys/fs/inode-max");
|
||||
|
||||
|
||||
if (val.length > 0)
|
||||
return Long.parseLong(val[0].trim());
|
||||
return -1;
|
||||
@@ -213,7 +212,7 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
public long getFreeMemoryGlobal() throws Exception {
|
||||
return sigar_manager.getMem().getFree();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getFreeMemoryJVM() {
|
||||
return Runtime.getRuntime().freeMemory();
|
||||
@@ -237,30 +236,30 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
public String toString() {
|
||||
StringBuffer result = new StringBuffer("");
|
||||
try {
|
||||
|
||||
|
||||
result.append("General:\n");
|
||||
result.append(getLastLoadAverage()).append(" (load avg)").append("\n");
|
||||
result.append(getTotalRunningProcesses()).append(" (total processes running)").append("\n");
|
||||
result.append(getTotalStoppedProcesses()).append(" (total processes stopped)").append("\n");
|
||||
result.append(getTotalZombieProcesses()).append(" (total processes zombie)").append("\n");
|
||||
result.append(getTotalProcesses()).append(" (total)").append("\n");
|
||||
|
||||
|
||||
result.append("\nMemory:\n");
|
||||
result.append(getFreeMemoryGlobal()/1000 + "kb (free, not cached, not inactive)\n");
|
||||
result.append(getFreeMemoryJVM()/1000 + "kb (free JVM)\n");
|
||||
result.append((getTotalMemoryJVM()-getFreeMemoryJVM())/1000 + "kb (used JVM)\n");
|
||||
result.append(getTotalMemoryJVM()/1000 + "kb (total JVM)\n");
|
||||
|
||||
result.append("\nOpen files:\n")
|
||||
|
||||
result.append("\nOpen files:\n")
|
||||
.append(getOpenFiles()).append(" / ").append(getUsedSockets()).append(" (normal / sockets)").append("\n")
|
||||
.append(getMaxOpenFiles()).append(" (max, also socket max)").append("\n")
|
||||
.append(getMaxInMemoryINodes()).append(" (max in-memory inodes)").append("\n");
|
||||
|
||||
result.append("\nNet:\n" + getTCPConnectionsInUse() + " (tcp conn in use)\n" + getAllocatedTCPConnections() + " (alloc'd tcp conn)\n" + getUsedSockets() + " (used sockets)").append("\n");
|
||||
|
||||
|
||||
result.append(getOutbundOpenConnectionCount()).append(" (outbound conn count)").append("\n")
|
||||
.append(getInboundOpenConnectionCount()).append(" (inbound conn count)").append("\n");
|
||||
|
||||
|
||||
int flags = NetFlags.CONN_TCP | NetFlags.CONN_UDP | NetFlags.CONN_SERVER;
|
||||
NetConnection[] connections = getOpenNetworkConnections(flags);
|
||||
|
||||
@@ -295,14 +294,14 @@ public class SystemInformationImpl implements SystemInformation {
|
||||
|
||||
result.append("\nContents of TMP directory (java.io.tmpdir)").append("\n");
|
||||
result.append(Arrays.toString(new File(System.getProperty("java.io.tmpdir")).listFiles()));
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.out.println(SystemInformationImpl.getInstance());
|
||||
|
||||
Reference in new issue
Block a user