Presto::Metrics
Presto is a distributed SQL engine, which launches coordinator and worker servers to process distributed queries in a cluster. We need to monitor the states of these coordinators/workers. Presto::Metrics is a library for accessing these states from Ruby.
Presto provides REST API for accessing JMX properties. Presto::Metrics accesses this REST API to extract JMX property values.
Installation
Add this line to your application's Gemfile:
gem 'presto-metrics'
And then execute:
$ bundle
Or install it yourself as:
$ gem install presto-metrics
Usage
require 'presto/metrics'
client = Presto::Metrics::Client.new # Access to http://localhost:8080 in default
# Alternatively, you can specify the host name and port number to use
client = Presto::Metrics::Client.new(:host => "localhost", :port=>8080)
client.os_metrics
# => {:open_file_descriptor_count=>360, :max_file_descriptor_count=>10240, :committed_virtual_memory_size=>18683629568, :total_swap_space_size=>2147483648, :free_swap_space_size=>1132986368, :process_cpu_time=>240244441000, :free_physical_memory_size=>2088931328, :total_physical_memory_size=>17179869184, :system_cpu_load=>0.044989775051124746, :process_cpu_load=>0.002293214043176635, :name=>"Mac OS X", :version=>"10.9.4", :available_processors=>8, :arch=>"x86_64", :system_load_average=>2.0537109375, :object_name=>"java.lang:type=OperatingSystem"}
# This is equivalent to write as follows
client.get_metrics("java.lang:type=OperatingSystem")
# Retrieve a specific set of parameters
client.query_manager_metrics(["executor.active_count", "executor.completed_task_count"])
# => {:"executor.active_count"=>0, :"executor.completed_task_count"=>0}
client.os_metrics([:system_load_average, :free_physical_memory_size])
#=> {:free_physical_memory_size=>3690512384, :system_load_average=>2.33056640625}
# Path queries
client.path("os:physical_memory_size")
# => {"free_physical_memory_size"=>55034294272}
# You can use comma-separated list of path queries
client.path("memory:heap_memory_usage/used,non_heap_memory_usage/used")
# => {"heap_memory_usage/used"=>926714864, "non_heap_memory_usage/used"=>108948488}
# Retrieve standard metrics
client.memory_usage_metrics # java.lang:Type=Memory
client.os_metrics # java.lang:type=OperatingSystm
client.gc_cms_metrics # java.lang:type=GarbageCollector,name=ConcurrentMarkSweep
client.gc_parnew_metrics # java.lang:type=GarbageCollector,name=ParNew
client.query_manager_metrics # com.facebook.presto.execution:name=QueryManager
client.query_execution_metrics # com.facebook.presto.execution:name=QueryExecution
client.node_scheduler_metrics # com.facebook.presto.execution:name=NodeScheduler
client.task_executor_metrics # com.facebook.presto.execution:name=TaskExecutor
client.task_manager_metrics # com.facebook.presto.execution:name=TaskManager
# Retrieve the JSON representation of JMX properties
client.get_json("java.lang:Type=Memory")
# Pretty print
require 'pp'
pp c.memory_usage_metrics
#{
# "verbose": false,
# "object_pending_finalization_count": 0,
# "heap_memory_usage": {
# "committed": 259522560,
# "init": 268435456,
# "max": 14962655232,
# "used": 84478072
# },
# "non_heap_memory_usage": {
# "committed": 163250176,
# "init": 159842304,
# "max": 471859200,
# "used": 53369528
3 },
# "object_name": "java.lang:type=Memory"
#}
Contributing
- Fork it ( https://github.com/xerial/presto-metrics/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request