[jenkins-extras-memory-monitor/f19] Initial import

Michal Srb msrb at fedoraproject.org
Mon May 13 14:42:22 UTC 2013


commit 9e6bbc68bc0d0e45888102e9118ba225760167b0
Author: Michal Srb <msrb at redhat.com>
Date:   Mon May 13 16:41:55 2013 +0200

    Initial import

 .gitignore                                        |    2 +
 0001-Remove-support-for-windows-and-solaris.patch |  251 +++++++++++++++++++++
 jenkins-extras-memory-monitor.spec                |   60 +++++
 sources                                           |    2 +
 4 files changed, 315 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..0b47847 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/memory-monitor-1.7.tar.gz
+/LICENSE.txt
diff --git a/0001-Remove-support-for-windows-and-solaris.patch b/0001-Remove-support-for-windows-and-solaris.patch
new file mode 100644
index 0000000..aea1cf1
--- /dev/null
+++ b/0001-Remove-support-for-windows-and-solaris.patch
@@ -0,0 +1,251 @@
+From c4b472998a055c0bc8edea0a13086d0a9f4d4b49 Mon Sep 17 00:00:00 2001
+From: Michal Srb <msrb at redhat.com>
+Date: Tue, 16 Apr 2013 15:20:52 +0200
+Subject: [PATCH] Remove support for windows and solaris
+
+---
+ src/main/java/org/jvnet/hudson/MemoryMonitor.java |  11 --
+ src/main/java/org/jvnet/hudson/Solaris.java       | 128 ----------------------
+ src/main/java/org/jvnet/hudson/Windows.java       |  66 -----------
+ 3 files changed, 205 deletions(-)
+ delete mode 100644 src/main/java/org/jvnet/hudson/Solaris.java
+ delete mode 100644 src/main/java/org/jvnet/hudson/Windows.java
+
+diff --git a/src/main/java/org/jvnet/hudson/MemoryMonitor.java b/src/main/java/org/jvnet/hudson/MemoryMonitor.java
+index 4951925..2b44827 100644
+--- a/src/main/java/org/jvnet/hudson/MemoryMonitor.java
++++ b/src/main/java/org/jvnet/hudson/MemoryMonitor.java
+@@ -59,8 +59,6 @@ public abstract class MemoryMonitor {
+     }
+ 
+     private static MemoryMonitor obtain() throws IOException {
+-        if(File.pathSeparatorChar==';')
+-            return new Windows();
+ 
+         if(new File("/proc/meminfo").exists())
+             return new ProcMemInfo();   // Linux has this. Exactly since when, I don't know.
+@@ -74,15 +72,6 @@ public abstract class MemoryMonitor {
+             // fall through next
+         }
+ 
+-        // Solaris?
+-        try {
+-            Solaris solaris = new Solaris();
+-            solaris.monitor();
+-            return solaris;
+-        } catch(Throwable _) {
+-            // next
+-        }
+-
+         throw new IOException(String.format("No suitable implementation found: os.name=%s os.arch=%s sun.arch.data.model=%s",
+                 System.getProperty("os.name"),System.getProperty("os.arch"),System.getProperty("sun.arch.data.model")));
+     }
+diff --git a/src/main/java/org/jvnet/hudson/Solaris.java b/src/main/java/org/jvnet/hudson/Solaris.java
+deleted file mode 100644
+index 6e13062..0000000
+--- a/src/main/java/org/jvnet/hudson/Solaris.java
++++ /dev/null
+@@ -1,128 +0,0 @@
+-/*
+- * The MIT License
+- *
+- * Copyright (c) 2008-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi, 
+- *
+- * Permission is hereby granted, free of charge, to any person obtaining a copy
+- * of this software and associated documentation files (the "Software"), to deal
+- * in the Software without restriction, including without limitation the rights
+- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+- * copies of the Software, and to permit persons to whom the Software is
+- * furnished to do so, subject to the following conditions:
+- *
+- * The above copyright notice and this permission notice shall be included in
+- * all copies or substantial portions of the Software.
+- *
+- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+- * THE SOFTWARE.
+- */
+-package org.jvnet.hudson;
+-
+-import java.io.BufferedReader;
+-import java.io.IOException;
+-import java.io.InputStreamReader;
+-import java.util.regex.Matcher;
+-import java.util.regex.Pattern;
+-
+-/**
+- * For Solaris, where top(1) is an optional install. 
+- *
+- * @author Kohsuke Kawaguchi
+- */
+-public class Solaris extends AbstractMemoryMonitorImpl {
+-
+-    @Override
+-    public MemoryUsage monitor() throws IOException {
+-        long[] v = getSwap();
+-        return new MemoryUsage(
+-            getTotalPhysicalMemory(),
+-            getAvailablePhysicalMemory(),
+-            v[0],v[1] 
+-        );
+-    }
+-
+-    private long getTotalPhysicalMemory() throws IOException {
+-        Process proc = startProcess("/usr/sbin/prtdiag");
+-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+-        try {
+-            String line;
+-            while ((line=r.readLine())!=null) {
+-                if (line.contains("Memory size:")) {
+-                    line = line.substring(line.indexOf(':')+1).trim();
+-                    return parse(line);
+-                }
+-            }
+-            return -1;
+-        } finally {
+-            r.close();
+-        }
+-    }
+-
+-    private long getAvailablePhysicalMemory() throws IOException {
+-        Process proc = startProcess("vmstat");
+-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+-        try {
+-            String line;
+-            while ((line=r.readLine())!=null) {
+-                if (NUMBER_ONLY.matcher(line).matches()) {
+-                    return Long.parseLong(line.trim().split(" +")[4])*1024;
+-                }
+-            }
+-            return -1;
+-        } finally {
+-            r.close();
+-        }
+-    }
+-
+-    /**
+-     * Returns total/availablae.
+-     */
+-    private long[] getSwap() throws IOException {
+-        long[] v = new long[]{-1,-1};
+-        Process proc = startProcess("/usr/sbin/swap","-s");
+-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+-        /* output
+-
+-            $ uname -a; swap -s
+-            SunOS kohsuke2 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-2500 Solaris
+-            total: 800296k bytes allocated + 181784k reserved = 982080k used, 6014528k available
+-          */
+-        try {
+-            String line = r.readLine().toLowerCase();
+-
+-            Matcher m = USED_SWAP.matcher(line);
+-            if (m.find()) {
+-                v[0] = Long.parseLong(m.group(1))*1024;
+-            }
+-
+-            m = AVAILABLE_SWAP.matcher(line);
+-            if (m.find()) {
+-                v[1] = Long.parseLong(m.group(1))*1024;
+-            }
+-
+-            // we want total/available, not used/available.
+-            if (v[0]!=-1 && v[1]!=-1)
+-                v[0] += v[1];
+-            return v;
+-        } finally {
+-            r.close();
+-        }
+-    }
+-
+-    private Process startProcess(String... cmd) throws IOException {
+-        ProcessBuilder pb = new ProcessBuilder(cmd);
+-        pb.redirectErrorStream(true);
+-        Process proc = pb.start();
+-        proc.getOutputStream().close();
+-        return proc;
+-    }
+-
+-    private static final Pattern NUMBER_ONLY = Pattern.compile("[0-9 ]+");
+-    private static final Pattern USED_SWAP = Pattern.compile(" ([0-9]+)k used");
+-    private static final Pattern AVAILABLE_SWAP = Pattern.compile(" ([0-9]+)k available");
+-}
+diff --git a/src/main/java/org/jvnet/hudson/Windows.java b/src/main/java/org/jvnet/hudson/Windows.java
+deleted file mode 100644
+index d33ccbf..0000000
+--- a/src/main/java/org/jvnet/hudson/Windows.java
++++ /dev/null
+@@ -1,66 +0,0 @@
+-/*
+- * The MIT License
+- *
+- * Copyright (c) 2008-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi,
+- *
+- * Permission is hereby granted, free of charge, to any person obtaining a copy
+- * of this software and associated documentation files (the "Software"), to deal
+- * in the Software without restriction, including without limitation the rights
+- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+- * copies of the Software, and to permit persons to whom the Software is
+- * furnished to do so, subject to the following conditions:
+- *
+- * The above copyright notice and this permission notice shall be included in
+- * all copies or substantial portions of the Software.
+- *
+- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+- * THE SOFTWARE.
+- */
+-package org.jvnet.hudson;
+-
+-import com.sun.jna.Native;
+-import com.sun.jna.Structure;
+-import com.sun.jna.win32.StdCallLibrary;
+-
+-/**
+- * {@link MemoryMonitor} implementation for Windows.
+- *
+- * <p>
+- * JNA requires that the class and interface be public.
+- *
+- * @author Kohsuke Kawaguchi
+-*/
+-public final class Windows extends MemoryMonitor {
+-    public MemoryUsage monitor() {
+-        MEMORYSTATUSEX mse = new MEMORYSTATUSEX();
+-        Kernel32.INSTANCE.GlobalMemoryStatusEx(mse);
+-        mse.read();
+-
+-        return new MemoryUsage(
+-                mse.ullTotalPhys, mse.ullAvailPhys,
+-                mse.ullTotalPageFile, mse.ullAvailPageFile);
+-    }
+-
+-    public interface Kernel32 extends StdCallLibrary {
+-        boolean GlobalMemoryStatusEx(MEMORYSTATUSEX p);
+-
+-        Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32",Kernel32.class);
+-    }
+-
+-    public static final class MEMORYSTATUSEX extends Structure {
+-        public int dwLength = size();
+-        public int dwMemoryLoad;
+-        public long ullTotalPhys;
+-        public long ullAvailPhys;
+-        public long ullTotalPageFile;
+-        public long ullAvailPageFile;
+-        public long ullTotalVirtual;
+-        public long ullAvailVirtual;
+-        public long ullAvailExtendedVirtual;
+-    }
+-}
+-- 
+1.8.1.4
+
diff --git a/jenkins-extras-memory-monitor.spec b/jenkins-extras-memory-monitor.spec
new file mode 100644
index 0000000..6ce2398
--- /dev/null
+++ b/jenkins-extras-memory-monitor.spec
@@ -0,0 +1,60 @@
+%global shortname memory-monitor
+
+Name:           jenkins-extras-memory-monitor
+Version:        1.7
+Release:        1%{?dist}
+Summary:        Java library for monitoring memory/swap usage
+
+# License is specified in pom file
+License:        MIT
+URL:            https://github.com/jenkinsci/extras-memory-monitor
+Source0:        https://github.com/jenkinsci/extras-%{shortname}/archive/%{shortname}-%{version}.tar.gz
+# License text copied from http://jenkins-ci.org/mit-license
+Source1:        LICENSE.txt
+
+Patch0:         0001-Remove-support-for-windows-and-solaris.patch
+
+BuildRequires:  maven-local
+BuildRequires:  java-devel
+BuildRequires:  mvn(net.java.dev.jna:jna)
+
+BuildArch:      noarch
+
+%description
+This package contains a small Java library for monitoring
+memory/swap usage.
+
+%package        javadoc
+Summary:        Javadoc for %{name}
+
+%description javadoc
+This package contains the API documentation for Jenkins memory monitor.
+
+
+%prep
+%setup -q -n extras-%{shortname}-%{shortname}-%{version}
+
+cp %{SOURCE1} LICENSE
+
+# Nothing really interesting in parent
+%pom_remove_parent
+%pom_xpath_inject "pom:project" "<groupId>org.jenkins-ci</groupId>"
+
+%patch0 -p1
+
+%build
+# tests are failing because 'top' is unavailable (adding BR won't solve the problem)
+%mvn_build -f
+
+%install
+%mvn_install
+
+%files -f .mfiles
+%doc LICENSE
+%files javadoc -f .mfiles-javadoc
+%doc LICENSE
+
+%changelog
+* Fri May 10 2013 Michal Srb <msrb at redhat.com> - 1.7-1
+- Initial package
+
diff --git a/sources b/sources
index e69de29..d0f9581 100644
--- a/sources
+++ b/sources
@@ -0,0 +1,2 @@
+4500fe59f653b3f887834cf847ed6dc3  memory-monitor-1.7.tar.gz
+ebb9535dcdd967d9bd5a580e704113fd  LICENSE.txt


More information about the scm-commits mailing list