[PYTHON] Write your blackbird plugin # 001

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.

plugin method

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.

Launch sequential

As a whole flow,

  1. Start from the blackbird command line (/ usr / bin / blackbird when installed with rpm)
  2. blackbird.sr71.Blackbird Instance generation
  3. Call the Main function (blackbird.sr71.main)
  4. Read the configuration file
  5. Create individual Threads for capture and send plugins
  6. Kick each Thread
  7. Each Thread is stored in the Queue for Metric and read from the Queue

It has become a flow.

2. Create a blackbird instance

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.

5. Generate Threads for various plugins

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.

6. Kick each Thread

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.

7. Each Thread is stored in the Queue for Metric and read from the Queue

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

What ??

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.

Recommended Posts

Write your blackbird plugin # 002
Write your blackbird plugin # 001
Write your blackbird plugin # 003
Write a vim plugin in Python
Write a simple Vim Plugin in Python 3