Skip to content

Zabbix Export


Version-1.37.0


Collect real-time data from the Zabbix service and send it to the GuanCe cloud center. Currently, Zabbix supports writing real-time data to files from version 5.0 to 7.0. ExportType allows to specify which entity types (events, history, trends) will be exported.

Config

Requirements Config

Zabbix config file: /etc/zabbix/zabbix_server.conf :

### Option: ExportDir
#       Directory for real time export of events, history and trends in newline delimited JSON format.
#       If set, enables real time export.
#
# Mandatory: no
ExportDir=/data/zbx/datakit

### Option: ExportFileSize
#       Maximum size per export file in bytes.
#       Only used for rotation if ExportDir is set.
#
# Mandatory: no
# Range: 1M-1G
ExportFileSize=32M

### Option: ExportType
#       List of comma delimited types of real time export - allows to control export entities by their
#       type (events, history, trends) individually.
#       Valid only if ExportDir is set.
#
# Mandatory: no
# Default:
# ExportType=events,history,trends

Modify the configuration items:

ExportDir=/data/zbx/datakit
ExportFileSize=32M

Permission to modify files:

mkdir -p /data/zbx/datakit
chown zabbix:zabbix -R /data/zbx/datakit
chmod u+rw -R /data/zbx/datakit/

Attention: When the size of the configuration file is small, it is measured based on the host configuration. Files that are too large can easily cause insufficient disk space. And the .old files should be deleted regularly.

Restart server:

systemctl restart zabbix-server

DataKit Config

Go to the conf.d/zabbix_exporter directory under the DataKit installation directory, copy zabbix_exporter.conf.sample and name it zabbix_exporter.conf. Examples are as follows:

    [[inputs.zabbix_exporter]]
      ## zabbix server web.
      localhostAddr = "http://localhost/zabbix/api_jsonrpc.php"
      user_name = "Admin"
      user_pw = "zabbix"

      ## measurement yaml Dir
      measurement_config_dir = "/data/zbx/yaml"

      ## exporting object.default is item. all is <trigger,item,trends>. 
      objects = "item"

      ## update items and interface data.
      ## like this: All data is updated at 2 o'clock every day.
      crontab = "0 2 * * *"

      # [inputs.zabbix_exporter.tags]
        # key1 = "value1"
        # key2 = "value2"
        # ...

      ## mysql database:zabbix , tables: items,interface.
      #[inputs.zabbix_exporter.mysql]
      #  db_host = "192.168.10.12"
      #  db_port = "3306"
      #  user = "root"
      #  pw = "123456"

      # Zabbix server version 5.x.
      [inputs.zabbix_exporter.export_v5]
        # zabbix realTime exportDir path
        export_dir = "/data/zbx/datakit/"

Restart DataKit server.

Data Caching

1 Retrieve the entire items table from MySQL and store it in memory. After exporting data from Zabbix, you need to query the items table using the item ID. Therefore, the entire table is stored using map[itemid]itemc.

mysql> select itemid, name, type, key_, hostid, units from items where itemid=29167;
+--------+--------------------+--------+-----------------------------+--------+-------+
| itemid | name               | type   | key_                        | hostid | units |
+--------+--------------------+--------+-----------------------------+--------+-------+
|  29167 | CPU interrupt time | 4      | system.cpu.util[,interrupt] |  10084 | %     |
+--------+--------------------+--------+-----------------------------+--------+-------+

There is a mapping table for type, using item_type as the key for the tag.

2 Retrieve the interface table from MySQL and store it in memory.

mysql> select * from zabbix.interface;
+-------------+--------+------+------+-------+---------------+-----+-------+
| interfaceid | hostid | main | type | useip | ip            | dns | port  |
+-------------+--------+------+------+-------+---------------+-----+-------+
|           1 |  10084 |    1 |    1 |     1 | 127.0.0.1     |     | 10050 |
|           2 |  10438 |    1 |    1 |     1 | 10.200.14.226 |     | 10050 |
+-------------+--------+------+------+-------+---------------+-----+-------+

Field Meanings:
main 0: Default network interface, 1: Non-default network interface
type 1: "Agent", 2: "SNMP", 3: "IPMI", 4: "JMX",

The IP can be retrieved based on the host ID, so the storage format for the interface table is map[hostid]interfaceC.

There is also a mapping table for type.

3 Measurement Caching

Read all files ending in .yaml from the measurement_config_dir directory and load them into memory.

Data Assembly

Using itemid = 29167 as an example

A line of data retrieved from the exporter file is as follows:

{"host":{"host":"Zabbix server","name":"Zabbix server"},"groups":["Zabbix servers"],"applications":["CPU"],"itemid":29167,"name":"CPU interrupt time","clock":1728611707,"ns":570308079,"value":0.000000,"type":0}

Data retrieved from the items table:

itemid, name, key_, units
29167, CPU interrupt time, "system.cpu.util[,interrupt]", %

Assembly Steps:

Use the item ID to query the items table (already cached in memory) to obtain name, key_, and units. At this point: name="CPU interrupt time", key_ = "system.cpu.util[,interrupt]", units=% (percentage format).

Then, retrieve the data for this name from the measurement table:

- measurement: System
  metric: system_cpu_util
  key: system.cpu.util
  params:
    - cpu
    - type
    - mode
    - logical_or_physical
  values:
    - ''
    - user
    - avg1
    - logical

Based on the string after the key in the items table (brackets removed), the data is found in the measurement. The corresponding relationship in the brackets indicates the following tags: cpu="", type="interrupt", mode="avg1", logical_or_physical="logical".

Finally, the final form of the metric is:

Metric Set: zabbix-server
Metric Name: system_cpu_util
Value: 0.000000
Tags:

cpu=""
type="interrupt"
mode="avg1"
logical_or_physical="logical"
measurement="System"
applications="CPU"
groups="Zabbix servers"
host="Zabbix server"
item_type="Zabbix agent"
interface_type="Agent"
interface_main="default"
ip="127.0.0.1"
hostname="Zabbix server"
time=1728611707570308079

Zabbix Service API

Obtain data through the API interfaces exposed by Zabbix.

First, obtain a token through the login interface. The token is used for authentication in subsequent requests.

Second, use the itemid to retrieve the name, key_, type, hostid, and unit information for that item. The returned data is in string format and needs to be converted to the corresponding format.

Note: The returned format is not fixed. If a single item is returned, it is in string format; if multiple items are requested, it is in array format.

Docs

Feedback

Is this page helpful? ×