lux-autohost
What is it?
lux-autohost provides two Action Creator API abstractions (for logging and metrics). These APIs provide developer-friendly (& expressive) methods that wrap the publishing of lux Action messages:
- Logging Action Creator API
error( data )
warn( data )
info( data )
debug( data )
- Metrics Action Creator API
meter( key, value [, unit, customData ] )
timer( key, value [, customData ] )
(timer units are in ms)
In addition to these methods, lux-autohost transparently adds metrics-capture for any lux Action executed in the client. In other words, lux-autohost automatically starts count and timer metrics for every action (so you don't have to worry about that), and it provides the Action Creator APIs in case you have other custom metrics/logging you need to capture.
Logging and metric payloads will be batched and transmitted at the interval you specify (see below).
Usage
Configuring the interval(s)
Below is an example of configuring the intervals at which logging & metrics will be transmitted to the autohost resource endpoints. In this example, metrics-related messages will be transmitted every 30 seconds, or every 500 messages (whichever is reached first), and logging-related messages will be transmitted every 5 seconds, or every 25 messages.
;
Configuring include/exclude
By default, lux-autohost will wire up metrics on every action. You may have actions that you don't care about monitoring (for example: an action that fires any time a text input updates as a user types). You can choose to add actions to an "exclude" list, OR you can switch lux-autohost into "include" mode, and only the actions specified will be monitored.
;
Using the Action Creator APIs
Logging
Here's an example of a React component pulling in the error
, warn
, info
and debug
Action Creator API calls that are provided for logging.
;
Metrics
Here's an example of a React component pulling in the meter
and timer
Action Creator API calls that are provided for metrics.
;
How Logging and Metrics Make it to autohost
The underlying batch manager in lux-autohost is an Action Listener for actions matching the method names provided by the logging and metrics Action Creator APIs (in other words, it listens for timer
, meter
, error
, warn
, info
and debug
action messages). Logging and metrics action messages are queued until the interval threshold has been reached, at which point lux-autohost will publish a sendLogBatch
or sendMetricsBatch
action message. Your API wrapper will need to handle sendLogBatch
and/or sendMetricsBatch
actions, transmitting them to your autohost endpoints however you prefer (we use halon to do this). For example, our API wrapper might look like this:
;