Showing with 34 additions and 19 deletions.
  1. +11 −1 CHANGELOG.md
  2. +11 −8 files/amq_metrics
  3. +10 −7 files/tk_metrics
  4. +1 −2 manifests/pe_metric.pp
  5. +1 −1 metadata.json
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Minor Release 4.2.0

## Improvements
- Allow not saving a metrics file
- Add a `--output-dir` CLI argument to metrics scripts which tells the script
where to save metrics output to.
- If `--output-dir` is not specified then no file is saved
- Metrics scripts print to STDOUT by default
- Use `--no-print` to silence output to STDOUT

# Minor Release 4.1.0

## Improvements
Expand All @@ -7,7 +17,7 @@
- This allows for integrations with other tools that can read the output from stdout.
- [PR #24](https://github.com/npwalker/pe_metric_curl_cron_jobs/pull/24)
- Move script configuration into a YAML file
- Allow the metrics scripts to be stored as static files instead of templates
- Allow the metrics scripts to be stored as static files instead of templates
- [PR #25](https://github.com/npwalker/pe_metric_curl_cron_jobs/pull/25)

# Major Release 4.0.0
Expand Down
19 changes: 11 additions & 8 deletions files/amq_metrics
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ require 'yaml'

options = {}
OptionParser.new do |opts|
opts.banner = "Usage: tk_metrics [options]"
opts.banner = "Usage: amq_metrics [options]"

opts.on('-p', '--print', 'Print to stdout') { |v| options[:print] = true }
opts.on('-p', '--[no-]print', 'Print to stdout') { |p| options[:print] = p }
opts.on('-m [TYPE]', '--metrics_type [TYPE]', 'Type of metric to collect') { |v| options[:metrics_type] = v }
opts.on('-o [DIR]', '--output-dir [DIR]', 'Directory to save output to') { |o| options[:output_dir] = o }
end.parse!

if options[:metrics_type].nil? then
Expand All @@ -23,7 +24,7 @@ end
METRICS_TYPE = options[:metrics_type]
config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)),"#{METRICS_TYPE}_config.yaml"))

OUTPUT_DIR = config['output_dir']
OUTPUT_DIR = options[:output_dir]
HOSTS = config['hosts']
PORT = config['metrics_port']
METRICS = config['additional_metrics']
Expand Down Expand Up @@ -99,13 +100,15 @@ HOSTS.each do |host|

json_dataset = JSON.pretty_generate(dataset)

Dir.chdir(OUTPUT_DIR) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
unless OUTPUT_DIR.nil? then
Dir.chdir(OUTPUT_DIR) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
end
end
end
if options[:print] == true then
if options[:print] != false then
STDOUT.write(json_dataset)
end
rescue Exception => e
Expand Down
17 changes: 10 additions & 7 deletions files/tk_metrics
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ options = {}
OptionParser.new do |opts|
opts.banner = "Usage: tk_metrics [options]"

opts.on('-p', '--print', 'Print to stdout') { |v| options[:print] = true }
opts.on('-p', '--[no-]print', 'Print to stdout') { |p| options[:print] = p }
opts.on('-m [TYPE]', '--metrics_type [TYPE]', 'Type of metric to collect') { |v| options[:metrics_type] = v }
opts.on('-o [DIR]', '--output-dir [DIR]', 'Directory to save output to') { |o| options[:output_dir] = o }
end.parse!

if options[:metrics_type].nil? then
Expand All @@ -23,7 +24,7 @@ end
METRICS_TYPE = options[:metrics_type]
config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)),"#{METRICS_TYPE}_config.yaml"))

OUTPUT_DIR = config['output_dir']
OUTPUT_DIR = options[:output_dir]
HOSTS = config['hosts']
PORT = config['metrics_port']
METRICS = config['additional_metrics']
Expand Down Expand Up @@ -103,13 +104,15 @@ HOSTS.each do |host|

json_dataset = JSON.pretty_generate(dataset)

Dir.chdir(OUTPUT_DIR) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
unless OUTPUT_DIR.nil? then
Dir.chdir(OUTPUT_DIR) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
end
end
end
if options[:print] == true then
if options[:print] != false then
STDOUT.write(json_dataset)
end
end
Expand Down
3 changes: 1 addition & 2 deletions manifests/pe_metric.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
}

$config_hash = {
'output_dir' => $metrics_output_dir,
'hosts' => $hosts,
'metrics_type' => $metrics_type,
'metrics_port' => $metrics_port,
Expand All @@ -39,7 +38,7 @@

cron { "${metrics_type}_metrics_collection" :
ensure => $metric_ensure,
command => "${script_file_name} --metrics_type ${metrics_type}",
command => "${script_file_name} --metrics_type ${metrics_type} --output-dir ${metrics_output_dir} --no-print",
user => 'root',
minute => $cron_minute,
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npwalker/pe_metric_curl_cron_jobs",
"version": "4.1.0",
"version": "4.2.0",
"author": "npwalker",
"summary": "A Puppet module for gathering metrics from PE components",
"license": "Apache-2.0",
Expand Down