Zabbix数据库表结构解析
zabbix数据库表结构

zabbix数据库表结构概述Zabbix 5.2.6 数据库共有170张表,Zabbix 数据表的名称都是复数。
资源之间的关联关系是通过外键来完成的。
比如host和item的关联关系,就是在items表中使用hostid与hosts表中的资源进行关联。
本文将介绍Zabbix 数据库中主要的数据表,以及如何对数据库中表进行增删改查操作,熟悉Zabbix 数据库表结构;数据库版本select version();统计 zabbix 数据库中表项select count(8) tables,table_schema frominformation_schema.tables where table_schema ='zabbix';查询zabbix 数据库大小select table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables where table_schema='zabbix';查询zabbix库各表容量大小select table_schema as '数据库', table_name as '表名', table_rows as '记录数', truncate(data_length/1024/1024,2) as '数据容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tables where table_schema='zabbix' order by data_length desc, index_length desc;hosts存储被监控主机的信息常用字段介绍Hostid:唯一标识Host在Zabbix及数据库中的id。
zabbix架构原理

zabbix架构原理Zabbix是一种用于监控和管理网络设备、服务器以及应用程序的开源解决方案。
它的架构原理如下:1. 服务器端(Zabbix Server):Zabbix的核心组件,负责接收来自各个监控代理和其他组件的数据,并处理这些数据。
它还负责存储监控数据、配置告警规则和触发动作。
2. 监控代理(Zabbix Agent):安装在需要监控的目标主机上,负责收集主机的性能数据并将其发送给Zabbix Server。
监控代理可以通过主动模式或被动模式与服务器通信。
3. 数据库(Database):Zabbix使用关系型数据库(如MySQL、PostgreSQL等)存储监控数据、配置信息和历史记录。
数据库存储了整个Zabbix系统的状态和配置信息。
4. 前端界面(Frontend):Zabbix提供了一个用户友好的Web界面,用于配置监控项、显示监控数据、设置报警规则等。
前端界面与服务器通过HTTP或HTTPS 协议进行通信。
5. 触发器(Triggers):Zabbix使用触发器定义在特定条件下触发报警动作的规则。
例如,当CPU利用率超过某个阈值时,触发器会触发相应的报警。
6. 动作(Actions):Zabbix的动作定义了在触发器满足条件时执行的操作,例如发送电子邮件、短信通知或运行脚本。
7. 监控项(Items):监控项定义了需要收集和监控的数据类型,可以是CPU利用率、内存使用量、网络流量等。
Zabbix支持多种监控方式,如简单检查、SNMP、JMX、IPMI等。
8. 图形和报表(Graphs and Reports):Zabbix可以生成各种图形和报表,以直观地展示监控数据的变化趋势和性能指标。
总体来说,Zabbix的架构包括服务器端、监控代理、数据库、前端界面以及触发器、动作、监控项、图形和报表等组件。
通过这些组件的协同工作,Zabbix实现了对网络设备、服务器和应用程序的全面监控和管理。
Zabbix数据库表结构解析

