SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Beyond the Loadable Modules
Extending a Zabbix Agent for fun and profit
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Agenda
What is the Zabbix Loadable Module ?
The Problem. Why the loadable module is not
for everyone.
The Solution. Next step beyond the Loadable
Module.
How it is implemented ?
What you can do with it ?
The Requirements.
Performance and convenience.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Zabbix Loadable Module, is a simple and
elegant way to extend your agent and a
server.


Unlike running an external script, this is a
shared library, which is loaded by Zabbix
component during startup and become a
part of such component, operating inside
it’s address space.
So, this is not only about running a custom
code from an Agent or the Server, but
doing it with performance in mind.
What is the Zabbix loadable module.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
At some point, you are realized, that the
performance of the UserParameter isn't
great.
Although, Zabbix Loadable Module and
correct “C” code is very powerful, it is not
for everyone. Because…
let's face the truth ….
The Problem.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Problem.
Most of us nowadays are not “C” developers.
Which is one of the pre-requirement for
developing a Zabbix Loadable Module.
Even if we do know how and can develop using “C”,
oftentimes we do not have a time to develop
and “own” a piece of the “C” code.
Even if we do know “C”, and can afford an
expense to “owning” a “C” code, oftentimes we do
need to develop something fast, using already
existing high-level modules
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Developing you Metrics collection code
using language other than “C”.
The Solution.
Embed this language into the Zabbix Agent
by using Loadable Modules.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Requirements.
The solution is to use any RAD(1) language. Try to pick
the one, which do have the following:
(1) RAD stands for “Rapid Application Development”
Rich data types. OOP capabilities is a plus
Embeddable with simple API
Rich library of the modules, which shall allow you
fast implementation of custom metrics acquisition.
It is a accepted in your company by it's lead Architect
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Requirements.
Language shall be mature, well developed and
documented and you shall have more than a
single developer around who can code in it.
It shall be approved by your local InfoSec team.
It shall be readily available for all hardware and
OS platforms you do need to cover.
For the people not exposed to this particular
language before, it shall be fairly easy to learn
It shall be fast enough for your purposes.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Decision.
I chose the Python(1) as my “language of choice”,
because it is matching of all my requirements and
I do have a rich library of classes and functions
which helps me to collect metrics data with ease.
(1) http://www.python.org
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Design decisions and a problems to solve:
How to startup and initialize
How to do the data types conversion
How to route Zabbix “call for the metric” to
the Python module.
How to finalize
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Setup of the development environment:
Or configure and install Python from the
sources. Look at http://www.python.org
Ether install python-devel (or similar)
package provided by your OS vendor
If you can compile any Python extension
module, you are fine.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for the data conversion:
PyLongAsLong(), PyFloat_AsDouble(), PyArg_Parse()

Converting Python objects into a “C” types
PyString_FromString(…)

Creating Python string object from “C” char*
PyTuple_SET_ITEM(…)

Set value in the tuple.
PyTuple_New(…)

Creating a new tuple. That’s how you pass parameters.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API you do need to know for the data conversion:
SET_MSG_RESULT(...)

Passing a message from “C” module back to Zabbix
SET_UI64_RESULT(…)/SET_DBL_RESULT(…)/SET_STR_RESULT(...)

Set Unsigned Integer/Double/String as a result
get_rparam(…)

Returning parameter from AGENT_REQUEST*
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for Initialization and
Finalization:
Py_Initialize()

Initialize Python environment
Py_SetProgramName(…) 

Set program name for an embedded Python
Py_Finalize()

Uninitialize Python environment
Py_IsInitialized()

Check if Python environment initialized
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API you do need to know for Initialization and
Finalization:
int zbx_module_init()

Loadable module initialization function. Executed when
module loads. Returns ZBX_MODULE_OK if module
loaded succedsfully, or ZBX_MODULE_FAIL otherwise.
During Startup, we are calling Python function
“main(...)” from module ZBX_startup.py
int zbx_module_uninit()
Loadable Module finalization function. Executed when
Zabbix Agent goes into shutdown. Returns
ZBX_MODULE_OK if module loaded succedsfully, or
ZBX_MODULE_FAIL otherwise. During shutdown, we
are calling Python function “main(...)” from the module
ZBX_finish.py
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for proper handling of the
PyObject*:
Python uses reference-based garbage collector.
Py_DECREF(…)

