Merge pull request #7 from roidelapluie/fix5

Move to unique metrics names
This commit is contained in:
Tim Meusel 2016-10-23 15:52:55 +02:00 committed by GitHub
commit f0d0b4f96f
2 changed files with 67 additions and 47 deletions

View File

@ -51,38 +51,38 @@ node_exporter --collector.textfile.directory /var/lib/prometheus-dropzone
### Sample
```
puppet_report_resources{name="Changed",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Failed",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Failed to restart",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Out of sync",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Restarted",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Scheduled",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Skipped",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_resources{name="Total",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 519
puppet_report_time{name="Acl",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 4.305946465999999
puppet_report_time{name="Anchor",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.002099278
puppet_report_time{name="Augeas",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 10.624435211000002
puppet_report_time{name="Concat file",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.003198308
puppet_report_time{name="Concat fragment",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.011727518000000003
puppet_report_time{name="Config retrieval",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 21.957285313
puppet_report_time{name="Cron",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.000998661
puppet_report_time{name="Exec",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.3956716509999998
puppet_report_time{name="File",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.27236491600000007
puppet_report_time{name="File line",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.0013426360000000001
puppet_report_time{name="Filebucket",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.000321591
puppet_report_time{name="Grafana datasource",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.185209661
puppet_report_time{name="Group",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.002729905
puppet_report_time{name="Mysql datadir",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.000549758
puppet_report_time{name="Package",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 1.6033163289999999
puppet_report_time{name="Service",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.9613265080000001
puppet_report_time{name="Total",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 40.333134474999994
puppet_report_time{name="User",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.0037832459999999997
puppet_report_time{name="Yumrepo",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0.0008275190000000001
puppet_report_changes{name="Total",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_events{name="Failure",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_events{name="Success",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report_events{name="Total",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 0
puppet_report{host="node.example.com",kind="apply",version="9.2-329 (Built on Wed Oct 19 16:15:32 CEST 2016)",transaction_uuid="4f85dbb4-d575-4386-83e4-e71576df71e1",host="node.example.com"} 1477040517280
puppet_report_resources{name="Changed",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Failed",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Failed to restart",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Out of sync",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Restarted",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Scheduled",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Skipped",environment="production",host="node.example.com"} 0
puppet_report_resources{name="Total",environment="production",host="node.example.com"} 519
puppet_report_time{name="Acl",environment="production",host="node.example.com"} 3.8629975709999984
puppet_report_time{name="Anchor",environment="production",host="node.example.com"} 0.002442332
puppet_report_time{name="Augeas",environment="production",host="node.example.com"} 10.629003954
puppet_report_time{name="Concat file",environment="production",host="node.example.com"} 0.0026740609999999997
puppet_report_time{name="Concat fragment",environment="production",host="node.example.com"} 0.012010700000000003
puppet_report_time{name="Config retrieval",environment="production",host="node.example.com"} 20.471957786
puppet_report_time{name="Cron",environment="production",host="node.example.com"} 0.000874118
puppet_report_time{name="Exec",environment="production",host="node.example.com"} 0.4114313850000001
puppet_report_time{name="File",environment="production",host="node.example.com"} 0.32955574000000015
puppet_report_time{name="File line",environment="production",host="node.example.com"} 0.002702939
puppet_report_time{name="Filebucket",environment="production",host="node.example.com"} 0.0003994
puppet_report_time{name="Grafana datasource",environment="production",host="node.example.com"} 0.187452552
puppet_report_time{name="Group",environment="production",host="node.example.com"} 0.0031514940000000003
puppet_report_time{name="Mysql datadir",environment="production",host="node.example.com"} 0.000422795
puppet_report_time{name="Package",environment="production",host="node.example.com"} 1.670733222
puppet_report_time{name="Service",environment="production",host="node.example.com"} 0.8740041969999999
puppet_report_time{name="Total",environment="production",host="node.example.com"} 38.468031933999995
puppet_report_time{name="User",environment="production",host="node.example.com"} 0.005163427
puppet_report_time{name="Yumrepo",environment="production",host="node.example.com"} 0.0010542610000000001
puppet_report_changes{name="Total",environment="production",host="node.example.com"} 0
puppet_report_events{name="Failure",environment="production",host="node.example.com"} 0
puppet_report_events{name="Success",environment="production",host="node.example.com"} 0
puppet_report_events{name="Total",environment="production",host="node.example.com"} 0
puppet_report{environment="production",host="node.example.com"} 1477054915347
```
## Contributors

View File

@ -29,33 +29,53 @@ Puppet::Reports.register_report(:prometheus) do
end
def process
now = DateTime.now.new_offset(0)
if REPORT_FILENAME.nil?
name = host + '.prom'
file = File.join(TEXTFILE_DIRECTORY, name)
namevar = self.host
else
file = File.join(TEXTFILE_DIRECTORY, REPORT_FILENAME)
namevar = REPORT_FILENAME
end
yaml_filename = File.join(TEXTFILE_DIRECTORY, '.' + namevar + '.yaml')
filename = File.join(TEXTFILE_DIRECTORY, namevar + '.prom')
common_values = {
transaction_uuid: self.transaction_uuid,
environment: self.environment,
host: self.host,
}.reduce('') {
|values, extra| values + ",#{extra[0].to_s}=\"#{extra[1].to_s}\""
}.reduce([]) {
|values, extra| values + Array("#{extra[0].to_s}=\"#{extra[1].to_s}\"")
}
epochtime = now.strftime('%Q')
File.open(file, 'w') do |file|
unless metrics.empty? or metrics['events'].nil?
metrics.each do |metric, data|
data.values.each do |val|
file.write("puppet_report_#{metric}{name=\"#{val[1]}\"#{common_values}} #{val[2]}\n")
new_metrics = Hash.new
unless metrics.empty? or metrics['events'].nil?
metrics.each do |metric, data|
data.values.each do |val|
new_metrics["puppet_report_#{metric}{name=\"#{val[1]}\",#{common_values.join(',')}}"] = val[2]
end
end
end
epochtime = DateTime.now.new_offset(0).strftime('%Q')
new_metrics["puppet_report{#{common_values.join(',')}}"] = epochtime
File.open(filename, 'w') do |file|
if File.exist?(yaml_filename)
file.write("# Old metrics\n")
existing_metrics = YAML.load_file(yaml_filename)
existing_metrics.each do |k, _v|
unless new_metrics.include?(k)
file.write("#{k} -1\n")
end
end
end
file.write("puppet_report{host=\"#{host}\",kind=\"#{kind}\",version=\"#{configuration_version}\"#{common_values}} #{epochtime}\n")
file.write("# New metrics\n")
new_metrics.each do |k, v|
file.write("#{k} #{v}\n")
end
end
File.open(yaml_filename, 'w') do |yaml_file|
yaml_file.write new_metrics.to_yaml
end
end
end