Manybubbles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71954


Change subject: Slick support for ganglia slope and units.
......................................................................

Slick support for ganglia slope and units.

Change-Id: I72c37cbdce61689cfdbe7895c00cb50f6ce62b0e
---
M manifests/init.pp
M manifests/metrics.pp
A manifests/metrics/jvm.pp
M templates/jmxtrans.json.erb
4 files changed, 158 insertions(+), 91 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet/jmxtrans 
refs/changes/54/71954/1

diff --git a/manifests/init.pp b/manifests/init.pp
index b2a3bb2..9576bd4 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -13,4 +13,3 @@
         require => Package['jmxtrans'],
     }
 }
-
diff --git a/manifests/metrics.pp b/manifests/metrics.pp
index 52fc7a2..03551cf 100644
--- a/manifests/metrics.pp
+++ b/manifests/metrics.pp
@@ -1,34 +1,48 @@
 # == Define jmxtrans::metrics
 #
-# Writes a jmxtrans JSON file in
-# /var/lib/jmxtrans/$title.json.
-# Each file in this directory should correspond to a single
-# JMX instance and specify the object and metric names to query
-# the JMX instance for.
+# Writes the config file causing this machine to monitor a set of metrics on a
+# host.  That file is named /etc/jmxtrans/$title.json.
+#
+# Suggestion: use these as external resources to force one or more jmxtrans
+# installs to monitor this machine.  See jmxtrans::metrics::jvm for an exmple.
 #
 # == Parameters
 # $jmx                  - host:port of JMX to query (required)
-# $queries              - array of hashes of the form [ { "obj" => "JMX object 
name", "attr" => [ "array", "of", "JMX", "metric", "names" ] }, ... ]
+# $objects              - array of hashes of the form:
+#   [
+#       {
+#           "name"        => "JMX object name",
+#           "resultAlias" => "pretty alias for JMX name",
+#           "attrs"       => [
+#               "attribute name" => {
+#                   "units" => "unit name",
+#                   "slope" => "slope type"
+#               }
+#           ]
+#       }
+#   ]
+#       resultAlias is optional
+#       units is only required for ganglia
+#       slope is only required for ganglia and is both, positive, or negative
+#       Yes, the hash after attribute name could be empty.
 # $jmx_alias            - Server alias name.  Optional.
 # $jmx_username         - JMX username (if there is one)  Optional.
 # $jmx_password         - JMX password (if there is one)  Optional.
 # $ganglia              - host:port of Ganglia gmond.  Optional.
 # $ganglia_group_name   - Ganglia metrics group.  Optional.
-# $ganglia_settings     - A hash of any extra ganglia output writer settings.
-#                         See: 
https://github.com/jmxtrans/jmxtrans/wiki/GangliaWriter.
 # $graphite             - host:port of Graphite server  Optional.
 # $graphite_root_prefix - rootPrefix for Graphite.  Optional.