Decrease reference count for a Python object
Py_INCREF(…)

Increase reference count for a Python object
Py_REFCNT(…)

Return the number of the reference counts
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for working with
Modules and executing Python “code objects”:
PyObject_GetAttrString(…)

Lookup an attribute or an object in the Python
module. Returns a reference to the attribute if found.
PyImport_ImportModule(…)

Importing a Python module. Returns a reference to a
module.
PyEval_CallObject(…)

Execute a Python “code object”.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API call returning list of the supported metrics:
ZBX_METRIC *zbx_module_item_list()
Returns a list of the metric keys
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Metrics exported from Python module to Zabbix :
python.ping[]
Returns “1” if module is properly initialized, otherwise
“0”
python.version[]
Returns text representatikon of the version of the
Python interpreter.
py[…]
Pass the call from Zabbix to Python
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
How to define metrics in Zabbix Loadable Module :
You shall define NULL-terminated array of ZBX_METRIC structures, as
static ZBX_METRIC keys[]
Each metric structure describes a single metric as:

Name
Name of the metric
Flag
Pass “0” if no parameters required or CF_HAVEPARAMS
if parameters are expected
Function
Reference to a metric function
Test parameters
Test parameters to a metric function
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Example:
static ZBX_METRIC keys[] =
{
{"python.ping", 0, zbx_module_python_ping, NULL},
{"python.version", 0, zbx_module_python_version, NULL},
{"py", CF_HAVEPARAMS, zbx_module_python_call_wrap, ""},
{NULL}
};
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Passing call from Zabbix to Python in “C”:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Routing call from Zabbix to Python through ZBX_call/main:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
What you can do with it.
Create metric collection. It could be something as
simple as this:
And after you place this module in pymodules
directory, you can query this metric like this:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Or full-blown Python
application with classes,
objects and everything ...
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Previous example will allow you to query the metric, which
returns the number of specific processes which command lines
are matching a user-defined pattern. For example, that how we
can query the number of sshd processes attached to pts pseudo-
terminals.
zabbix_get -s localhost –k py["AF_ps","sshd: (.*)pts/(.*)","sshd"]
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Let's talk about performance:
I my test, I am requesting a series of metrics from a
passive Agent, using zabbix_get
Let's test just the effectiveness of the call. Our metric
will be very simple and return UNIX timestamp
I am setting up the same module, which will be called
from Loadable Module and UserParameters
UserParameter=python.time,/usr/bin/python /usr/local/etc/pymodules/ZBX_time.py
In the same /usr/local/etc/zabbix_agentd.conf
vs
LoadModulePath=/usr/local/etc
LoadModule=python.so
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Required time:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Seconds per request:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
You are using RAD language to create a
custom Metric collection
You can use any Python features. No
restrictions. But your metric collection code
shall be efficient and quick.
The test shows increase in performance.
Embedded Python which loaded through
Zabbix Loadable Module provides about 5.7
times faster response time while executing
the same code. But your results may vary ...
Your metric collection is as fast, as your host
can compute and efficient your code.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Conclusion
Author: Vladimir Ulogov
e-mail: vladimir.ulogov@zabbix.com
https://github.com/vulogov/zlm-python
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Conclusion
Q/A ?

Más contenido relacionado

La actualidad más candente

SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringNayden Gochev
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Chris Fregly
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzIvan Krylov
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan Krylov
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...DrupalMumbai
 
A Taste of Pharo 7.0
A Taste of Pharo 7.0A Taste of Pharo 7.0
A Taste of Pharo 7.0ESUG
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyMatthew Gaudet
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisRuslan Shevchenko
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)servicesRafael Winterhalter
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Daniele Pallastrelli
 
