Gathers metrics from the Ruby process it is executed in and sends them to an InfluxDB database.
Add this line to your application's Gemfile:
And then execute:
Or do all this at once:
$ bundle add influxdb-process
This library assumes that you already have a working InfluxDB client instance.
It does not attempt to create one for you.
If not, see InfluxDB Ruby for client initialization instructions.
Let's say you have the client in the
influxdb variable, as it says.
Add this to any place in your Ruby program:
When you deploy this, the process where this code is executed will create a new thread. It will periodically collect process metrics and send them to InfluxDB via the provided client.
Alternatively, you can instrument whenever you want (after each request / job / batch):
# in an initializer, once p = ::::.(influxdb) # later, in an appropriate place, as many times as needed p.instrument
You can pass additional options to customize the behavior of this gem. Here they are (with default values):
::::.( influxdb, memory_series: 'process_memory', object_series: 'process_objects', interval: 10, # seconds process: $PROGRAM_NAME )
Metrics will be tagged with process name.
$PROGRAM_NAME will be used.
You can set your own process name via an additional keyword argument in the constructor. For example:
::::.(influxdb, process: 'report_generator')
You can also set the
INFLUXDB_PROCESS_NAME environment variable:
INFLUXDB_PROCESS_NAME=cache_cleaner bundle exec ruby ...
It will take precedence over the keyword argument.
System memory metrics (total, resident, shared memory used by the process as seen from the OS) are read
/proc filesystem. They are not reported on systems where it is not available.
After checking out the repo, run
bin/setup to install dependencies.
You can also run
bin/console for an interactive prompt that will allow you to experiment.
How to test this gem:
- Install and run InfluxDB
- Create a
testdatabase in it
It will generate metrics and push them to the
To install this gem onto your local machine, run
bundle exec rake install.
To release a new version:
- Update the version number in
bundle exec rake release, which will do the following:
- create a git tag for the version
- push git commits and tags
- push the
.gemfile to rubygems.org
Bug reports and pull requests are welcome on GitHub at https://github.com/vassilevsky/influxdb-process
The gem is available as open source under the terms of the MIT License.