Version information
This version is compatible with:
- Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x
- Puppet >= 6.1.0 < 8.0.0
- , ,
Start using this module
Add this module to your Puppetfile:
mod 'dodevops-jmxtrans', '0.1.5'
Learn more about managing modules with a PuppetfileDocumentation
Table of Contents
- Overview
- Module Description - What the module does and why it is useful
- Usage - Configuration options and additional functionality
- Installing jmxtrans
- Managing the service
- Configuring servers and queries
- Development - Guide for contributing to the module
Overview
Configure jmxtrans for collecting and exporting JVM metrics data.
This module was adopted from PLoperations and was available as
ploperations/jmxtrans
before.
Module Description
This module can be used to install and manage the jmxtrans service, as well as configure how it connects to JVM processes, what data it pulls out, and where it sends the data it collects.
For more information on jmxtrans, see the source repo.
Requirements
This module is not dependent on any java puppet module, however without any java on the system, the startup of jmxtrans will fail. Please take care to have a working java installation on the server (recommended of course with the puppetlabs/java module) and the java binary in the PATH or at least a JAVA_HOME set. The jmxtrans startup script will try to detect the java via one of these ways.
Installing jmxtrans
If you have a repository configured on the system with a jmxtrans
package
available, you can install jmxtrans by setting the package_name
parameter on
the main jmxtrans
class.
class { '::jmxtrans':
package_name => 'jmxtrans',
}
If you have a package available on the local filesystem or remotely over HTTP
(if your package manager supports it), you can set the package_source
parameter. Note that if you are on anything other than a Debian or EL-based
operating system, you will also need to set package_provider
.
class { '::jmxtrans':
package_name => 'jmxtrans',
package_source => 'http://central.maven.org/maven2/org/jmxtrans/jmxtrans/254/jmxtrans-254.rpm',
}
Managing the service
If you want to manage the service, you can set the service_name
parameter,
which will set ensure => running
on the service.
class { '::jmxtrans':
package_name => 'jmxtrans',
service_name => 'jmxtrans',
}
Configuring servers and queries
The jmxtrans::query
defined type is used to configure "servers" and "queries"
as described in the jmxtrans documentation.
Example usage:
jmxtrans::query { 'puppetserver':
host => 'localhost',
port => 1099,
queries => [
{
object => "metrics:name=puppetlabs.${facts['hostname']}.compiler.compile",
attributes => ['Max', 'Min', 'Mean', 'StdDev', 'Count'],
result_alias => 'puppetlabs.puppetmaster.compiler.compile',
writers => [
{
'@class' => 'com.googlecode.jmxtrans.model.output.KeyOutWriter',
outputFile => '/tmp/puppetserver-compile-metrics.txt',
maxLogFileSize => '10MB',
maxLogBackupFiles => '200',
debug => true,
},
],
},
{
object => "metrics:name=puppetlabs.${facts['hostname']}.jruby.num-free-jrubies",
attributes => ['Value'],
result_alias => 'puppetlabs.puppetmaster.jruby.num-free-jrubies',
writers => [
{
'@class' => 'com.googlecode.jmxtrans.model.output.KeyOutWriter',
outputFile => '/tmp/puppetserver-jruby-metrics.txt',
maxLogFileSize => '10MB',
maxLogBackupFiles => '200',
debug => true,
},
],
},
],
}
This will configure jmxtrans to connect to a JMX RMI on localhost
listening
on port 1099, and it will:
- extract the values for
Max
,Min
,Mean
,StdDev
, andCount
from themetrics:name=puppetlabs.${facts['hostname']}.compiler.compile
object and write them to/tmp/puppetserver-compile-metrics.txt
. - extract the value of the
Value
attribute for the objectmetrics:name=puppetlabs.${facts['hostname']}.jruby.num-free-jrubies
and write it to/tmp/puppetserver-jruby-metrics.txt
.
If you intend to use the GraphiteWriter, StdoutWriter or GelfWriter on all the objects for the server, there are top level parameters that you can set which will be inherited by all the query objects.
Development
Pull Requests on GitHub are welcome. Please include tests for any new features or functionality change. See rspec-puppet for details on writing unit tests for Puppet.
Always keep the reference up to date by running
bundle exec puppet strings generate --format markdown
Reference
Table of Contents
Classes
jmxtrans
: This is the main class for using jmxtrans. It should be included before using anything else from the module.jmxtrans::config
: This class is used to configure the jmxtrans config filesjmxtrans::install
: This class is used to install the jmxtrans package. If$::jmxtrans::package_name
is undef, then this class will do nothing. If `$::jmxtransjmxtrans::service
: This class manages the jmxtrans service. If$::jmxtrans::service_name
is undef, this class does nothing.
Defined types
jmxtrans::query
: This defined type is used to add a JSON configuration for jmxtrans to pull metrics for a given JVM process and write them out. It can automat
Functions
jmxtrans::merge_notundef
: This function will merge a list of hashes, ignoring key => value pairs in the the latter which have a value ofundef
jmxtrans::to_json
: Stringify data into the JSON format
Classes
jmxtrans
This is the main class for using jmxtrans. It should be included before using anything else from the module.
Examples
jmxtrans is installed via some other method
include jmxtrans
jmxtrans is available in a repository via the package jmxtrans
class { 'jmxtrans':
package_name => 'jmxtrans',
service_name => 'jmxtrans',
}
jmxtrans should be installed via rpm installing a remote package
class { 'jmxtrans':
package_name => 'jmxtrans',
service_name => 'jmxtrans',
package_source => 'http://central.maven.org/maven2/org/jmxtrans/jmxtrans/254/jmxtrans-254.rpm',
}
jmxtrans runs under a different user with a different config path
class { 'jmxtrans':
config_directory => '/etc/jmxtrans/config/',
user => 'java',
}
Parameters
The following parameters are available in the jmxtrans
class:
package_name
service_name
package_source
package_provider
working_directory
systemd_environment_file
manage_service_file
package_version
systemd_template
binary_path
config_directory
user
package_name
Data type: Optional[String[1]]
The package to install. Skips managing the package if undef.
Default value: undef
service_name
Data type: Optional[String[1]]
The service to manage. Skips managing the service if undef.
Default value: undef
package_source
Data type: Optional[String[1]]
A URL or local path to get a package from.
Default value: undef
package_provider
Data type: Optional[String[1]]
Used to explicitly set the provider to use to install the package.
Default value: undef
working_directory
Data type: Optional[String[1]]
Sets the working directory for the jmxtrans processes.
Default value: undef
systemd_environment_file
Data type: Optional[String[1]]
Path to the file where the environment variables needed by the jmxtrans service should be defined (e.g. '/etc/default/jmxtrans' or '/etc/sysconfig/jmxtrans').
Default value: undef
manage_service_file
Data type: Boolean
Manage the service definition file (systemd/init) for the JMXtrans-Service
Default value: false
package_version
Data type: String[1]
The version of the package to be installed. Defaults to 'present'.
Default value: present
systemd_template
Data type: String[1]
Template to be be used to generate the systemd unit. Defaults to 'jmxtrans/jmxtrans.service.pp'
Default value: 'jmxtrans/jmxtrans.service.epp'
binary_path
Data type: String[1]
Path to the jmxtrans executable. Defaults to '/usr/share/jmxtrans/bin/jmxtrans'.
Default value: '/usr/share/jmxtrans/bin/jmxtrans'
config_directory
Data type: String[1]
Where to place JSON configurations. Defaults to '/var/lib/jmxtrans'.
Default value: '/var/lib/jmxtrans'
user
Data type: String[1]
The user who will own the JSON configurations. Defaults to 'jmxtrans'.
Default value: 'jmxtrans'
jmxtrans::config
This class is used to configure the jmxtrans config files
jmxtrans::install
This class is used to install the jmxtrans package. If
$::jmxtrans::package_name
is undef, then this class will do nothing. If
$::jmxtrans::package_source
is set, the package will be installed from the
location specified.
This class will use the default provider for a platform if an explicit
value is not set for $::jmxtrans::package_source
. If a value is set for
that parameter, this class will use the rpm
provider on RedHat systems and
the dpkg
provider on Debian systems. This can be overridden by specifying a
value for the $::jmxtrans::package_provider
parameter.
jmxtrans::service
This class manages the jmxtrans service. If $::jmxtrans::service_name
is
undef, this class does nothing.
Defined types
jmxtrans::query
This defined type is used to add a JSON configuration for jmxtrans to pull metrics for a given JVM process and write them out. It can automatically configure the GraphiteWriter, or you can pass explicit configuration for any other jmxtrans-supported writer.
Parameters
The following parameters are available in the jmxtrans::query
defined type:
title
The resource title is used for the server alias
.
ensure
Data type: Enum['present', 'absent']
Whether the configuration should exist or not.
Default value: 'present'
host
Data type: String[1]
The host to connect to JMX on. Defaults to $title
.
Default value: $title
port
Data type: Optional[Integer[1]]
The port to connect to JMX on.
Default value: undef
username
Data type: Optional[String[1]]
The username to use to connect to JMX.
Default value: undef
password
Data type: Optional[String[1]]
The password to use to connect to JMX.
Default value: undef
num_threads
Data type: Optional[Integer[1]]
How many queries to execute
concurrently. Defaults to undef
, which will execute the queries serially.
Default value: undef
stdout
Data type: Boolean
Set to true
to enable the StdoutWriter for each
query on this object, so you don't have to do it manually.
Default value: false
graphite
Data type: Optional[Struct[{ host => String[1], port => Integer[1], Optional[root] => String[1], Optional[boolean_as_number] => Boolean, }]]
The Graphite configuration. Passing a hash
with host
and port
will configure the GraphiteWriter for each query on
this object, so you don't have to do it manually. You may also set:
root
[String] to configure therootPrefix
boolean_as_number
[String] to configure thebooleanAsNumber
Default value: undef
gelf
Data type: Optional[Struct[{ host => String[1], port => Integer[1], Optional[additionalFields] => Hash, Optional[transport] => String, Optional[queueSize] => Integer, Optional[connectTimeout] => Integer, Optional[reconnectDelay] => Integer, Optional[tcpNoDelay] => Boolean, Optional[sendBufferSize] => Integer, Optional[tlsEnabled] => Boolean, Optional[tlsTrustCertChainFile] => String, Optional[tlsCertVerificationEnabled] => Boolean, Optional[tcpKeepAlive] => Boolean, Optional[maxInflightSends] => Integer, }]]
The GelfWriter configuration. Passing a hash with
host
and port
will configure the GelfWriter for each query on this object, so
you don't have to do it manually. You may also set additional parameters as documented
in the JMXTrans Wiki
Default value: undef
queries
Data type: Optional[Array[Struct[{ object => String[1], attributes => Array[String[1]], Optional[type_names] => Array[String[1]], Optional[result_alias] => String[1], Optional[writers] => Array[Hash], }]]]
An array of queries to configure on the object. These consist of hashes of the form:
{
'object' => 'net.sf.ehcache:typeCacheStatistics,*',
'attributes' => [ 'CacheHits', 'CacheMisses', 'ObjectCount' ],
'type_names' => ['name'],
'result_alias' => 'ehcache',
'writers' => [
{
'@class' => 'com.googlecode.jmxtrans.model.output.KeyOutWriter',
'outputFile' => '/tmp/keyout2.txt',
'maxLogFileSize' => '10MB',
'maxLogBackupFiles' => '200',
'debug' => true,
},
],
}
Default value: undef
Functions
jmxtrans::merge_notundef
Type: Puppet Language
This function will merge a list of hashes, ignoring key => value pairs in the
the latter which have a value of undef
jmxtrans::merge_notundef(Hash $original, Hash $to_merge)
This function will merge a list of hashes, ignoring key => value pairs in the
the latter which have a value of undef
Returns: Any
Merged list
original
Data type: Hash
The base hash. All key values from this will be included.
to_merge
Data type: Hash
A variable number of hashes to merge in. Each of these
will have its key => value pairs added to the original hash, except where
the value is undef
. Later values will override earlier values.
jmxtrans::to_json
Type: Ruby 4.x API
Stringify data into the JSON format
jmxtrans::to_json(Data $data)
Stringify data into the JSON format
Returns: Any
Generated JSON string
data
Data type: Data
Data to stringify
Change log
All notable changes to this project will be documented in this file. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
v0.1.5 (2021-07-29)
Added
v0.1.4 (2021-07-28)
Fixed
v0.1.3 (2021-06-10)
v0.1.2 (2021-06-10)
Added
- allow a URL source to be passed to dpkg #8 (suckatrash)
- Gelf writer #7 (dploeger)
- Systemd template parametrized #6 (mrodm)
- Remove preexec commands #5 (petems)
- Adds config class #1 (petems)
Fixed
- Updates so CI works #9 (genebean)
- Manage jmxtrans /var/run/ directory #4 (charlesdunbar)
v0.1.1 (2016-04-28)
v0.1.0 (2016-04-28)
* This Changelog was automatically generated by github_changelog_generator
Dependencies
- puppet/archive (>= 2.0.0 < 6.0.0)
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.