Sour Pickles
Sour PicklesSour Pickles
Sour PicklesSensePost
 
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Chris Fregly
 
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentalscbcunc
 

La actualidad más candente (20)

SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with Spring
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Java8
Java8Java8
Java8
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
 
A Taste of Pharo 7.0
A Taste of Pharo 7.0A Taste of Pharo 7.0
A Taste of Pharo 7.0
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 
Sour Pickles
Sour PicklesSour Pickles
Sour Pickles
 
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
 
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentals
 

Destacado

Presentatie stadsvestiaire (Fictieve Cijfers)
Presentatie stadsvestiaire (Fictieve Cijfers)Presentatie stadsvestiaire (Fictieve Cijfers)
Presentatie stadsvestiaire (Fictieve Cijfers)Thomas Van Ryckeghem
 
My portfolio in Educational Technology
My portfolio in Educational TechnologyMy portfolio in Educational Technology
My portfolio in Educational Technologyjobie pacres
 
Final assignment
Final assignmentFinal assignment
Final assignmentSounak Deb
 
IdeaMart - New App Marketing Plan
IdeaMart - New App Marketing PlanIdeaMart - New App Marketing Plan
IdeaMart - New App Marketing PlanDarshak Kamani
 
Media task 1 powerpoint
Media task 1 powerpointMedia task 1 powerpoint
Media task 1 powerpointjackcooney97
 
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16MLconf
 
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...Корус Консалтинг СНГ
 
Emakume zientzialariak
Emakume zientzialariakEmakume zientzialariak
Emakume zientzialariakiazpiro1
 
Maths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionMaths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionKathleen Ong
 
Продукты Сбербанк страхование для малого и среднего бизнеса
Продукты Сбербанк страхование для малого и среднего бизнесаПродукты Сбербанк страхование для малого и среднего бизнеса
Продукты Сбербанк страхование для малого и среднего бизнесаДеловая среда
 
short course on Subsurface stochastic modelling and geostatistics
short course on Subsurface stochastic modelling and geostatisticsshort course on Subsurface stochastic modelling and geostatistics
short course on Subsurface stochastic modelling and geostatisticsAmro Elfeki
 

Destacado (16)

Presentatie stadsvestiaire (Fictieve Cijfers)
Presentatie stadsvestiaire (Fictieve Cijfers)Presentatie stadsvestiaire (Fictieve Cijfers)
Presentatie stadsvestiaire (Fictieve Cijfers)
 
ca3
ca3ca3
ca3
 
My portfolio in Educational Technology
My portfolio in Educational TechnologyMy portfolio in Educational Technology
My portfolio in Educational Technology
 
Final assignment
Final assignmentFinal assignment
Final assignment
 
IdeaMart - New App Marketing Plan
IdeaMart - New App Marketing PlanIdeaMart - New App Marketing Plan
IdeaMart - New App Marketing Plan
 
Media task 1 powerpoint
Media task 1 powerpointMedia task 1 powerpoint
Media task 1 powerpoint
 
Consultative Selling Whitepaper 2016
Consultative Selling Whitepaper 2016Consultative Selling Whitepaper 2016
Consultative Selling Whitepaper 2016
 
Acaleph 2
Acaleph 2Acaleph 2
Acaleph 2
 
Les5e ppt 06
Les5e ppt 06Les5e ppt 06
Les5e ppt 06
 
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16
Dr. Ike Nassi, Founder, TidalScale at MLconf NYC - 4/15/16
 
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...
Мониторинг загрузки EDI-файлов в корпоративной информационной системе SAP. Оп...
 
Les5e ppt 03
Les5e ppt 03Les5e ppt 03
Les5e ppt 03
 
Emakume zientzialariak
Emakume zientzialariakEmakume zientzialariak
Emakume zientzialariak
 
Maths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionMaths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor question
 
Продукты Сбербанк страхование для малого и среднего бизнеса
Продукты Сбербанк страхование для малого и среднего бизнесаПродукты Сбербанк страхование для малого и среднего бизнеса
Продукты Сбербанк страхование для малого и среднего бизнеса
 
