Filippo Giunchedi has submitted this change and it was merged.

Change subject: jheapdump: gdb-based heap dump for JVM
......................................................................


jheapdump: gdb-based heap dump for JVM

create a java::tools class to include this tool since it might get used
elsewhere beside elasticsearch module

Change-Id: I7fc40ff5a0ebd29824f9dbf76bf3d989343ce515
---
M modules/elasticsearch/manifests/packages.pp
A modules/java/files/jheapdump
A modules/java/manifests/tools.pp
3 files changed, 96 insertions(+), 0 deletions(-)

Approvals:
  Filippo Giunchedi: Verified; Looks good to me, approved
  Manybubbles: Looks good to me, but someone else must approve



diff --git a/modules/elasticsearch/manifests/packages.pp 
b/modules/elasticsearch/manifests/packages.pp
index 4886476..98b0dab 100644
--- a/modules/elasticsearch/manifests/packages.pp
+++ b/modules/elasticsearch/manifests/packages.pp
@@ -3,6 +3,8 @@
 # Provisions Elasticsearch package and dependencies.
 #
 class elasticsearch::packages {
+    include ::java::tools
+
     if ! defined ( Package['openjdk-7-jdk'] ) {
         package { 'openjdk-7-jdk':
             ensure => 'present',
diff --git a/modules/java/files/jheapdump b/modules/java/files/jheapdump
new file mode 100644
index 0000000..acbfeae
--- /dev/null
+++ b/modules/java/files/jheapdump
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# 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 along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Copyright 2014 Filippo Giunchedi <fgiunch...@wikimedia.org>
+# Copyright 2014 Wikimedia Foundation
+
+set -e
+set -u
+
+pid=${1:-}
+path=${2:-}
+
+function usage_exit() {
+  echo "usage: $0 PID BASE_NAME"
+  echo "  capture a core from PID into BASE_NAME.core.PID"
+  echo "  and extract java heap dump into BASE_NAME.hprof.PID"
+  exit 1
+}
+
+if [ -z "$pid" -o -z "$path" ]; then
+  usage_exit
+fi
+
+jmap=${JMAP:-$(command -vp jmap)}
+gcore=${GCORE:-$(command -vp gcore)}
+java=${JAVA:-$(command -vp java)}
+
+if [ -z "$jmap" -o -z "$gcore" -o -z "$java" ]; then
+  echo "jmap or gcore or java not found"
+  usage_exit
+fi
+
+if [ -d "$path" ]; then
+  echo "BASE_NAME can't be a directory"
+  usage_exit
+fi
+
+core_path="${path}.core.${pid}"
+heap_path="${path}.hprof.${pid}"
+jmap_options="-dump:format=b,file=${heap_path}"
+# remove trailing ".${pid}"
+gcore_options="-o ${core_path%*.${pid}}"
+
+# XXX check disk space
+if [ ! -e "$core_path" ]; then
+  echo "dumping core from ${pid} into ${core_path}"
+  echo "WARNING: this file can get very big!"
+  echo "         make sure there is enough disk space available"
+  sudo ${gcore} ${gcore_options} ${pid}
+fi
+
+if [ ! -e "$heap_path" ]; then
+  echo "writing heap profile to ${heap_path}"
+  sudo ${jmap} ${jmap_options} "${java}" "${core_path}"
+fi
+
+echo "done."
+
+echo "NOTE: the core file at ${core_path}, if unused remove with:"
+echo "      sudo rm ${core_path}"
diff --git a/modules/java/manifests/tools.pp b/modules/java/manifests/tools.pp
new file mode 100644
index 0000000..61c6273
--- /dev/null
+++ b/modules/java/manifests/tools.pp
@@ -0,0 +1,21 @@
+# == Class: java::tools
+#
+# This class aims at providing convenience tools to be used on systems where
+# java (JRE or JDK) is installed.
+
+class java::tools {
+    if ! defined ( Package['gdb'] ) {
+        package { 'gdb':
+            ensure => present
+        }
+    }
+
+    # NOTE jmap is used, thus requiring a jdk to be installed
+    file { '/usr/local/bin/jheapdump':
+        ensure  => file,
+        owner   => root,
+        group   => root,
+        mode    => '0555',
+        source  => 'puppet:///modules/java/jheapdump',
+    }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/170996
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7fc40ff5a0ebd29824f9dbf76bf3d989343ce515
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Filippo Giunchedi <fgiunch...@wikimedia.org>
Gerrit-Reviewer: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Ottomata <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to