Run and Test
In the previous step, we created a simple plugin, registered a metric, and updated the metric's value.
Now, let's run the plugin to make sure it works as expected.
Modifying Program.cs
Instead of installing the plugin in MoBro every time we want to test it, the SDK provides a convenient utility called
MoBroPluginBuilder. It creates and runs the plugin locally, just like MoBro would.
Replace the content of the Program.cs file with the following:
using MoBro.Plugin.SDK;
// Create and start the plugin to test it locally
using var plugin = MoBroPluginBuilder
.Create<Plugin.Example.Plugin>()
.Build();
// Keep the plugin running until enter is pressed
Console.ReadLine();
Build and Run
Since this is a standard .NET console application, you can run it directly from your IDE (including the debugger).
Alternatively, run the following command in the project directory:
dotnet run
Output
Once the plugin is built and started, you should see the following output:
PS C:\dev\Plugin.Example> dotnet run
16:23:03.959 [INF] Creating new plugin instance
16:23:03.965 [INF] Invoking 'init' function on plugin
16:23:03.986 [INF] Registered Metric: first_metric
16:23:03.990 [DBG] Value of metric first_metric updated to: Hello World
From the logs, you can see that:
- A new instance of the plugin was created.
- The
Init()function was called. - The
first_metricmetric was registered. - The value of
first_metricwas updated toHello World.
Congratulations!
You've successfully created and run your first plugin! 🎉
Can't wait to see the metric in MoBro? With MoBro running, install the plugin straight from the project directory using the CLI:
mobro install .
Then open the Metric Explorer in MoBro. Publish and Install covers this step in detail.
Currently, the plugin provides a single metric whose value never changes.
In the next section, we will:
- Expand the functionality by updating metrics periodically.
- Add a setting to let users customize the plugin.