New Relic Rust Plugin Agent SDK
This project represents a Rust binding of New Relic Plugin API. This crate can be used to build plugin agents.
Examples
// Plugin agent setup
let mut agent = new;
let mut c1 = agent.create_component;
agent.create_metric;
agent.create_metric;
agent.register_component;
// Poll cycle function. This function is excuted every [poll_cycle] seconds.
// Start the agent
agent.run;
state
An agent has the option to have a state to be able to preserve metric readings through cycles. States are passed to Agent instances via the set_state
function. States are generic types, which means you can create a custom struct like in this example:
// Plugin agent setup
let mut agent = new;
let mut c1 = agent.create_component;
agent.create_metric;
agent.register_component;
// Poll cycle function. This function is excuted every [poll_cycle] seconds.
// Start the agent
agent.run;
config
NewRelic plugin reads configuration from a config.yml
file located in the current working directory. If no config.yml
file is present, default values are used. Possible config keys and values:
Config key | Description | Default |
---|---|---|
endpoint | NewRelic custom plugin API endpoint | https://platform-api.newrelic.com/platform/v1/metrics |
log4rs_file | log4rs config file | log4rs.yml |
deliver_cycle | metric reporting frequency | 60 (seconds) |
poll_cycle | poll cycle frequency | 20 (seconds) |
logging
NewRelic plugin uses log4rs. All events logged from within the agent are sent to a logger named "agent". You can add more loggers in log4rs config file to log messages from your plugin's code.
Example log4rs.yml
file:
refresh_rate: 60 seconds
appenders:
agent:
kind: file
path: "log/agent.log"
encoder:
pattern: "{d} - {l} - {f} - {m}{n}"
plugin:
kind: file
path: "log/plugin.log"
encoder:
pattern: "{d} - {l} - {f} - {m}{n}"
loggers:
agent:
level: error
appenders:
- agent
plugin:
level: info
appenders:
- plugin