Top Level Namespace
- Includes:
- Librato::Metrics
Defined Under Namespace
Modules: Librato
Instance Method Summary collapse
- #err(msg) ⇒ Object
- #get_beans(bean_name) ⇒ Object
- #load_yaml(filename) ⇒ Object
- #match_beans(opts) ⇒ Object
- #publish_beans(publisher, beans, opts) ⇒ Object
- #publish_loop(opts, publisher, interval, beans) ⇒ Object
Instance Method Details
#err(msg) ⇒ Object
8 9 10 11 |
# File 'bin/librato-metrics-tap-jmxbeans', line 8 def err(msg) $stderr.puts msg exit 1 end |
#get_beans(bean_name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'bin/librato-metrics-tap-jmxbeans', line 13 def get_beans(bean_name) beans = Taps::JMX::match_beans(bean_name) unless beans && beans.length > 0 err "No beans match: #{bean_name}" end beans end |
#load_yaml(filename) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'bin/librato-metrics-tap-jmxbeans', line 45 def load_yaml(filename) begin yaml_file= File.open(filename, "r") rescue => err puts "Failed to open yaml file #{filename}: #{err.}" exit 1 end begin yaml = YAML::load(yaml_file) rescue => err puts "Failed to parse yaml #{filename}: #{err.}" exit 1 end yaml_file.close return yaml end |
#match_beans(opts) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'bin/librato-metrics-tap-jmxbeans', line 21 def match_beans(opts) ret = Taps::JMX::connect!(opts[:jmx_host], opts[:jmx_port]) unless ret err "Failed to connect to JMX endpoint" end unless opts[:bean_name] err "Must specify --bean-name when matching bean names" end beans = get_beans(opts[:bean_name]) puts beans.join("\n") end |
#publish_beans(publisher, beans, opts) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'bin/librato-metrics-tap-jmxbeans', line 35 def publish_beans(publisher, beans, opts) (counters, gauges) = Taps::JMX::retrieve(beans, opts[:ignore_missing]) r = publisher.post(counters, gauges, opts) unless r $stderr.puts "ERROR: Failed to publish metrics!" end return r end |
#publish_loop(opts, publisher, interval, beans) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'bin/librato-metrics-tap-jmxbeans', line 63 def publish_loop(opts, publisher, interval, beans) # If --interval or --interval-file has been specified, # broadcast every interval seconds. We wait for # interval seconds each time to ensure we broadcast # on the interval # # We use a random stagger to ensure that we are measuring and # publishing our metrics at a random point within the period. This # ensures that multiple entities are not measuring and reporting # at the same exact points in time. stagger = rand(interval) begin t = Time.now.tv_sec # Floor the time to the current interval t2 = (t / interval) * interval # Offset by the stagger t2 += stagger # If our stagger is < interval/2, it is possible that we # went back in time. In that case, simply skip another interval # if t2 <= t t2 += interval end sleep (t2 - t) t = Time.now # We report our measure time as the nearest interval tsecs = ((t.tv_sec + (interval / 2)) / interval) * interval publish_beans(publisher, beans, opts.merge(:measure_time => tsecs)) end while true end |