Ottomata has uploaded a new change for review.

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


Change subject: Adding support for tmax, dmax and sendMetadata.
......................................................................

Adding support for tmax, dmax and sendMetadata.

Also updating documentation.

Change-Id: Ie7df61914a242888f21b987e85139f11d7522a93
See: https://github.com/jmxtrans/jmxtrans/wiki/GangliaWriter
---
M README.md
M manifests/init.pp
M manifests/metrics.pp
M templates/jmxtrans.json.erb
4 files changed, 123 insertions(+), 61 deletions(-)


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

diff --git a/README.md b/README.md
index bb62790..a7786a9 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,41 @@
 [best practices](https://github.com/jmxtrans/jmxtrans/wiki/BestPractices)
 for more information.
 
-# Usage
+The ```objects``` parameter to jmxtrans::metrics is an array of hashes of the 
form:
+
+```puppet
+objects => [
+    {
+        'name'        => 'JMX.object.name',
+        'resultAlias' => 'pretty alias for JMX name', # optional
+        # attrs is a hash of JMX attributes under this JMX object
+        # with settings specific to this attribute.
+        # Most settings will only be relevant to specific output writers.
+        # Each available option is described here:
+        'attrs'       => {
+            'JMX.attribute.name' => {
+                # Ganglia Options.  See:
+                # 
https://github.com/jmxtrans/jmxtrans/wiki/GangliaWriter#example-configuration
+
+                # Slope must be one of ```both```, ```positive```, or 
```negative```.
+                # See 
http://codeblog.majakorpi.net/post/16281432462/ganglia-xml-slope-attribute
+                'slope'       => 'both|positive|negative',
+                'units'       => 'unit name',
+                'tmax'        => 'seconds value',
+                'dmax'        => 'seconds value',
+                'sendMetadata => 'seconds value',
+            }
+        }
+    }
+]
+```
+Notes:
+
+- Yes, the hash after attribute name could be empty.
+- No, we don't support replacing it with an array of names.
+
+# Usage Examples
+
 ## Hadoop NameNode with multiple jmxtrans outputs
 
 Query a Hadoop NameNode for some stats, and write the metrics to
@@ -34,14 +68,23 @@
     ganglia_group_name    => 'hadoop',
     graphite              => '127.0.0.1:2003',
     graphite_root_prefix  => 'hadoop',
-    queries => [
+    objects              => [
         {
-            'obj'    => 'Hadoop:service=NameNode,name=NameNodeActivity',
-            'attr'   => ['FileInfoOps', 'FilesCreated', 'FilesDeleted'],
+            'name'           =>  
'Hadoop:service=NameNode,name=NameNodeActivity',
+            'resultAlias'    => 'hadoop.namenode',
+            'attrs'          => {
+                'FileInfoOps'  => { 'units' => 'operations', 'slope' => 
'positive' },
+                'FilesCreated' => { 'units' => 'creations',  'slope' => 
'positive' },
+                'FilesDeleted' => { 'units' => 'deletions',  'slope' => 
'positive' },
+            }
         },
         {
-            'obj'    => 'Hadoop:service=NameNode,name=FSNamesystem',
-            'attr'   => ['BlockCapacity', 'BlocksTotal', 'TotalFiles'],
+            'name' => 'Hadoop:service=NameNode,name=FSNamesystem',
+            'attrs => {
+                'BlockCapacity' => { 'units' => 'blocks', 'slope' => 'both' },
+                'BlocksTotal'   => { 'units' => 'blocks', 'slope' => 'both' },
+                'TotalFiles'    => { 'units' => 'files',  'slope' => 'both' },
+            }
         },
     ],
 }