-# $outfile              - local file path in which to save metric query 
results.  Optional.
+# $outfile              - local file path in which to save metric query 
results.
+#                           Optional.
 #
 define jmxtrans::metrics(
     $jmx,
-    $queries,
+    $objects,
     $jmx_alias            = undef,
     $jmx_username         = undef,
     $jmx_password         = undef,
     $ganglia              = undef,
     $ganglia_group_name   = undef,
-    $ganglia_settings     = undef,
     $graphite             = undef,
     $graphite_root_prefix = undef,
     $outfile              = undef
@@ -36,9 +50,9 @@
 {
     include jmxtrans
 
-    file { "/var/lib/jmxtrans/${title}.json":
+    file { "/etc/jmxtrans/${title}.json":
         content => template('jmxtrans/jmxtrans.json.erb'),
         notify  => Service['jmxtrans'],
         require => Package['jmxtrans'],
     }
-}
\ No newline at end of file
+}
diff --git a/manifests/metrics/jvm.pp b/manifests/metrics/jvm.pp
new file mode 100644
index 0000000..dc7d9a5
--- /dev/null
+++ b/manifests/metrics/jvm.pp
@@ -0,0 +1,75 @@
+# == Define jmxtrans::metrics::jvm
+#
+# Sets up this JVM to be monitored by a jmxtrans node.
+# Note that at present this only really does the right thing with the CMS
+# collector.
+#
+# == Parameters
+# $title          - host:port of JMX to query (required)
+define jmxtrans::metrics::jvm() {
+    @@jmxtrans::metrics { "${title}-jvm-metrics":
+        jmx                => "$title",
+        ganglia_group_name => 'jvm memory',
+        objects            => [
+            {
+                'name'        => 'java.lang:type=Memory',
+                'resultAlias' => 'Memory',
+                'attrs'       => {
+                    'HeapMemoryUsage'    => {'units' => 'bytes', 'slope' => 
'both'},
+                    'NonHeapMemoryUsage' => {'units' => 'bytes', 'slope' => 
'both'},
+                }
+            },
+            # Parallel GC
+            {
+                'name'        => 'java.lang:name=ParNew,type=PS Scavenge',
+                'resultAlias' => 'Incremental GC',
+                'attrs'       => {
+                    'CollectionCount' => {'units' => 'GCs', 'slope' => 'both'},
+                    'CollectionTime'  => {'units' => 'milliseconds', 'slope' 
=> 'positive'},
+                }
+            },
+            {
+                'name'        => 'java.lang:name=ConcurrentMarkSweep,type=PS 
MarkSweep',
+                'resultAlias' => 'Full GC',
+                'attrs'       => {
+                    'CollectionCount' => {'units' => 'GCs', 'slope' => 'both'},
+                    'CollectionTime'  => {'units' => 'milliseconds', 'slope' 
=> 'positive'},
+                }
+            },
+            # CMS GC
+            {
+                'name'        => 'java.lang:name=ParNew,type=GarbageCollector',
+                'resultAlias' => 'Incremental GC',
+                'attrs'       => {
+                    'CollectionCount' => {'units' => 'GCs', 'slope' => 'both'},
+                    'CollectionTime'  => {'units' => 'milliseconds', 'slope' 
=> 'positive'},
+                }
+            },
+            {
+                'name'        => 
'java.lang:name=ConcurrentMarkSweep,type=GarbageCollector',
+                'resultAlias' => 'Full GC',
+                'attrs'       => {
+                    'CollectionCount' => {'units' => 'GCs', 'slope' => 'both'},
+                    'CollectionTime'  => {'units' => 'milliseconds', 'slope' 
=> 'positive'},
+                }
+            },
+            # These only show up for Java 7
+            {
+                'name'        => 'java.nio:name=mapped,type=BufferPool',
+                'resultAlias' => 'Mapped Buffer Pool',
+                'attrs'       => {
+                    'MemoryUsed' => {'units' => 'bytes', 'slope' => 'both'},
+                    'Count'      => {'units' => 'buffers', 'slope' => 'both'},
+                }
+            },
+            {
+                'name'        => 'java.nio:name=direct,type=BufferPool',
+                'resultAlias' => 'Direct Buffer Pool',
+                'attrs'       => {
+                    'MemoryUsed' => {'units' => 'bytes', 'slope' => 'both'},
+                    'Count'      => {'units' => 'buffers', 'slope' => 'both'},
+                }
+            }
+        ]
+    }
+}
diff --git a/templates/jmxtrans.json.erb b/templates/jmxtrans.json.erb
index 2123905..48399b6 100644
--- a/templates/jmxtrans.json.erb
+++ b/templates/jmxtrans.json.erb
@@ -1,87 +1,66 @@
-<%
+<% (jmx_host, jmx_port) = jmx.split(':') -%>
 
-(jmx_host, jmx_port) = jmx.split(':')
-
-# Build output writer json strings
-# from the outfile, ganglia, and/or
-# graphite variables.
-
-output_writers = []
-
-if @outfile
-  output_writers.push("{
-        \"@class\" : \"com.googlecode.jmxtrans.model.output.KeyOutWriter\",
-        \"settings\" : {
-          \"outputFile\" : \"#{outfile}\"
-        }
-      }")
-end
-
-if @ganglia
-  (ganglia_host, ganglia_port) = ganglia.split(':') if @ganglia
-
-  ganglia_output_writer = "{
-        \"@class\" : \"com.googlecode.jmxtrans.model.output.GangliaWriter\",
-        \"settings\"  : {
-          \"host\"      : \"#{ganglia_host}\",
-          \"port\"      : #{ganglia_port}"
-  ganglia_output_writer += ",\n          \"groupName\" : 
\"#{ganglia_group_name}\"" if @ganglia_group_name
-  # render any extra ganglia settings
-  if (@ganglia_settings)
-    @ganglia_settings.each_pair do |key, value|
-      ganglia_output_writer += ",\n          \"#{key}\" : \"#{value}\""
-    end
-  end
-  ganglia_output_writer += "\n        }\n      }"
-  output_writers.push(ganglia_output_writer)
-end
-
-if @graphite
-  (graphite_host, graphite_port) = graphite.split(':')
-  graphite_output_writer = "{
-        \"@class\" : \"com.googlecode.jmxtrans.model.output.GraphiteWriter\",
-        \"settings\"   : {
-          \"host\"       : \"#{graphite_host}\",
-          \"port\"       : #{graphite_port}"
-  graphite_output_writer += ",\n          \"rootPrefix\" : 
\"#{graphite_root_prefix}\"" if @graphite_root_prefix
-  graphite_output_writer += "\n        }\n      }"
-  output_writers.push(graphite_output_writer)
-end
-
-# Output the JSON string.
--%>
-
-{ "servers" : [ {
-
-  "host"  : "<%= jmx_host %>",
-  "port"  : <%= jmx_port %>,
+{ "servers":
+  [ { "host": "<%= jmx_host %>"
+    , "port": <%= jmx_port %>
 <% if @jmx_alias -%>
-  "alias" : "<%= @jmx_alias %>",
+    , "alias": "<%= @jmx_alias %>"
 <% end -%>
 <% if @jmx_username -%>
-  "username" : "<%= @jmx_username %>",
+    , "username": "<%= @jmx_username %>"
 <% end -%>
 <% if @jmx_password -%>
-  "password" : "<%= @jmx_password %>",
+    , "password": "<%= @jmx_password %>"
 <% end -%>
-  "queries" :
-  [
-<% # loop over each query and output it with each configured output_writer -%>
-<% queries.each_with_index do |query, index| -%>
-<% unless index == 0 -%>
-    ,
-<% end -%>
-    {
-      "obj"  : "<%= query["obj"] %>",
-      "attr" : [ <%= query['attr'].map {|t| "\""+t.to_s+"\""}.join(', ') %> ],
-<% if query.has_key? "resultAlias" -%>
-      "resultAlias" : "<%= query["resultAlias"] %>",
-<% end -%>
-      "outputWriters" : [
-      <%= output_writers.join(",\n      ") %>
+    , "queries":
+      [
+<% # each attr gets it own obj chunk because it could have a different slope 
and unit. -%>
+<% @objects.each_with_index do |object, obj_index| -%>
+<%   object['attrs'].keys.sort.each_with_index do |attr_name, attr_index| -%>
+      <% if obj_index == 0 && attr_index == 0 -%>  <% else -%>, <% end -%>{ 
"obj": "<%= object["name"] %>"
+        , "attr": [ "<%= attr_name %>" ]
+<%     if object.has_key? "resultAlias" -%>
+        , "resultAlias": "<%= object["resultAlias"] %>"
+<%     end -%>
+        , "outputWriters":
+          [
+<%     if @outfile -%>
+            { "@class": "com.googlecode.jmxtrans.model.output.KeyOutWriter"
+            , "settings":
+              { "outputFile": "<%= @outfile %>" }
+            }
+<%     end -%>
+<%     if @ganglia -%>
+<%       (ganglia_host, ganglia_port) = @ganglia.split(':') -%>
+          <% if @outfile -%>, <% else -%>  <% end -%>{ "@class" : 
"com.googlecode.jmxtrans.model.output.GangliaWriter"
+            , "settings":
+              { "host": "<%= ganglia_host %>"
+              , "port": <%= ganglia_port %>
+              , "units": "<%= object['attrs'][attr_name]['units'] %>"
+              , "slope": "<%= object['attrs'][attr_name]['slope'].upcase %>"
+<%       if @ganglia_group_name -%>
+              , "groupName": "<%= ganglia_group_name %>"
+<%       end -%>
+              }
+            }
+<%     end -%>
+<%     if @graphite -%>
+<%       (graphite_host, graphite_port) = @graphite.split(':') -%>
+          <% if @outfile || @ganglia -%>, <% else -%>  <% end -%>{ "@class" : 
"com.googlecode.jmxtrans.model.output.GraphiteWriter"
+            , "settings":
+              { "host": "<%= graphite_host %>"
+              , "port": <%= graphite_port %>"
+<%       if @graphite_root_prefix -%>
+              , "rootPrefix": "<%= @graphite_root_prefix %>"
+<%       end -%>
+              }
+            }
+<%     end -%>
+          ]
+        }
+<%   end # object['attrs'].keys.sort.each_with_index -%>
+<% end # @objects.each_with_index -%>
       ]
     }
-<% end # queries.each_with_index -%>
   ]
-
-} ] }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I72c37cbdce61689cfdbe7895c00cb50f6ce62b0e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet/jmxtrans
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to