Revision: dd2e3d9cc209
Author: Jean Deruelle <[email protected]>
Date: Fri Feb 1 03:31:46 2013
Log: Fixes Issue 14
http://code.google.com/p/commscale/source/detail?r=dd2e3d9cc209&repo=commons
Added:
/congestion/src/main/java/org/mobicents/commons/congestion/CPUCongestionMonitor.java
Modified:
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionListener.java
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionMonitor.java
/congestion/src/main/java/org/mobicents/commons/congestion/MemoryCongestionMonitor.java
/pom.xml
=======================================
--- /dev/null
+++
/congestion/src/main/java/org/mobicents/commons/congestion/CPUCongestionMonitor.java
Fri Feb 1 03:31:46 2013
@@ -0,0 +1,168 @@
+/*
+ * TeleStax, Open Source Cloud Communications.
+ * Copyright 2012 and individual contributors by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.commons.congestion;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+
+import javax.management.MBeanServerConnection;
+
+import javolution.util.FastList;
+
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author [email protected]
+ *
+ */
+public class CPUCongestionMonitor implements CongestionMonitor {
+ private static final Logger logger =
Logger.getLogger(CPUCongestionMonitor.class);
+
+ private static final String SOURCE = "CPU";
+
+ private final FastList<CongestionListener> listeners = new
FastList<CongestionListener>();
+
+ private OperatingSystemMXBean osMBean;
+ private volatile double percentageOfCPUUsed;
+
+ private volatile boolean cpuTooHigh = false;
+
+ private int backToNormalCPUThreshold;
+
+ private int cpuThreshold;
+
+ public CPUCongestionMonitor() {
+ MBeanServerConnection mbsc =
ManagementFactory.getPlatformMBeanServer();
+
+ try {
+ osMBean = ManagementFactory.newPlatformMXBeanProxy(
+ mbsc, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
OperatingSystemMXBean.class);
+ } catch (IOException e) {
+ logger.error("Couldn't get the java.lang:type=OperatingSystem MBean",
e);
+ }
+ }
+
+ /**
+ * @param backToNormalPercentageOfMemoryUsed
+ * the backToNormalPercentageOfMemoryUsed to set
+ */
+ public void setBackToNormalCPUThreshold(int backToNormalCPUThreshold) {
+ this.backToNormalCPUThreshold = backToNormalCPUThreshold;
+ if (logger.isInfoEnabled()) {
+ logger.info("Back To Normal CPU threshold set to " +
backToNormalCPUThreshold + "%");
+ }
+ }
+
+ /**
+ * @return the backToNormalPercentageOfCPUThreshold
+ */
+ public int getBackToNormalCPUThreshold() {
+ return backToNormalCPUThreshold;
+ }
+
+ /**
+ * @param cpuThreshold
+ * the cpuThreshold to set
+ */
+ public void setCPUThreshold(int cpuThreshold) {
+ this.cpuThreshold = cpuThreshold;
+ if (logger.isInfoEnabled()) {
+ logger.info("CPU threshold set to " + this.cpuThreshold +
"%");
+ }
+ }
+
+ /**
+ * @return the cpuThreshold
+ */
+ public int getCPUThreshold() {
+ return cpuThreshold;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.mobicents.commons.congestion.CongestionMonitor#monitor()
+ */
+ @Override
+ public void monitor() {
+ if(osMBean == null) {
+ return;
+ }
+
+ percentageOfCPUUsed = osMBean.getSystemLoadAverage();
+ if(logger.isTraceEnabled()) {
+ logger.trace("System Load Average = " +
percentageOfCPUUsed);
+ }
+ if (this.cpuTooHigh) {
+ if (this.percentageOfCPUUsed <
this.backToNormalCPUThreshold) {
+ logger.warn("Memory used: " + percentageOfCPUUsed + "% < to the back
to normal CPU threshold : " + this.backToNormalCPUThreshold);
+ this.cpuTooHigh = false;
+
+ // Lets notify the listeners
+ for (FastList.Node<CongestionListener> n = listeners.head(), end =
listeners.tail(); (n = n.getNext()) != end;) {
+ CongestionListener listener =
n.getValue();
+ listener.onCongestionFinish(SOURCE);
+ }
+ }
+ } else {
+ if (this.percentageOfCPUUsed > cpuThreshold) {
+ logger.warn("Memory used: " + percentageOfCPUUsed + "% > to the CPU
threshold : " + this.cpuThreshold);
+ this.cpuTooHigh = true;
+
+ // Lets notify the listeners
+ for (FastList.Node<CongestionListener> n = listeners.head(), end =
listeners.tail(); (n = n.getNext()) != end;) {
+ CongestionListener listener =
n.getValue();
+ listener.onCongestionStart(SOURCE);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.commons.congestion.CongestionMonitor#addCongestionListener(org.mobicents.commons.congestion.CongestionListener)
+ */
+ @Override
+ public void addCongestionListener(CongestionListener listener) {
+ this.listeners.add(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.commons.congestion.CongestionMonitor#removeCongestionListener(org.mobicents.commons.congestion.CongestionListener)
+ */
+ @Override
+ public void removeCongestionListener(CongestionListener listener) {
+ this.listeners.remove(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.mobicents.commons.congestion.CongestionMonitor#getSource()
+ */
+ @Override
+ public String getSource() {
+ return SOURCE;
+ }
+
+}
=======================================
---
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionListener.java
Thu Jan 31 08:56:44 2013
+++
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionListener.java
Fri Feb 1 03:31:46 2013
@@ -1,24 +1,23 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
- * contributors as indicated by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a full listing
- * of individual contributors.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License, v. 2.0.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License,
- * v. 2.0 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
+ * TeleStax, Open Source Cloud Communications.
+ * Copyright 2012 and individual contributors by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.mobicents.commons.congestion;
/**
=======================================
---
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionMonitor.java
Thu Jan 31 08:56:44 2013
+++
/congestion/src/main/java/org/mobicents/commons/congestion/CongestionMonitor.java
Fri Feb 1 03:31:46 2013
@@ -1,24 +1,23 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
- * contributors as indicated by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a full listing
- * of individual contributors.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License, v. 2.0.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License,
- * v. 2.0 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
+ * TeleStax, Open Source Cloud Communications.
+ * Copyright 2012 and individual contributors by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.mobicents.commons.congestion;
/**
=======================================
---
/congestion/src/main/java/org/mobicents/commons/congestion/MemoryCongestionMonitor.java
Thu Jan 31 08:56:44 2013
+++
/congestion/src/main/java/org/mobicents/commons/congestion/MemoryCongestionMonitor.java
Fri Feb 1 03:31:46 2013
@@ -1,24 +1,23 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
- * contributors as indicated by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a full listing
- * of individual contributors.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License, v. 2.0.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License,
- * v. 2.0 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
+ * TeleStax, Open Source Cloud Communications.
+ * Copyright 2012 and individual contributors by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.mobicents.commons.congestion;
import javolution.util.FastList;
@@ -87,8 +86,7 @@
/*
* (non-Javadoc)
- *
- * @see org.mobicents.ss7.congestion.CongestionMonitor#monitor()
+ * @see org.mobicents.commons.congestion.CongestionMonitor#monitor()
*/
@Override
public void monitor() {
@@ -129,10 +127,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.mobicents.ss7.congestion.CongestionMonitor#addCongestionListener(
- * org.mobicents.ss7.congestion.CongestionListener)
+ * @see
org.mobicents.commons.congestion.CongestionMonitor#addCongestionListener(org.mobicents.commons.congestion.CongestionListener)
*/
@Override
public void addCongestionListener(CongestionListener listener) {
@@ -141,10 +136,7 @@
/*
* (non-Javadoc)
- *
- * @see
- *
org.mobicents.ss7.congestion.CongestionMonitor#removeCongestionListener
- * (org.mobicents.ss7.congestion.CongestionListener)
+ * @see
org.mobicents.commons.congestion.CongestionMonitor#removeCongestionListener(org.mobicents.commons.congestion.CongestionListener)
*/
@Override
public void removeCongestionListener(CongestionListener listener) {
@@ -153,8 +145,7 @@
/*
* (non-Javadoc)
- *
- * @see org.mobicents.ss7.congestion.CongestionMonitor#getSource()
+ * @see org.mobicents.commons.congestion.CongestionMonitor#getSource()
*/
@Override
public String getSource() {
=======================================
--- /pom.xml Thu Jan 31 08:56:44 2013
+++ /pom.xml Fri Feb 1 03:31:46 2013
@@ -68,10 +68,7 @@
</scm>
<properties>
- <slf4j.version>1.5.5</slf4j.version>
- <log4j.version>1.2.16</log4j.version>
- <junit.version>4.8.2</junit.version>
- <javolution.version>5.5.1</javolution.version>
+ <junit.version>4.8.2</junit.version>
</properties>
<modules>
--
---
You received this message because you are subscribed to the Google Groups "mobicents-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.