3.4 KiB
3.4 KiB
Classes
Typedefs
TX2
Kind: global class
TX2.action(action_name, [opts], fn)
Expose an action/function triggerable via PM2 or PM2.io
Kind: static method of TX2
Param | Type | Description |
---|---|---|
action_name | string |
Name of the action |
[opts] | object |
Optional parameter |
fn | function |
Function to be called |
Example (Action without arguments)
tx2.action('run_query', (cb) => {
cb({ success: true })
})
Example (Action with arguments)
tx2.action('run_query', arg1, (cb) => {
cb({ success: arg1 })
})
TX2.event(name, data)
Sends an Event
Kind: static method of TX2
Param | Type | Description |
---|---|---|
name | string |
Name of the event |
data | object |
Metadata attached to the event |
Example
tx2.event('event-name', { multi: 'data' })
TX2.issue(err)
Sends an Issue
Kind: static method of TX2
Param | Type | Description |
---|---|---|
err | string | Error |
Error object or string to notify |
Example
tx2.issue(new Error('bad error')
TX2.metric(name, [function]) ⇒ Metric
Expose a Metric
Kind: static method of TX2
Returns: Metric
- A metrics object
Param | Type | Description |
---|---|---|
name | string |
Name of the metric |
[function] | function |
Optional function to trigger every second to retrieve updated value |
Example
tx2.metric('metric_name', () => obj.value)
Example
tx2.metric('metric_name', 'unit', () => obj.value)
Example
let mn = tx2.metric('metric_name')
mn.set(20)
TX2.counter(name) ⇒ Counter
Expose a Metric of type: Counter. By calling .inc() or .dec() you update that value
Kind: static method of TX2
Param | Type | Description |
---|---|---|
name | string |
Name of the Metric |
Metric : Object
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
val | function |
Return the current value |
set | function |
Set value |
Counter : object
Expose a metric of type: Counter.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
inc | function |
Increment value |
dev | function |
Decrement value |