short course on Subsurface stochastic modelling and geostatistics
short course on Subsurface stochastic modelling and geostatisticsshort course on Subsurface stochastic modelling and geostatistics
short course on Subsurface stochastic modelling and geostatistics
 

Similar a Beyond the Loadable Module

ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first moduleVladimir Ulogov
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical MementoOdoo
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4openerpwiki
 
OpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonOpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonCodeOps Technologies LLP
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdfBOSC Tech Labs
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOCCarl Lu
 
Building A Sensor Network Controller
Building A Sensor Network ControllerBuilding A Sensor Network Controller
Building A Sensor Network Controllermichaelpigg
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Introduction of Pharo 5.0
Introduction of Pharo 5.0Introduction of Pharo 5.0
Introduction of Pharo 5.0Masashi Umezawa
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftWan Muzaffar Wan Hashim
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentsadomovalex
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and LingvokotLingvokot
 
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]Animesh Singh
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegelermfrancis
 

Similar a Beyond the Loadable Module (20)

ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first module
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4
 
OpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonOpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in Python
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
 
Building A Sensor Network Controller
Building A Sensor Network ControllerBuilding A Sensor Network Controller
Building A Sensor Network Controller
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Introduction of Pharo 5.0
Introduction of Pharo 5.0Introduction of Pharo 5.0
Introduction of Pharo 5.0
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Vhdl design flow
Vhdl design flowVhdl design flow
Vhdl design flow
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint development
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
Bapi jco
Bapi jcoBapi jco
Bapi jco
 
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
 

Más de Vladimir Ulogov

Introduction to the core.ns application framework
Introduction to the core.ns application frameworkIntroduction to the core.ns application framework
Introduction to the core.ns application frameworkVladimir Ulogov
 
Generating test data for Statistical and ML models
Generating test data for Statistical and ML modelsGenerating test data for Statistical and ML models
Generating test data for Statistical and ML modelsVladimir Ulogov
 
Short presentation of the Bitmasher private-key encryption
Short presentation of the Bitmasher private-key encryptionShort presentation of the Bitmasher private-key encryption
Short presentation of the Bitmasher private-key encryptionVladimir Ulogov
 
Krabbe - messaging in loose groups
Krabbe - messaging in loose groupsKrabbe - messaging in loose groups
Krabbe - messaging in loose groupsVladimir Ulogov
 
"the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar."the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar.Vladimir Ulogov
 

Más de Vladimir Ulogov (9)

Introduction to the core.ns application framework
Introduction to the core.ns application frameworkIntroduction to the core.ns application framework
Introduction to the core.ns application framework
 
Generating test data for Statistical and ML models
Generating test data for Statistical and ML modelsGenerating test data for Statistical and ML models
Generating test data for Statistical and ML models
 
Short presentation of the Bitmasher private-key encryption
Short presentation of the Bitmasher private-key encryptionShort presentation of the Bitmasher private-key encryption
Short presentation of the Bitmasher private-key encryption
 
Krabbe - messaging in loose groups
Krabbe - messaging in loose groupsKrabbe - messaging in loose groups
Krabbe - messaging in loose groups
 
"the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar."the Bund" language. A PEG grammar.
"the Bund" language. A PEG grammar.
 
The Bund language
The Bund languageThe Bund language
The Bund language
 
Vladimir_Ulogov_Resume
Vladimir_Ulogov_ResumeVladimir_Ulogov_Resume
Vladimir_Ulogov_Resume
 
zas-agent-0.1.1
zas-agent-0.1.1zas-agent-0.1.1
zas-agent-0.1.1
 
zlm-cython
zlm-cythonzlm-cython
zlm-cython
 

