Plugin API
What a plugin class implements, and the config, store, and metrics
handed to its constructor.
OmeggaPlugin
An omegga plugin
| Property | Type | Description |
|---|---|---|
omegga | OmeggaLike | |
config | PluginConfig<Config> | |
store | PluginStore<Storage> | |
metrics? | PluginMetrics | Prometheus metrics for this plugin; no-ops when metrics are disabled. Always supplied by the plugin loader. It is declared optional purely so that plugins written before metrics existed still satisfy implements OmeggaPlugin. Declare metrics: PM on your own class, as the templates do for omegga, config, and store, to get the non-optional type. |
init
init(): Promise<void | { registeredCommands?: string[] }>
Run when plugin starts, returns /commands it uses
stop
stop(): Promise<void>
Run when plugin is stopped
pluginEvent
pluginEvent?(event: string, from: string, ...args: any[]): Promise<unknown>
Run when another plugin tries to interact with this plugin
| Param | Type | Description |
|---|---|---|
event | string | Event name |
from | string | Name of origin plugin |
...args | any[] |
Returns value other plugin expects
Declared in src/plugin.ts.
PluginStore
A simple document store for plugins
get
get<T extends keyof Storage>(key: T): Promise<Storage[T]>
Get a value from plugin storage
set
set<T extends keyof Storage>(key: T, value: Storage[T]): Promise<void>
Set a value to plugin storage
delete
delete(key: string): Promise<void>
Delete a value from plugin storage
wipe
wipe(): Promise<void>
Wipe all values in plugin storage
count
count(): Promise<number>
Count entries in plugin storage
keys
keys(): Promise<(keyof Storage)[]>
Get a list of keys in plugin storage
Declared in src/plugin.ts.
PluginConfig
A config representative of the config outlined in doc.json
type PluginConfig<T extends Record<string, unknown> = Record<string, unknown>> = T
Declared in src/plugin.ts.
PluginMetrics
Prometheus metrics for a plugin, exported under omegga_plugin_<plugin>_.
Handles are always returned, so no guards are needed: when the metrics endpoint is disabled every call is a no-op.
| Property | Type | Description |
|---|---|---|
enabled | boolean | Whether the metrics endpoint is enabled; handles work either way |
counter
counter(opts: PluginMetricOptions): MetricCounter
gauge
gauge(opts: PluginMetricOptions): MetricGauge
histogram
histogram(opts: PluginMetricOptions & { buckets?: number[]; }): MetricHistogram
Declared in src/plugin.ts.
PluginMetricOptions
Options common to every plugin metric
| Property | Type | Description |
|---|---|---|
name | string | Metric name, exported as omegga_plugin_<plugin>_<name>. Must be lowercase letters, digits, and underscores. |
help? | string | One-line description, shown in the scrape output |
labels? | string[] | Label names this metric may use (plugin is added automatically) |
Declared in src/plugin.ts.
MetricCounter
A value that only ever increases, such as a number of events
inc
inc(value?: number): void
inc(labels: PluginMetricLabels, value?: number): void
Add to the count (default 1), optionally on a labelled series
reset
reset(): void
Discard every series
Declared in src/plugin.ts.
MetricGauge
A value that can go up and down, such as a queue length
set
set(value: number): void
set(labels: PluginMetricLabels, value: number): void
inc
inc(value?: number): void
inc(labels: PluginMetricLabels, value?: number): void
dec
dec(value?: number): void
dec(labels: PluginMetricLabels, value?: number): void
remove
remove(labels?: PluginMetricLabels): void
Stop exporting one labelled series
collect
collect(fn: () => number | void): void
Produce the value on demand instead of setting it. The callback runs when the metric is collected, which is cheaper than setting it on a timer.
reset
reset(): void
Declared in src/plugin.ts.
MetricHistogram
Bucketed observations, such as durations
observe
observe(value: number): void
observe(labels: PluginMetricLabels, value: number): void
startTimer
startTimer(labels?: PluginMetricLabels): () => number
Start a timer; call the returned function to observe elapsed seconds
reset
reset(): void
Declared in src/plugin.ts.
PluginMetricLabels
Label values attached to a plugin metric
type PluginMetricLabels = Record<string, string | number | boolean>
Declared in src/plugin.ts.
PluginInterop
| Property | Type | Description |
|---|---|---|
name | string | |
documentation | IPluginDocumentation | null | |
loaded | boolean |
emitPlugin
emitPlugin?(event: string, args: any[]): Promise<any>
Declared in src/plugin.ts.