Minutely probes
Minutely probes are a mechanism to periodically send custom metrics to AppSignal. This is a system that is included in the AppSignal Ruby gem by default. At the start of every minute the minutely probes are triggered one by one to collect metrics and then snoozed until the next minute.
By default the AppSignal Ruby gem enables probes for libraries that are detected for your app.
Usage
The minutely probes allow the AppSignal Ruby gem to collect custom metrics by default for integrations and app-specific metrics by creating your own probe.
Multiple instances
Once activated, the minutely probes system runs on every instance of an app. This means that if a probe report metrics without some kind of differentiating tag, global metrics may be overwritten by instance-level metrics. For example, there's a probe that tracks how large the local background job queue is for an app. The queue database runs locally on the instance and queue sizes may vary wildly. Each instance of an app reports different metric values for the same metric and tags, overwriting the metric value every minute with those of the last reporting instance.
To remedy this, we suggest tagging your metrics with the hostname or something else unique for each instance. For example, the Sidekiq probe tags metrics with the Redis hostname by default.
Alternatively you can disable minutely probes for all but one instance, on which the minutely probes process is run. We suggest using the APPSIGNAL_ENABLE_MINUTELY_PROBES
environment variable to only enable it on the instance of your choosing.
Configuration
The minutely probes are configured using the enable_minutely_probes
config option.
Creating probes
If you want to track more custom metrics from your app than our the default probes that ship with our integrations, you can add your own probe(s).
An AppSignal minutely probe can be either of three things. Which of the three types to use for your class depends on the use case.
Lambda probe
The simplest probe type to register. If you have no dependencies for your probe this is the preferred method.
Class probe
A class probe is a lazy initialized probe. It will only be started if the minutely probes are started. It will be initialized at the start of the minutely probes thread and remain initialized for as long as your app is running.
This method is useful when you do not have enable_minutely_probes
enabled for every environment and don't want it to be initialized by default.
Initialized class probe
This method is most useful for overriding default probes. The AppSignal Ruby gem ships some probes for integrations by default. These default probes register probes as a class so they won't be initialized when overridden. When the probe default config does not fit your use case you can override a default probe with your own config.
Note that we do not register a class as a probe, but an instance of the class using .new
and pass along a config object, e.g. BackgroundJobLibraryProbe.new(<config>)
.
Registering probes
Probes can be registered with the register
method on the Appsignal::Probes
module.
This method accepts two arguments.
key
- This is the key/name of the probe. This will be used to identify the probe in case an error occurs while executing the probe (which will be logged to the appsignal.log file) and to override an existing probe.probe
- This is one of the supported probe types that should be called every minute to collect metrics.
Rails apps
We recommend registering your probes in a Rails initializer, like: config/initializers/my_probe.rb
.
Dependency requirements
Not always should a probe be added to the list of probes by default. Some dependency may be required for the probe to work properly. This dependency check is used in probes shipped in the gem, but can also be used in your own probes.
By adding a class method called dependencies_present?
, a check can be performed ahead of starting the probe whether not it should be started. This works on both class probes and initialized class probes. For the latter scenario there should be no call to said dependency in the initialize
method of the probe as it's already initialized.
Overriding default probes
AppSignal ships with default probes for certain integrations. If for any reason this probe does not function properly or requires some additional configuration for your use case, you can override the default probe by initializing the probe class with your own config.
Example overriding the Sidekiq probe.
(Note that you'll need to set the REDIS_URL
environment variable yourself.)
Overriding probes will log a debug message in the appsignal.log file which can help to detect if a probe is correctly overridden.
Unregister probes
To unregister previously registered probes, including the default probes, use the Appsignal::Probes.unregister
method. Call the unregister method with the name of the probe to unregister it.