Beyond the Loadable Module

  • 1. ZABBIX www.zabbix.comBeyond the Loadable Modules Beyond the Loadable Modules Extending a Zabbix Agent for fun and profit
  • 2. ZABBIX www.zabbix.comBeyond the Loadable Modules Agenda What is the Zabbix Loadable Module ? The Problem. Why the loadable module is not for everyone. The Solution. Next step beyond the Loadable Module. How it is implemented ? What you can do with it ? The Requirements. Performance and convenience.
  • 3. ZABBIX www.zabbix.comBeyond the Loadable Modules Zabbix Loadable Module, is a simple and elegant way to extend your agent and a server. 
 Unlike running an external script, this is a shared library, which is loaded by Zabbix component during startup and become a part of such component, operating inside it’s address space. So, this is not only about running a custom code from an Agent or the Server, but doing it with performance in mind. What is the Zabbix loadable module.
  • 4. ZABBIX www.zabbix.comBeyond the Loadable Modules At some point, you are realized, that the performance of the UserParameter isn't great. Although, Zabbix Loadable Module and correct “C” code is very powerful, it is not for everyone. Because… let's face the truth …. The Problem.
  • 5. ZABBIX www.zabbix.comBeyond the Loadable Modules The Problem. Most of us nowadays are not “C” developers. Which is one of the pre-requirement for developing a Zabbix Loadable Module. Even if we do know how and can develop using “C”, oftentimes we do not have a time to develop and “own” a piece of the “C” code. Even if we do know “C”, and can afford an expense to “owning” a “C” code, oftentimes we do need to develop something fast, using already existing high-level modules
  • 6. ZABBIX www.zabbix.comBeyond the Loadable Modules Developing you Metrics collection code using language other than “C”. The Solution. Embed this language into the Zabbix Agent by using Loadable Modules.
  • 7. ZABBIX www.zabbix.comBeyond the Loadable Modules The Requirements. The solution is to use any RAD(1) language. Try to pick the one, which do have the following: (1) RAD stands for “Rapid Application Development” Rich data types. OOP capabilities is a plus Embeddable with simple API Rich library of the modules, which shall allow you fast implementation of custom metrics acquisition. It is a accepted in your company by it's lead Architect
  • 8. ZABBIX www.zabbix.comBeyond the Loadable Modules The Requirements. Language shall be mature, well developed and documented and you shall have more than a single developer around who can code in it. It shall be approved by your local InfoSec team. It shall be readily available for all hardware and OS platforms you do need to cover. For the people not exposed to this particular language before, it shall be fairly easy to learn It shall be fast enough for your purposes.
  • 9. ZABBIX www.zabbix.comBeyond the Loadable Modules The Decision. I chose the Python(1) as my “language of choice”, because it is matching of all my requirements and I do have a rich library of classes and functions which helps me to collect metrics data with ease. (1) http://www.python.org
  • 10. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Design decisions and a problems to solve: How to startup and initialize How to do the data types conversion How to route Zabbix “call for the metric” to the Python module. How to finalize
  • 11. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Setup of the development environment: Or configure and install Python from the sources. Look at http://www.python.org Ether install python-devel (or similar) package provided by your OS vendor If you can compile any Python extension module, you are fine.
  • 12. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for the data conversion: PyLongAsLong(), PyFloat_AsDouble(), PyArg_Parse() 
Converting Python objects into a “C” types PyString_FromString(…) 
Creating Python string object from “C” char* PyTuple_SET_ITEM(…)
 Set value in the tuple. PyTuple_New(…)
 Creating a new tuple. That’s how you pass parameters.
  • 13. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API you do need to know for the data conversion: SET_MSG_RESULT(...) 