@@ -52,50 +95,62 @@
 ```puppet
 include jmxtrans
 
-# Since we have multiple hosts sharing the same queries,
-# we define a $jmx_kafka_queries variable to hold them.
-# This will be passed as the queries parameter to each Kafka host.
-$jmx_kafka_queries = [
+# Since we have multiple hosts sharing the same objects,
+# we define a $jmx_kafka_objects variable to hold them.
+# This will be passed as the objects parameter to each Kafka host.
+
+$jmx_kafka_objects = [
     {
-        'obj'    => 'kafka:type=kafka.BrokerAllTopicStat',
-        'attr'   => [ 'BytesIn', 'BytesOut', 'FailedFetchRequest', 
'FailedProduceRequest', 'MessagesIn' ]
+        'name'   => 'kafka:type=kafka.BrokerAllTopicStat',
+        'attrs   => {
+            'BytesIn'              => { 'units' => 'bytes',    'slope' => 
'positive' },
+            'BytesOut'             => { 'units' => 'bytes',    'slope' => 
'positive' },
+            'FailedFetchRequest'   => { 'units' => 'requests', 'slope' => 
'positive' },
+            'FailedProduceRequest' => { 'units' => 'requests', 'slope' => 
'positive' },
+            'MessagesIn'           => { 'units' => 'messages', 'slope' => 
'positive' },
+        }
     },
     {
-        'obj'    => 'kafka:type=kafka.LogFlushStats',
-        'attr'   => [ 'AvgFlushMs', 'FlushesPerSecond', 'MaxFlushMs', 
'NumFlushes', 'TotalFlushMs' ]
+        'name'   => 'kafka:type=kafka.LogFlushStats',
+        'attrs'  => {
+            'FlushesPerSecond' => { 'units' => 'flushes' }, # 'both' is 
ganglia default slope value. Leaving it off here.
+            'NumFlushes'       => { 'units' => 'flushes', slope => 'positive' 
},
+            'AvgFlushMs'       => { 'units' => 'ms' },  
+            'MaxFlushMs'       => { 'units' => 'ms' },
+            'TotalFlushMs'     => { 'units' => 'ms', 'slope' => 'positive' },
+        }
     },
     {
-        'obj'    => 'kafka:type=kafka.SocketServerStats',
-        'attr'   => [
-            'AvgFetchRequestMs',
-            'AvgProduceRequestMs',
-            'BytesReadPerSecond',
-            'BytesWrittenPerSecond',
-            'FetchRequestsPerSecond',
-            'MaxFetchRequestMs',
-            'MaxProduceRequestMs',
-            'NumFetchRequests',
-            'NumProduceRequests',
-            'ProduceRequestsPerSecond',
-            'TotalBytesRead',
-            'TotalBytesWritten',
-            'TotalFetchRequestMs',
-            'TotalProduceRequestMs'
-        ]
+        'name'   => 'kafka:type=kafka.SocketServerStats',
+        'attrs'  => {
+            'BytesReadPerSecond'       => { 'units' => 'bytes'},
+            'BytesWrittenPerSecond'    => { 'units' => 'bytes'},
+
+            'ProduceRequestsPerSecond' => { 'units' => 'requests'},
+            'AvgProduceRequestMs'      => { 'units' => 'requests'},
+            'MaxProduceRequestMs'      => { 'units' => 'requests'},
+            'TotalProduceRequestMs'    => { 'units' => 'ms' }
+
+            'FetchRequestsPerSecond'   => { 'units' => 'requests' },
+            'AvgFetchRequestMs'        => { 'units' => 'ms' },
+            'MaxFetchRequestMs'        => { 'units' => 'ms' },
+            'TotalFetchRequestMs'      => { 'units' => 'ms' },
+        }
     }
+
 ]
 
-# query kafka1 for its JMX metrics
+# query kafka1 broker for its JMX metrics
 jmxtrans::metrics { 'kafka1':
     jmx     => 'kafka1:9999',
     ganglia => '192.168.10.50:8469',
-    queries => $jmx_kafka_queries,
+    objects => $jmx_kafka_objects,
 }
 
-# query kafka2 for its JMX metrics
+# query kafka2 broker for its JMX metrics
 jmxtrans::metrics { 'kafka2':
     jmx     => 'kafka2:9999',
     ganglia => '192.168.10.50:8469',
-    queries => $jmx_kafka_queries,
+    objects => $jmx_kafka_objects,
 }
 ```
\ No newline at end of file
diff --git a/manifests/init.pp b/manifests/init.pp
index 9576bd4..bac97a9 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -3,13 +3,14 @@
 # The jmxtrans::metrics define includes this class, so you probably don't
 # need to use it directly.
 #
