This time, I will talk about the mechanism of blackbird data transmission by the first step of writing the blackbird plugin! At the same time, I would like to talk about the startup sequential of blackbird itself.
Now, let's get a rough overview.
blackbird uses the plugin format for both the data acquisition part and the transmission part (although it may not be called data strictly because it is a Metric of each middleware). The Plugin to be acquired is established as a Plugin by implementing a class that inherits a specific base class. So basically you can implement it by writing just one snippet-level Python file.
As a whole flow,
It has become a flow.
The blackbird instance checks config when it is created (when calling the __init __
method).
At that time, it is called root config file, or it reads the file specified by the --config
option like blackbird --config = CONFIG_FILE
.
Then, check the path specified by the ʻinclude_dir` directive and read each included file.
At the same time, config parse and validation are also performed, and if a validation error occurs at this stage, the startup will fail.
notes:
The validation error here means that a directive that expects an int type contains a str type (in other words, the ʻint () `method throws a ValueError). For example, the required directives are not specified.
Each Thread has a name (the name itself has no meaning, but it increases transparency during debugging, and it can be started with a name to load multiple plugins with different settings). It can be attached. For the Thread name, use the section name (described later) in the config.
What is the section name here?
[SECTION_NAME]
directive_001 = XXXXX
directive_002 = ABC012
Means _SECTION \ NAME above. That is, in this case a Thread named SECTION \ _NAME will be generated.
The blackbird.sr71.Blackbird instance becomes the main process, and this process calls the run
method of each Thread, and the run
method calls the method that collects the data of each plugin.
Each Thread throws an item to the Queue for Metric (for data), and the plugin for the plugin that sends somewhere retrieves the item from the Queue and sends the data.
If you show the contents so far in the figure, it looks like this
------------------------------------------
| blackbird Main process |
------------------------------------------
| | |
-- Tharead001 -- Thread002 -- Thread003 ...
---------
|-------|
|-------|
| Queue |
|-------|
|-------|
---------
#Queue is created in Main process
Well, what I want to say after all is that it is very easy to write a plugin, write the part to get data and Metrics, call the enqueue method of the base class, and it is basically the end. I will explain the details of how to write a plugin in detail next time.