Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
via rubygems
gem install leafy-metrics
or add to your Gemfile
gem 'leafy-metrics'
installing the gem also takes care of the jar dependencies with jruby-1.7.16+
an instance of the registry Leafy::Metrics::Registry
can register various metrics like gauge, timer, meter, counter and histogram and remove them again.
registry = Leafy::Metrics::Registry.new
it can be other a given block or any object with a #call method returning the gauge - a number
registry.register_gauge( 'app.uptime') do
App.uptime
end
or with an object
class UptimeGauge
def call
App.uptime
enf
end
registry.register_gauge( 'app.uptime', UptimeGauge.new )
a timer can measure the time an block needs to execute:
timer = registry.register_timer( 'app.timer' )
timer.time do
App.update_data
end
a counter simply counts i.e. can be incremented or decremented
counter = registry.register_counter( 'active.users.counter' )
# one new user logged on
counter.inc
# three new users logged on
counter.inc 3
# one user logged off
counter.dec
# two users logged off
counter.dec 2
used = registry.register_meter( 'app.used' )
mark the occurrence of an event
used.mark
mark the occurrence of 'n' events
used.mark n
measures the distribution of values in a stream of data using an exponentially decaying reservoir
histogram = registry.register_histogram( 'search.results' )
histogram.update( Search.last_result.size )
registry.unregister( 'app.uptime )
currently there is not further introspection on the registry and its health-check. with the Leafy::Json::MetricsWriter
(from leafy-rack) you can get a json representation of the current metrics report
Leafy::Json::MetricsWriter.to_json( registry.metrics )
all reporters use a builder pattern. there are following timeunits for configuration:
Leafy::Metrics::Reporter::DAYS
Leafy::Metrics::Reporter::HOURS
Leafy::Metrics::Reporter::MINUTES
Leafy::Metrics::Reporter::SECONDS
Leafy::Metrics::Reporter::MILLISECONDS
Leafy::Metrics::Reporter::MICROSECONDS
Leafy::Metrics::Reporter::NANOSECONDS
in all examples below metrics = Leafy::Metrics::Registry.new
require 'leafy/metrics/console_reporter'
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter ).build
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
....
reporter.stop
or with all the possible configuration
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter )
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
.output_to( STDERR )
.build
or the config via a block
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter ) do
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
output_to( STDERR )
end.build
for each metric there will be a CSV file inside a given directory
require 'leafy/metrics/csv_reporter'
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter )
.build( 'metrics/directory' )
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
....
reporter.stop
or with all possible configuration
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter )
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
.build( 'metrics/directory' )
or configuration via block
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter ) do
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
end.build( 'metrics/directory' )
there are three targets where to send the data
Leafy::Metrics::Graphite.new_tcp( hostname, port )
Leafy::Metrics::Graphite.new_udp( hostname, port )
Leafy::Metrics::Graphite.new_pickled( hostname, port, batchsize )
the latter is collecting a few report event and sends them as batch. the sender
is one of the above targets.
require 'leafy/metrics/graphite_reporter'
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter )
.build_tcp( hostname, port )
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
....
reporter.stop
or with full configuration
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter )
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
.prefixed_with( 'myapp' )
.build( sender )
or with block configuration
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter ) do
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
prefixed_with( 'myapp' )
end.build_udp( host, port )
reporter = metrics.reporter_builder( com.readytalk.metrics.StatsDReporter ) do
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
end.build( host, port )
or using the Java module reference
reporter = metrics.reporter_builder( Java::ComReadytalkMetrics::StatsDReporter ) do
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
prefixed_with( 'app' )
end.build( host, port )
get all the gems and jars in place
gem install jar-dependencies --development
bundle install
for running all specs
rake
or
rspec spec/reporter_spec.rb
FAQs
Unknown package
We found that leafy-metrics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.