snmp_*(除 8.中提到的):同上,SNMP 参数。
maintenanceid,maintenance_*:这是 Zabbix 另一个机制 Maintaince 有关,用于使 Host
置于维护状态而不会报警。
常用操作
前面只讲了 Hosts 一张表,所以这里只能介绍一些针对 Host 的操作。
更新机器的 proxy。找到 proxy 的 hostid,更新对用 host 的 proxy_hostid:
select hostid from hosts where host='ProxyA' and ip='0.0.0.0'; -- get hostid: 1234
update hosts set proxy_hostid=1234 where host='Host_To_Update_Proxy'; enable/disable host:
|
|
| jmx_errors_from | int(11)
| NO | | 0
|
|
| jmx_error
| varchar(128)
| NO | |
|
|
| name
| varchar(64)
| NO | MUL |
|
|
批注 [d1]: 改下结构
| flags
| int(11)
| NO | | 0
|
个类似,Zabbix 中任意一种资源都有自己的 id,比如 itemid,groupid 等。
proxy_hostid:如果使用了‘Proxy-Server’架构,这个字段表示的是监控这台机器的 Proxy
的 hostid。有一点需要注意,每个 Proxy 在 Hosts 表里有两条记录(其他 Host 只有一条
zabbix深入分析

Zabbix深入分析2015目录1研究目标 (2)3WEB界面菜单功能......................................................................................................... 4主要功能名词及概念 ......................................................................................................4.1.1SNMP................................................................................................................4.1.2IPMP..................................................................................................................4.1.3配置(configuration) ..................................................................................4.1.4主机和主机组(Hosts and host group) .................................................IT 服务(IT services)................................................................................发现(Discovery)........................................................................................队列(Queue)..............................................................................................应用(Applications)....................................................................................分布式监控(Distributed monitoring) ...................................................维护(Maintenance) (5)5.9SSH检查..................................................................................................................5.10Telnet检查...............................................................................................................5.11外部检查..................................................................................................................5.12汇总检查..................................................................................................................5.13被动监控..................................................................................................................5.14JMX监控 .................................................................................................................66.3.5滞留状态..........................................................................................................6.4触发器依赖性(Dependency) .........................................................................6.5触发器严重性(Severity)..................................................................................6.6触发器的单位符号(Unit symbols)...............................................................6.6.1单位后缀..........................................................................................................6.6.2使用举例 (7)8Quickstart............................................................................................................................ 9数据模型............................................................................................................................ 10Zabbix API..................................................................................................................10.1概览...........................................................................................................................10.1.1API使用说明..................................................................................................10.1.2Zabbix API支持的数据类型 ......................................................................10.3.4Grahps...............................................................................................................10.3.5Templates..........................................................................................................10.3.6Export and import...........................................................................................10.3.7Low-level discovery.........................................................................................10.3.8Screens...............................................................................................................10.3.9Actions and alerts ............................................................................................10.5API信息...................................................................................................................10.6API引用的对象(Object)的属性 ..................................................................10.6.1History object...................................................................................................11图表套件-FusionChats..............................................................................................11.1概述...........................................................................................................................11.2套件...........................................................................................................................12.3.1外部查看图表可行性 ...........................................................................12.3.2利用FusionCharts 展现.......................................................................12.4报警策略的可定制性...........................................................................................12.5与Zabbix用户会话同步策略 ............................................................................12.5.1统一用户..................................................................................................12.5.2动态登录..................................................................................................13系统的集成................................................................................................................13.1方案...........................................................................................................................13.1.1方案一:内建模块................................................................................13.1.2方案二:iframe嵌入 ............................................................................13.1.3方案三:图表接口................................................................................13.2方案总结..................................................................................................................1研究目标通过对ZABBIX的研究实现如下目标:熟悉可监控的基本模块研究API,并且要写代码测试到监控任务的API控制,包括创建,暂停,更改选项,删除任务。
Zabbix 数据库表结构说明文档

Zabbix 数据库表结构说明文档Zabbix 数据库表结构说明文档目录目录Zabbix 数据库表结构说明文档 (1)Zabbix 数据库表结构说明文档 (1)目录 (1)1. acknowledges表(空) (5)1. actions表 (6)1. alerts表 (7)1. applications_discovery表(空) (8)1. applications_prototype表 (9)1. applications_template表 (9)1. applications表 (9)1. auditlog表 (10)1. auditlog_details表 (10)1. autoreg_host表 (11)1. conditions表 (11)1. config (13)1. corr_condition表(空) (15)1. corr_condition_group表(空) (16)1. corr_condition_tag表(空) (16)1. corr_condition_tagpair表(空) (16)1. corr_condition_tagvalue表(空) (17)1. Corr_operation表(空) (17)1. correlation表(空) (17)1. dashboard表 (18)1. Dashboard_user表 (18)1. Dashboard_usrgrp表 (18)1. dbversion表 (19)1. dchecks表 (19)1. dhosts表(空) (20)1. drules表 (21)1. dservices表(空) (22)1. escalations表(空) (22)1. event_recovery表 (23)1. event_tag表(空) (23)1. events表 (24)1. expressions表 (24)1. functions表 (25)1. globalmacro表 (26)1. globalvars表(空) (26)1. graph_discovery表 (26)1. graph_theme表 (26)1. graphs表 (27)1. graphs_items表 (29)1. group_discovery表(空) (31)1. group_prototype表 (31)1. groups表 (31)1. history表 (32)1. history_log表 (32)1. history_str表 (33)1. history_text表(空) (33)1. history_uint表 (34)1. host_discovery表 (34)1. host_inventory表(空) (35)1. hostmacro表 (37)1. hosts表 (37)1. hosts_groups表 (41)1. hosts_templates表 (41)1. housekeeper表(空) (41)1. httpstep表(空) (42)1. httpstep_field表(空) (42)1. httpstepitem表(空) (43)1. httptest表(空) (43)1:基本认证 (45)2:NTML认证 (45)1. httptest_field表(空) (45)1. httptestitem表(空) (45)1. icon_map表(空) (46)1. icon_mapping表(空) (46)1. ids表 (47)1. images表 (47)1. interface表 (48)1. interface_discovery表(空) (49)1. item_condition表 (50)1. item_discovery表 (50)1. item_preproc表 (51)1. items表 (51)1. items_applications表 (55)1. maintenances表(空) (56)1. maintenances_groups表(空) (56)1. maintenances_hosts表(空) (57)1. mappings表 (57)1. media表 (58)1. media_type表 (59)1. opcommand表(空) (60)1. opcommand_grp表(空) (61)1. opcommand_hst表(空) (62)1. opconditions表 (62)1. operations表 (64)1. opgroup表 (65)1. opinventory表(空) (65)1. opmessage表 (66)1. opmessage_grp表 (66)1. opmessage_usr表 (67)1. optemplate表 (67)1. problem表 (68)1. problem_tag表(空) (68)1. profiles表 (69)1. proxy_autoreg_host表(空) (70)1. proxy_dhistory表(空) (71)1. proxy_history表(空) (71)1. regexps表 (72)1. rights表 (72)1. screen_user表(空) (73)1. screen_usrgrp表(空) (73)1. screens表 (74)1. screens_items表 (74)1. scripts表 (77)1. service_alarms表(空) (78)1. services表(空) (78)1. services_links表(空) (79)1. services_times表(空) (80)1. sessions表 (80)1. slides表(空) (81)1. slideshow_user表(空) (81)1. slideshow_usrgrp表(空) (81)1. slideshows表(空) (82)1. sysmap_element_trigger表(空) (82)1. sysmap_element_url表(空) (83)1. sysmap_shape表 (83)1. sysmap_url表(空) (84)1. sysmap_user表(空) (85)1. sysmap_usrgrp表(空) (85)1. sysmaps表 (86)1. sysmaps_link_triggers表(空) (89)1. sysmaps_links表(空) (89)1. task表(空) (90)1. task_acknowledge表(空) (91)1. task_close_problem表(空) (91)1. task_remote_command表(空) (91)1. timeperiods表(空) (92)1. trends表 (93)1. trends_uint表 (94)1. trigger_depends表 (94)1. trigger_discovery表 (94)1. trigger_tag表(空) (95)1. triggers表 (95)1. users表 (96)1. users_groups表 (98)1. usrgrp表 (98)1. valuemaps表 (99)1. widget表 (99)1. widget_field表 (99)一、触发器(trigger)状态发生变化后,即产生某个事件(event)管理员需要对这些状态变化进行确认(acknowledges)表。
zabbix数据库说明

eventid:事件的id
clock:事件发生的时间戳
8、alerts表:
alertid:报警id
eventid:事件id
clock:时间戳
message:报警内容
triggerid
description 描述
status 触发器状态,值为1表示未启动
12、actions表,实现报警的操作
actionid
name 报警的组名
def_shortdata 触发条件
def_longdata 触发动作
Zabbix数据库常用表结构
1、hosts表:hosts表是Zabbix当前正在监控的服务器的相关信息
hostid:被监控服务器id
host:被监控服务器名称
ip:被监控服务器的ip
2、items表:监控项的相关信息
Itemid:监控项的id
hostid:该监控项监控的服务器id,对应于hosts表的hostid
description:监控项的描述
key_:监控的key值
3、history表:存储了详细的历史监控信息,
itemid:监控项的id,对应于items表的itemid
clock:监控数据采集时的时间戳
value:监控到的数据
4、trends表:存储的趋势数据
itemid:监控项的id,对应于items表的itemid
clock:
5、graphs表:每个监控项有一个对应的监控图,这是监控图的信息表
status:值为1表示已确认
9、screens表,监控图像的分组信息
Zabbix的history相关数据表数据太大,执行表分区操作过程

Zabbix的history相关数据表数据太⼤,执⾏表分区操作过程⼀、查询zabbix数据库⼤⼩mysql> select table_schema, concat(truncate(sum(data_length)/1024/1024,2),' mb') as data_size,concat(truncate(sum(index_length)/1024/1024,2),'mb') as index_size from information_schema.tables group by table_sc +--------------------+------------+------------+| table_schema | data_size | index_size |+--------------------+------------+------------+| zabbix | 8326.06 mb | 3031.85mb || jumpserver | 26.57 mb | 8.21mb || mysql | 2.49 mb | 0.21mb || information_schema | 0.15 mb | 0.00mb || sys | 0.01 mb | 0.00mb || performance_schema | 0.00 mb | 0.00mb |+--------------------+------------+------------+6 rows in set (0.40 sec)发现Zabbix数据占⽤了8G空间⼆、查询Zabbix数据库⾥所有表⼤⼩mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb,table_rows from information_schema.tables where table_schema='zabbix' order by total_mb desc;+----------------------------+---------------+------------+| table_name | total_mb | table_rows |+----------------------------+---------------+------------+| history_uint | 5487.29687500 | 56075683 || history | 4843.39062500 | 51787332 || trends_uint | 526.92187500 | 7440029 || history_str | 251.39062500 | 2393973 || trends | 215.87500000 | 2978883 || items | 6.21875000 | 10033 || events | 4.93750000 | 7922 || alerts | 4.67187500 | 5030 || items_applications | 2.35937500 | 11510 || triggers | 1.89062500 | 4359 || auditlog | 1.85937500 | 6803 || images | 1.53125000 | 138 || functions | 0.67187500 | 4746 || item_discovery | 0.57812500 | 3921 || graphs_items | 0.51562500 | 3773 || graphs | 0.50000000 | 1561 || auditlog_details | 0.42187500 | 2620 || event_recovery | 0.32812500 | 2936 || applications | 0.29687500 | 2345 || item_preproc | 0.29687500 | 3668 || application_template | 0.28125000 | 1989 || sessions | 0.23437500 | 1064 || hosts | 0.17187500 | 167 || profiles | 0.15625000 | 564 || sysmaps_elements | 0.15625000 | 95 || mappings | 0.12500000 | 820 || widget_field | 0.10937500 | 170 || graph_discovery | 0.10937500 | 887 || problem | 0.09375000 | 104 || item_condition | 0.07812500 | 446 || sysmaps | 0.07812500 | 13 || trigger_depends | 0.07812500 | 401 || httptest | 0.07812500 | 41 || event_suppress | 0.06250000 | 0 || escalations | 0.06250000 | 8 || sysmaps_links | 0.06250000 | 0 || scripts | 0.06250000 | 3 || trigger_discovery | 0.06250000 | 648 || hostmacro | 0.06250000 | 297 || group_prototype | 0.06250000 | 7 || acknowledges | 0.06250000 | 207 || slides | 0.04687500 | 0 || rights | 0.04687500 | 4 || maintenances_groups | 0.04687500 | 0 || host_discovery | 0.04687500 | 2 || httpstepitem | 0.04687500 | 123 || item_application_prototype | 0.04687500 | 23 || autoreg_host | 0.04687500 | 0 || task | 0.04687500 | 0 || maintenances | 0.04687500 | 0 || dservices | 0.04687500 | 30 || sysmap_element_trigger | 0.04687500 | 0 || tag_filter | 0.04687500 | 0 || drules | 0.04687500 | 8 || slideshows | 0.04687500 | 0 || users_groups | 0.04687500 | 5 || services_links | 0.04687500 | 0 || opcommand_hst | 0.04687500 | 0 || optemplate | 0.04687500 | 0 || interface | 0.04687500 | 82 || slideshow_usrgrp | 0.04687500 | 0 || opcommand_grp | 0.04687500 | 0 || opmessage_usr | 0.04687500 | 22 || sysmaps_link_triggers | 0.04687500 | 0 || service_alarms | 0.04687500 | 0 || opmessage_grp | 0.04687500 | 4 || hosts_templates | 0.04687500 | 263 || icon_mapping | 0.04687500 | 0 || application_prototype | 0.04687500 | 23 || dashboard_usrgrp | 0.04687500 | 0 || media | 0.04687500 | 9 || hosts_groups | 0.04687500 | 211 || icon_map | 0.04687500 | 0 || application_discovery | 0.04687500 | 8 || sysmap_usrgrp | 0.04687500 | 0 || dashboard_user | 0.04687500 | 0 || opgroup | 0.04687500 | 0 || httptestitem | 0.04687500 | 123 || sysmap_user | 0.04687500 | 0 || screens | 0.04687500 | 12 || actions | 0.04687500 | 16 || screen_usrgrp | 0.04687500 | 0 || maintenances_windows | 0.04687500 | 0 || correlation | 0.04687500 | 0 || slideshow_user | 0.04687500 | 0 || config | 0.04687500 | 0 || screen_user | 0.04687500 | 0 || maintenances_hosts | 0.04687500 | 0 || group_discovery | 0.03125000 | 0 || conditions | 0.03125000 | 30 || sysmap_element_url | 0.03125000 | 0 || problem_tag | 0.03125000 | 0 || regexps | 0.03125000 | 5 || httpstep_field | 0.03125000 | 26 || interface_discovery | 0.03125000 | 0 || services_times | 0.03125000 | 0 || maintenance_tag | 0.03125000 | 0 || history_text | 0.03125000 | 22 || graph_theme | 0.03125000 | 4 || httpstep | 0.03125000 | 41 || dhosts | 0.03125000 | 31 || widget | 0.03125000 | 23 || users | 0.03125000 | 3 || services | 0.03125000 | 0 || hstgrp | 0.03125000 | 27 || history_log | 0.03125000 | 0 || dchecks | 0.03125000 | 8 || valuemaps | 0.03125000 | 75 || opcommand | 0.03125000 | 0 || usrgrp | 0.03125000 | 8 || media_type | 0.03125000 | 11 || opmessage | 0.03125000 | 30 || globalmacro | 0.03125000 | 0 || trigger_tag | 0.03125000 | 0 || screens_items | 0.03125000 | 51 || proxy_history | 0.03125000 | 0 || corr_condition_group | 0.03125000 | 0 || expressions | 0.03125000 | 10 || dashboard | 0.03125000 | 3 || proxy_dhistory | 0.03125000 | 0 || corr_condition | 0.03125000 | 0 || operations | 0.03125000 | 32 || httptest_field | 0.03125000 | 0 || sysmap_url | 0.03125000 | 0 || proxy_autoreg_host | 0.03125000 | 0 || sysmap_shape | 0.03125000 | 0 || opconditions | 0.03125000 | 0 || event_tag | 0.03125000 | 0 || corr_operation | 0.03125000 | 0 || timeperiods | 0.01562500 | 0 || corr_condition_tagvalue | 0.01562500 | 0 || task_remote_command_result | 0.01562500 | 0 || corr_condition_tagpair | 0.01562500 | 0 || task_remote_command | 0.01562500 | 0 || corr_condition_tag | 0.01562500 | 0 || task_close_problem | 0.01562500 | 0 || task_check_now | 0.01562500 | 0 || housekeeper | 0.01562500 | 0 || ids | 0.01562500 | 52 || globalvars | 0.01562500 | 0 || dbversion | 0.01562500 | 0 || task_acknowledge | 0.01562500 | 0 || opinventory | 0.01562500 | 0 || host_inventory | 0.01562500 | 20 |+----------------------------+---------------+------------+144 rows in set (0.02 sec)mysql>发现history和trends相关表数据量很⼤,⼀个是历史数据,⼀个是趋势数据需要对这些表进⾏分区操作,提⾼效率三、下载分区脚本drwxr-xr-x. 4 root root 4096 12⽉ 26 2018 share[root@zabbix_server zabbix-4.0.3]# wget https:///zabbix/partitiontables_gt_zbx34.sh --2019-06-28 11:20:28-- https:///zabbix/partitiontables_gt_zbx34.sh正在解析主机 ... 222.186.135.67正在连接 |222.186.135.67|:443... 已连接。
zabbix表达式详解

zabbix表达式详解Zabbix是一款流行的网络监控系统,它可以通过各种方式监控网络设备、服务器和应用程序的性能和可用性。
在Zabbix中,表达式是一种用于定义监控项的规则,它可以根据不同的条件和操作符来计算结果。
下面是对Zabbix表达式进行详细解释的一些重要方面。
1.表达式语法:Zabbix表达式采用类似于SQL的语法结构,包含函数、操作符和变量。
表达式可以包含多个函数和操作符,它们可以嵌套和组合在一起,以实现更复杂的监控项计算。
2.函数:Zabbix提供了各种函数,用于处理不同类型的监控数据。
常见的函数包括avg、min、max、last等,用于计算平均值、最小值、最大值和最近值。
此外,还有一些特殊的函数,如count用于计算符合条件的监控数据的数量,sum用于计算符合条件的监控数据的总和。
3.操作符:Zabbix支持各种操作符,用于对监控数据进行比较和计算。
常见的操作符包括等于(=)、不等于(<>)、大于(>)、小于(<)、大于等于(>=)、小于等于(<=)等。
此外,还有一些特殊的操作符,如and、or、not等,用于组合多个条件。
4.变量:Zabbix表达式中可以使用各种变量,用于表示监控数据和其他相关信息。
常见的变量包括{$ITEM.VALUE}用于表示监控项的值,{$HOSTNAME}用于表示主机名,{$TRIGGER.ID}用于表示触发器的ID等。
通过使用变量,可以实现对不同监控项和触发器的灵活处理。
5.触发器表达式:Zabbix的触发器是基于表达式的,它定义了在何种条件下触发告警。
触发器表达式使用了Zabbix表达式语法,并可以包含各种函数、操作符和变量。
触发器表达式可以根据监控项的值、时间范围和其他条件来计算出一个布尔值,如果满足条件,则触发器被触发,并触发相应的告警。
6.举例说明:下面是一个示例表达式,用于计算某个监控项的平均值是否超过了某个阈值:avg({$ITEM.VALUE}) > 100在这个表达式中,avg函数用于计算监控项的平均值,{$ITEM.VALUE}表示监控项的值,>操作符用于比较两个值的大小,100表示阈值。