+# == Parameters
 class jmxtrans {
     package { 'jmxtrans':
-        ensure => 'installed',
+        ensure  => 'installed',
     }
     service { 'jmxtrans':
-        ensure => 'running',
-        enable => true,
+        ensure  => 'running',
+        enable  => true,
         require => Package['jmxtrans'],
     }
 }
diff --git a/manifests/metrics.pp b/manifests/metrics.pp
index 2e16660..9c57019 100644
--- a/manifests/metrics.pp
+++ b/manifests/metrics.pp
@@ -7,8 +7,8 @@
 # installs to monitor this machine.  See jmxtrans::metrics::jvm for an exmple.
 #
 # == Parameters
-# $jmx                  - host:port of JMX to query (required)
-# $objects              - array of hashes of the form:
+# $jmx                  - host:port of JMX to query.
+# $objects              - array of hashes of the following form.  See 
READEME.md for more info.
 #   [
 #       {
 #           "name"        => "JMX object name",
@@ -21,26 +21,16 @@
 #           }
 #       }
 #   ]
-# --resultAlias is optional
-# --units is only required for ganglia
-# ---Displayed with the graph to give context.  Nothing is worse than looking 
at
-# ---a graph and not knowing if something is in seconds, milliseconds, or
-# ---microseconds.
-# --slope is only required for ganglia and is 'both', 'positive', or 'negative'
-# ---See 
http://codeblog.majakorpi.net/post/16281432462/ganglia-xml-slope-attribute
-# ---for more information including the rrd-beginners link if the concept sitll
-# ---isn't clear.
-# --Yes, the hash after attribute name could be empty.
-# --No, we don't support replacing it with an array of names.
-# $jmx_alias            - Server alias name.  Optional.
+#
+# $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.
-# $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.
+# $ganglia              - host:port of Ganglia gmond.     Optional.
+# $ganglia_group_name   - Ganglia metrics group.          Optional.
+# $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.
+# $json_dir             - path to jmxtrans JSON config directory.  Default: 
/etc/jmxtrans.
 #
 define jmxtrans::metrics(
     $jmx,
@@ -52,12 +42,13 @@
     $ganglia_group_name   = undef,
     $graphite             = undef,
     $graphite_root_prefix = undef,
-    $outfile              = undef
+    $outfile              = undef,
+    $json_dir             = '/etc/jmxtrans',
 )
 {
     include jmxtrans
 
-    file { "/etc/jmxtrans/${title}.json":
+    file { "${json_dir}/${title}.json":
         content => template('jmxtrans/jmxtrans.json.erb'),
         notify  => Service['jmxtrans'],
         require => Package['jmxtrans'],
diff --git a/templates/jmxtrans.json.erb b/templates/jmxtrans.json.erb
index 48399b6..9a571e3 100644
--- a/templates/jmxtrans.json.erb
+++ b/templates/jmxtrans.json.erb
@@ -36,8 +36,23 @@
             , "settings":
               { "host": "<%= ganglia_host %>"
               , "port": <%= ganglia_port %>
-              , "units": "<%= object['attrs'][attr_name]['units'] %>"
+<%          if !object['attrs'][attr_name].empty? -%>
+<%             if object['attrs'][attr_name].has_key? 'slope' -%>
               , "slope": "<%= object['attrs'][attr_name]['slope'].upcase %>"
+<%             end -%>
+<%             if object['attrs'][attr_name].has_key? 'units' -%>
+              , "units": "<%= object['attrs'][attr_name]['units'] %>"
+<%             end -%>
+<%             if object['attrs'][attr_name].has_key? 'tmax' -%>
+              , "tmax": <%= object['attrs'][attr_name]['tmax'] %>
+<%             end -%>
+<%             if object['attrs'][attr_name].has_key? 'dmax' -%>
+              , "dmax": <%= object['attrs'][attr_name]['dmax'] %>
+<%             end -%>
+<%             if object['attrs'][attr_name].has_key? 'sendMetadata' -%>
+              , "sendMetadata": <%= object['attrs'][attr_name]['sendMetadata'] 
%>
+<%             end -%>
+<%          end # if !object['attrs'][attr_name].empty? -%>
 <%       if @ganglia_group_name -%>
               , "groupName": "<%= ganglia_group_name %>"
 <%       end -%>

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

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

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

Reply via email to