Passing a message from “C” module back to Zabbix SET_UI64_RESULT(…)/SET_DBL_RESULT(…)/SET_STR_RESULT(...) 
Set Unsigned Integer/Double/String as a result get_rparam(…)
 Returning parameter from AGENT_REQUEST*
  • 14. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for Initialization and Finalization: Py_Initialize()
 Initialize Python environment Py_SetProgramName(…) 
 Set program name for an embedded Python Py_Finalize()
 Uninitialize Python environment Py_IsInitialized()
 Check if Python environment initialized
  • 15. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API you do need to know for Initialization and Finalization: int zbx_module_init()
 Loadable module initialization function. Executed when module loads. Returns ZBX_MODULE_OK if module loaded succedsfully, or ZBX_MODULE_FAIL otherwise. During Startup, we are calling Python function “main(...)” from module ZBX_startup.py int zbx_module_uninit() Loadable Module finalization function. Executed when Zabbix Agent goes into shutdown. Returns ZBX_MODULE_OK if module loaded succedsfully, or ZBX_MODULE_FAIL otherwise. During shutdown, we are calling Python function “main(...)” from the module ZBX_finish.py
  • 16. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for proper handling of the PyObject*: Python uses reference-based garbage collector. Py_DECREF(…)
 Decrease reference count for a Python object Py_INCREF(…)
 Increase reference count for a Python object Py_REFCNT(…)
 Return the number of the reference counts
  • 17. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for working with Modules and executing Python “code objects”: PyObject_GetAttrString(…)
 Lookup an attribute or an object in the Python module. Returns a reference to the attribute if found. PyImport_ImportModule(…)
 Importing a Python module. Returns a reference to a module. PyEval_CallObject(…) 
Execute a Python “code object”.
  • 18. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API call returning list of the supported metrics: ZBX_METRIC *zbx_module_item_list() Returns a list of the metric keys
  • 19. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Metrics exported from Python module to Zabbix : python.ping[] Returns “1” if module is properly initialized, otherwise “0” python.version[] Returns text representatikon of the version of the Python interpreter. py[…] Pass the call from Zabbix to Python
  • 20. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. How to define metrics in Zabbix Loadable Module : You shall define NULL-terminated array of ZBX_METRIC structures, as static ZBX_METRIC keys[] Each metric structure describes a single metric as:
 Name Name of the metric Flag Pass “0” if no parameters required or CF_HAVEPARAMS if parameters are expected Function Reference to a metric function Test parameters Test parameters to a metric function
  • 21. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Example: static ZBX_METRIC keys[] = { {"python.ping", 0, zbx_module_python_ping, NULL}, {"python.version", 0, zbx_module_python_version, NULL}, {"py", CF_HAVEPARAMS, zbx_module_python_call_wrap, ""}, {NULL} };
  • 22. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Passing call from Zabbix to Python in “C”:
  • 23. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Routing call from Zabbix to Python through ZBX_call/main:
  • 24. ZABBIX www.zabbix.comBeyond the Loadable Modules What you can do with it. Create metric collection. It could be something as simple as this: And after you place this module in pymodules directory, you can query this metric like this:
  • 25. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Or full-blown Python application with classes, objects and everything ...
  • 26. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Previous example will allow you to query the metric, which returns the number of specific processes which command lines are matching a user-defined pattern. For example, that how we can query the number of sshd processes attached to pts pseudo- terminals. zabbix_get -s localhost –k py["AF_ps","sshd: (.*)pts/(.*)","sshd"]
  • 27. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Let's talk about performance: I my test, I am requesting a series of metrics from a passive Agent, using zabbix_get Let's test just the effectiveness of the call. Our metric will be very simple and return UNIX timestamp I am setting up the same module, which will be called from Loadable Module and UserParameters UserParameter=python.time,/usr/bin/python /usr/local/etc/pymodules/ZBX_time.py In the same /usr/local/etc/zabbix_agentd.conf vs LoadModulePath=/usr/local/etc LoadModule=python.so
  • 28. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Required time:
  • 29. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Seconds per request:
  • 30. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience You are using RAD language to create a custom Metric collection You can use any Python features. No restrictions. But your metric collection code shall be efficient and quick. The test shows increase in performance. Embedded Python which loaded through Zabbix Loadable Module provides about 5.7 times faster response time while executing the same code. But your results may vary ... Your metric collection is as fast, as your host can compute and efficient your code.
  • 31. ZABBIX www.zabbix.comBeyond the Loadable Modules Conclusion Author: Vladimir Ulogov e-mail: vladimir.ulogov@zabbix.com https://github.com/vulogov/zlm-python
  • 32. ZABBIX www.zabbix.comBeyond the Loadable Modules Conclusion Q/A ?