019-zabbix數據庫表詳解


https://www.cnblogs.com/yaoyaojcy/p/10367945.html

 

 

 1. 查看目前zabbix系統所有數據表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
[root@localhost /]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id  is  170786
Server version: 5.5.60-MariaDB MariaDB Server
 
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to clear the current input statement.
 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
5 rows  in  set  (0.01 sec)
 
MariaDB [(none)]> use zabbix
Reading table information  for  completion of table and column names
You can turn off  this  feature to  get  a quicker startup with -A
 
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
interface                   |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
144 rows  in  set  (0.00 sec)
 
MariaDB [zabbix]>

2. 查看hosts數據表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
MariaDB [zabbix]> show create table hosts \G;
*************************** 1. row ***************************
        Table: hosts
Create Table: CREATE TABLE `hosts` (
   `hostid` bigint(20) unsigned NOT NULL,
   `proxy_hostid` bigint(20) unsigned DEFAULT NULL,
   `host` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `status`  int (11) NOT NULL DEFAULT  '0' ,
   `disable_until`  int (11) NOT NULL DEFAULT  '0' ,
   `error` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `available`  int (11) NOT NULL DEFAULT  '0' ,
   `errors_from`  int (11) NOT NULL DEFAULT  '0' ,
   `lastaccess`  int (11) NOT NULL DEFAULT  '0' ,
   `ipmi_authtype`  int (11) NOT NULL DEFAULT  '-1' ,
   `ipmi_privilege`  int (11) NOT NULL DEFAULT  '2' ,
   `ipmi_username` varchar(16) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `ipmi_password` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `ipmi_disable_until`  int (11) NOT NULL DEFAULT  '0' ,
   `ipmi_available`  int (11) NOT NULL DEFAULT  '0' ,
   `snmp_disable_until`  int (11) NOT NULL DEFAULT  '0' ,
   `snmp_available`  int (11) NOT NULL DEFAULT  '0' ,
   `maintenanceid` bigint(20) unsigned DEFAULT NULL,
   `maintenance_status`  int (11) NOT NULL DEFAULT  '0' ,
   `maintenance_type`  int (11) NOT NULL DEFAULT  '0' ,
   `maintenance_from`  int (11) NOT NULL DEFAULT  '0' ,
   `ipmi_errors_from`  int (11) NOT NULL DEFAULT  '0' ,
   `snmp_errors_from`  int (11) NOT NULL DEFAULT  '0' ,
   `ipmi_error` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `snmp_error` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `jmx_disable_until`  int (11) NOT NULL DEFAULT  '0' ,
   `jmx_available`  int (11) NOT NULL DEFAULT  '0' ,
   `jmx_errors_from`  int (11) NOT NULL DEFAULT  '0' ,
   `jmx_error` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `name` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `flags`  int (11) NOT NULL DEFAULT  '0' ,
   `templateid` bigint(20) unsigned DEFAULT NULL,
   `description` text COLLATE utf8_bin NOT NULL,
   `tls_connect`  int (11) NOT NULL DEFAULT  '1' ,
   `tls_accept`  int (11) NOT NULL DEFAULT  '1' ,
   `tls_issuer` varchar(1024) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `tls_subject` varchar(1024) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `tls_psk_identity` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `tls_psk` varchar(512) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `proxy_address` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `auto_compress`  int (11) NOT NULL DEFAULT  '1' ,
   PRIMARY KEY (`hostid`),
   KEY `hosts_1` (`host`),
   KEY `hosts_2` (`status`),
   KEY `hosts_3` (`proxy_hostid`),
   KEY `hosts_4` (`name`),
   KEY `hosts_5` (`maintenanceid`),
   KEY `c_hosts_3` (`templateid`),
   CONSTRAINT `c_hosts_3` FOREIGN KEY (`templateid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE,
   CONSTRAINT `c_hosts_1` FOREIGN KEY (`proxy_hostid`) REFERENCES `hosts` (`hostid`),
   CONSTRAINT `c_hosts_2` FOREIGN KEY (`maintenanceid`) REFERENCES `maintenances` (`maintenanceid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row  in  set  (0.00 sec)
 
ERROR: No query specified

3. 查看interface數據表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MariaDB [zabbix]> show create table  interface  \G;
*************************** 1. row ***************************
        Table:  interface
Create Table: CREATE TABLE ` interface ` (
   `interfaceid` bigint(20) unsigned NOT NULL,
   `hostid` bigint(20) unsigned NOT NULL,
   `main`  int (11) NOT NULL DEFAULT  '0' ,
   `type`  int (11) NOT NULL DEFAULT  '0' ,
   `useip`  int (11) NOT NULL DEFAULT  '1' ,
   `ip` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '127.0.0.1' ,
   `dns` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `port` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '10050' ,
   `bulk`  int (11) NOT NULL DEFAULT  '1' ,
   PRIMARY KEY (`interfaceid`),
   KEY `interface_1` (`hostid`,`type`),
   KEY `interface_2` (`ip`,`dns`),
   CONSTRAINT `c_interface_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row  in  set  (0.00 sec)
 
ERROR: No query specified

 目前zabbix系統監控2台主機:

查看一下hostid 10263 信息: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
MariaDB [zabbix]>  select  from  interface  a inner  join  hosts b  on  a.hostid=b.hostid  where  a.hostid=10263 \G;
*************************** 1. row ***************************
        interfaceid: 3
             hostid: 10263
               main: 1
               type: 2
              useip: 1
                 ip: 172.18.100.25
                dns:
               port: 161
               bulk: 1
             hostid: 10263
       proxy_hostid: NULL
               host: CARLOS_test_100.25
             status: 0
      disable_until: 0
              error:
          available: 0
        errors_from: 0
         lastaccess: 0
      ipmi_authtype: -1
     ipmi_privilege: 2
      ipmi_username:
      ipmi_password:
ipmi_disable_until: 0
     ipmi_available: 0
snmp_disable_until: 0
     snmp_available: 1
      maintenanceid: NULL
maintenance_status: 0
   maintenance_type: 0
   maintenance_from: 0
   ipmi_errors_from: 0
   snmp_errors_from: 0
         ipmi_error:
         snmp_error:
  jmx_disable_until: 0
      jmx_available: 0
    jmx_errors_from: 0
          jmx_error:
               name: CARLOS_test_100.25
              flags: 0
         templateid: NULL
        description:
        tls_connect: 1
         tls_accept: 1
         tls_issuer:
        tls_subject:
   tls_psk_identity:
            tls_psk:
      proxy_address:
      auto_compress: 1

4. 查看items數據表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
MariaDB [zabbix]> show create table items \G;
*************************** 1. row ***************************
        Table: items
Create Table: CREATE TABLE `items` (
   `itemid` bigint(20) unsigned NOT NULL,
   `type`  int (11) NOT NULL DEFAULT  '0' ,
   `snmp_community` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `snmp_oid` varchar(512) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `hostid` bigint(20) unsigned NOT NULL,
   `name` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `key_` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `delay` varchar(1024) COLLATE utf8_bin NOT NULL DEFAULT  '0' ,
   `history` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '90d' ,
   `trends` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '365d' ,
   `status`  int (11) NOT NULL DEFAULT  '0' ,
   `value_type`  int (11) NOT NULL DEFAULT  '0' ,
   `trapper_hosts` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `units` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `snmpv3_securityname` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `snmpv3_securitylevel`  int (11) NOT NULL DEFAULT  '0' ,
   `snmpv3_authpassphrase` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `snmpv3_privpassphrase` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `formula` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `error` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `lastlogsize` bigint(20) unsigned NOT NULL DEFAULT  '0' ,
   `logtimefmt` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `templateid` bigint(20) unsigned DEFAULT NULL,
   `valuemapid` bigint(20) unsigned DEFAULT NULL,
   ` params ` text COLLATE utf8_bin NOT NULL,
   `ipmi_sensor` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `authtype`  int (11) NOT NULL DEFAULT  '0' ,
   `username` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `password` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `publickey` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `privatekey` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `mtime`  int (11) NOT NULL DEFAULT  '0' ,
   `flags`  int (11) NOT NULL DEFAULT  '0' ,
   `interfaceid` bigint(20) unsigned DEFAULT NULL,
   `port` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `description` text COLLATE utf8_bin NOT NULL,
   `inventory_link`  int (11) NOT NULL DEFAULT  '0' ,
   `lifetime` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '30d' ,
   `snmpv3_authprotocol`  int (11) NOT NULL DEFAULT  '0' ,
   `snmpv3_privprotocol`  int (11) NOT NULL DEFAULT  '0' ,
   `state`  int (11) NOT NULL DEFAULT  '0' ,
   `snmpv3_contextname` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `evaltype`  int (11) NOT NULL DEFAULT  '0' ,
   `jmx_endpoint` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `master_itemid` bigint(20) unsigned DEFAULT NULL,
   `timeout` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '3s' ,
   `url` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `query_fields` varchar(2048) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `posts` text COLLATE utf8_bin NOT NULL,
   `status_codes` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '200' ,
   `follow_redirects`  int (11) NOT NULL DEFAULT  '1' ,
   `post_type`  int (11) NOT NULL DEFAULT  '0' ,
   `http_proxy` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `headers` text COLLATE utf8_bin NOT NULL,
   `retrieve_mode`  int (11) NOT NULL DEFAULT  '0' ,
   `request_method`  int (11) NOT NULL DEFAULT  '0' ,
   `output_format`  int (11) NOT NULL DEFAULT  '0' ,
   `ssl_cert_file` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `ssl_key_file` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `ssl_key_password` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT  '' ,
   `verify_peer`  int (11) NOT NULL DEFAULT  '0' ,
   `verify_host`  int (11) NOT NULL DEFAULT  '0' ,
   `allow_traps`  int (11) NOT NULL DEFAULT  '0' ,
   PRIMARY KEY (`itemid`),
   UNIQUE KEY `items_1` (`hostid`,`key_`),
   KEY `items_3` (`status`),
   KEY `items_4` (`templateid`),
   KEY `items_5` (`valuemapid`),
   KEY `items_6` (`interfaceid`),
   KEY `items_7` (`master_itemid`),
   CONSTRAINT `c_items_5` FOREIGN KEY (`master_itemid`) REFERENCES `items` (`itemid`) ON DELETE CASCADE,
   CONSTRAINT `c_items_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE,
   CONSTRAINT `c_items_2` FOREIGN KEY (`templateid`) REFERENCES `items` (`itemid`) ON DELETE CASCADE,
   CONSTRAINT `c_items_3` FOREIGN KEY (`valuemapid`) REFERENCES `valuemaps` (`valuemapid`),
   CONSTRAINT `c_items_4` FOREIGN KEY (`interfaceid`) REFERENCES ` interface ` (`interfaceid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin  

查看當前zabbix系統items數量:

1
select  count(*)  from  interface  a inner  join  hosts b  on  a.hostid=b.hostid inner  join  items c  on  c.hostid=a.hostid  where  a.hostid=10263 \G;

查看當前zabbix系統單台主機key值與cpu相關:

1
2
select  c.key_,b.hostid,a.ip  from  interface  a inner  join  hosts b  on  a.hostid=b.hostid inner  join  items c  on  c.hostid=a.hostid  where  a.hostid=
10263 and c.key_ like  "%cpu%"  \G;

查看一下與主機相關聯的模板數:

1
show tables like  "%host%" ;

1
select  from  hosts_templates;

以上顯示主機hostid=10263一共關聯6個模板,在zabbix頁面確認一下:

5. 查看目前zabbix系統history表:

1
select  from  history

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
MariaDB [zabbix]>  select  from  items  where  itemid=28565 and value_type=0 \G;
*************************** 1. row ***************************
                itemid: 28565
                  type: 3
        snmp_community:
              snmp_oid:
                hostid: 10263
                  name: ICMP response time
                  key_: icmppingsec
                 delay: 60s
               history: 90d
                trends: 365d
                status: 0
            value_type: 0
         trapper_hosts:
                 units:
   snmpv3_securityname:
  snmpv3_securitylevel: 0
snmpv3_authpassphrase:
snmpv3_privpassphrase:
               formula:
                 error:
           lastlogsize: 0
            logtimefmt:
            templateid: 28511
            valuemapid: NULL
                params :
           ipmi_sensor:
              authtype: 0
              username:
              password:
             publickey:
            privatekey:
                 mtime: 0
                 flags: 0
           interfaceid: 3
                  port:
           description:
        inventory_link: 0
              lifetime: 30d
   snmpv3_authprotocol: 0
   snmpv3_privprotocol: 0
                 state: 0
    snmpv3_contextname:
              evaltype: 0
          jmx_endpoint:
         master_itemid: NULL
               timeout: 3s
                   url:
          query_fields:
                 posts:
          status_codes: 200
      follow_redirects: 1
             post_type: 0
            http_proxy:
               headers:
         retrieve_mode: 0
        request_method: 0
         output_format: 0
         ssl_cert_file:
          ssl_key_file:
      ssl_key_password:
           verify_peer: 0
           verify_host: 0
           allow_traps: 0

6. 查看目前zabbix系統triggers表:

 

 

自學Zabbix之路15.1 Zabbix數據庫表結構簡單解析-Hosts表、Hosts_groups表、Interface表

說在前面:

  • 數據庫中的表的名稱都是復數,比如存放Host信息的表的名字是Hosts等。
  • 數據庫操作有風險,一旦出問題會造成Zabbix crash。需要謹慎操作。
  • 普通的查詢可以在備庫上進行。兩邊數據是實時同步的。

概述:

  • Zabbix數據庫共有108個表,表的名稱都是復數的。
  • 針對Zabbix中的每一個資源,都有一張表與其對應,比如hosts表,items表等。
  • 每一張表中都有一個id字段,如hosts表中的hostid,items中的itemid等。而資源之間的關聯關系是通過外鍵來完成的。
  • 資源之間的關聯關系是通過外鍵來完成的。比如host和item的關聯關系,就是在items表中使用hostid與hosts表中的資源進行關聯。

1. Hosts表

“host”就是一台被監控的對象。

Hosts表結構如下:

  • Hostid:唯一標識Host在Zabbix及數據庫中的id。不同表之間的關聯也要用id。
  • Proxy_hostid:若啟用“proxy-server”架構,才會出現被監控機器的proxy_hostid。
  • Host:被監控機器的名字。
  • Dns:DNS的名稱。
  • Useip:是否用ip監控。
  • Port:監控的端口。
  • Status:機器目前的狀態。“0”為正常監控,“1”為disable。
  • disable_util,error,available,errors_from(ipmi_disable_util,ipmi_error…和 snmp_disable_until…都是此類):這幾個都是Zabbix Poller會去修改的值。我看了下poller.c的代碼,當poller在第一次取不到值(根據值的類型不同會更新相應的列,Item類型為snmp就會更新snmp_XXX,默認為“zabbix”類型)的時候,會等15秒(CONFIG_UNREACHABLE_DELAY)來重試,並且日志會顯示“first network error”,如果15秒后依然取不到值,zabbix會在數據庫更新這個host取不到值的信息,即這幾列。並且日志里顯示“another network error”。 
  • Lastacess:表示proxy最后一次工作的時間。這里的“工作”指Zabbix Server收到Proxy數據。
  • Ipmi*、snmp*、jmx*為使用這三種監控方式時的監控記錄。
  • maintenanceid,maintenance_*:這是Zabbix另一個機制Maintaince有關,用於使Host 置於維護狀態而不會報警。

簡單針對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'; 
   得到更新的Host狀態(enable/disable)如下:
         update hosts set status='0' where host='Host_To_Enable'; 
         update hosts set status='1' where host='Host_To_Disable'; 

2.Hosts_groups 表

  hosts_groups保存了host(主機)與host groups(主機組)的關聯關系。

  這部分信息可以在我們自己做一些批量查詢,例如查詢關聯到某個主機組的所有設備的IP 、存活狀態等,進一步去查詢該批量設備的load、IO、mem等統計信息。

3.Interface表 

  Interface表用於存儲每一個host的接口信息,此表與hosts表分離,方便了用戶修改信息與管理。

 

 

自學Zabbix之路15.2 Zabbix數據庫表結構簡單解析-Items表

 Items表記錄了item的所有設置。在Zabbix中,最多的操作就是對items的。如添加監控項、刪除監控項、更新監控配置等。

 

itemid:item的id 

type:item的type,和前端見面配置item的type的對應。數據庫中,這一列的值是0到17的數字,分別代表不同的類型:

  •  0:Zabbix agent 
  •  1:SNMPv1 agent 
  •  2:Zabbix trapper 
  •  3:simple check 
  •  4:SNMPv2 agent 
  •  5:Zabbix internal 
  •  6:SNMPv3 agent 
  •  7:Zabbix agent(active) 
  •  8:Zabbix aggregate  
  •  9:web item 
  • 10:external check 
  • 11:database monitor 
  • 12:IPMI agent 
  • 13:SSH agent 
  • 14:TELNET agent 
  • 15:calculated 
  • 16:JMX agent 
  • 17:SNMP trap 

hostid:item所在的host的hostid。如果該item是屬於template,那么這里顯示的是templateid 

name:item的名字

key_:item的key 

delay:這里的delay,實際就是在配置item時候配置的“Update Interval”

trends:前端配置中的存儲trend的時間

status:item的狀態

  • 0:item是enabled狀態
  • 1:item是disabled狀態
  • 3:numeric unsigned
  • 4:text

value_type:item返回值的類型,配置item時候配置的“Type of Information”

trapper_hosts:當item為trapper類型的時候,記錄了也許發送的host

units: item配置界面中的‘units’

multiplier:針對這個item是否啟用了 ’custom multiplier‘

delta: item配置界面上的‘store value’

snmpv3*: 都是和SNMP3相關的配置

formula:頁面設置item時候“User custom multiplier”配置的數字

error:item的錯誤信息

lastlogsize:針對log和logrt類型的items使用時,記錄上衣系讀取時日志文件的大小

logtimefmt:針對log和logrt有效,配置日志中時間的格式

templateid:記錄Host上item對應的在template上的item的itemid

valuemapid:Item配置界面中選擇“valuemap”的id

delay_flex:Item配置界面中選擇“Fexible interval”的id

params:當需要額外參數item時,記錄這些參數的地方

ipmi_sensor:使用IPMI類型的items需要設定的參數

data_type:Item配置界面中‘datatype’ 選擇item返回的數據類型

authtype:使用SSHI類型的items時有效,選擇SSH登陸的類型

username:使用SSHI類型的items時有效,選擇SSH登陸的用戶名

password:使用SSHI類型的items時有效,選擇SSH登陸的密碼

publickey:使用SSHI類型的items時有效,但是只有當authtype設置we使用publickey時才有效

privatekey:使用SSHI類型的items時有效,但是只有當authtype設置we使用privatekey時才有效

mtime:針對log和logrt有效,配置日志文件的修改時間

flags:

  • 0:表示一個普通的item
  • 4:表示是discover生成的item

interfaceid:當使用hosts類型的item時生效,用來選擇host上不同的interface

port:使用SNMP監控室使用的端口號

description:Item配置界面上的“Description”

inventory_link:如果這個item的值要座位host的inventory,這里填寫的是對應的inventoied

state:當前item的狀態

  • 0:正常
  • 1:not supported 

 

自學Zabbix之路15.3 Zabbix數據庫表結構簡單解析-Triggers表、Applications表、 Mapplings表

 1.Trigger表

 Trigger是zabbix的重要組成部分,相對應的Trigger表也比較復雜。 主要體現在與其他表的關聯關系很強。
 

2. Applicaion表

    Application表用於存儲監控像所屬於的應用

 

 

  • applicationid:為主鍵編號
  • hostid:對應與host的id
  • name:用於存儲application的名稱
  • flag:用於存儲application的狀態。

3 Mappling表

Mappings表用於存儲的應用狀態映射信息,存儲數據時會將不同的值、不同的范圍對應不同的狀態,而用戶關心的正是這些狀態。

自學Zabbix之路15.4 Zabbix數據庫表結構簡單解析-Expressions表、Media表、 Events表 

 1.Expressions表

   Expressions表用於判斷triggers時需要用到的正則表達式,助於合理的進行triggers判斷。

 

2.Media表

  media 保存了某個用戶的media配置項,即對應的告警方式,如郵件等方式。
 

3. Events表

當Zabbix server獲取到一個數據,它就會檢查跟這個item相關的trigger,然后無論是否觸發action,都會生成一個event。

source:event可能由多種源頭生成,這里的source就是記錄了這個event是由於什么事 件而生成的。

  • 0:由trigger生成的event
  • 1:由discovery rule生成的event
  •  2:由agent auto-registration生成的event
  •  3:internal的event

object:這個字段記錄了和event關聯的Zabbix對象。

  • 對於trigger相關的events,這里的值只可能是0
  • 對於discovery相關的event,“1”表示是discovered host,“2”表示是discovered service
  • 對於auto-registration的event,這里值一定是“3”
  • 對於interval的event
    “0”表示trigger,
    “4”表示item,
    “5”表示low-level discovery  

objectid:根據前面object里的定義,這里可能為triggerid,也可能是discovered hostid
ns:在 2.0.0加入這個納秒的記錄的。原因是這樣的,如果只有timestamp,那么這個{ITEM.VALUE}會發生錯亂。
value:和object字段類似,根據source的不同,這里的值有不同的含義
       對於trigger類型的event:

  •           0:trigger的狀態為OK
  •           1:trigger的狀態為PROBLEM 

       對於discovery類型的event:

  • 0:host或者service正在工作
  • 1:host或者service停止工作
  • 2:host或者service被偵測到
  • 3:host或者service丟失了

       對於internal類型的event:

    • 0:normal狀態
    • 1:unknown或者not supported狀態
 
 

自學Zabbix之路15.5 Zabbix數據庫表結構簡單解析-其他 表

 1. Actions表

   actions表記錄了當觸發器觸發時,需要采用的動作。

2.Alerts 表

 alerts 表保存了歷史的告警事件,可以從這個表里面去做一些統計分析,例如某個部門、某人、某類時間的告警統計,以及更深入的故障發生、恢復時間

 3. Config表

 config表保存了全局的參數,前端包括后端也是,很多情況下會查詢改表的參數的,例如用戶的自定義主題、登陸認證類型等,非常重要。

4. Functions 表

 記錄了trigger中使用的表達式,例如max、last、nodata等函數。

5. graphs_items 表

  graphs_items保存了屬於某個圖表的所有的監控項信息。

 

6.profiles 表

 profiles 表保存了用戶的一些配置項。 

 

7.sessions 表

 sessions 表很重要,保存了每個用戶的sessions,在登陸、注銷的時候均會操作該張表的。

 

8.History
 History表用於存儲監控所得的原始數據

 

  • itemid對應與監控項
  • clock為數據的獲取時間,用時間戳表示
  • value為獲取的原始數據
  • ns表示采集到該數據所用的時間

 9.History_str表 

   history_str表用於存儲采集到的數據中需要用字符串記錄的數據。

  • temid對應與監控項
  • clock為數據的獲取時間,用時間戳表示
  • value為獲取的原始數據
  • ns表示采集到該數據所用的時間

 10.Trends 表

   Trends表用於儲存監控的趨勢性數據,若將所有歷史數據保留將占用大量存儲空間,單用戶可能仍需要查看監控對像的趨勢狀態,因此需要用到trends表。

 11.Users 表

  部分用戶配置會在該表中,例如auotlogin、autologout、url、theme等信息。

 

 

表結構和進程:
MariaDB [zabbix]> show tables
    -> ;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |        :存儲問題原因的表
| actions                    |        :存儲自動發現動作的表
| alerts                     |        :報警的表
| application_discovery      |        :應用發現
| application_prototype      |        :應用樣板
| application_template       |        :應用模板
| applications               |        :應用
| auditlog                   |        :操作日志,就是web頁面中的審計日志
| auditlog_details           |        :操作日志詳細
| autoreg_host               |        :自動注冊的主機
| conditions                 |        :條件,具體沒研究,比如觸發器的條件,自動注冊的條件等
| config                     |        :配置,就是web中管理中的一般項目中的所有
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |        :關聯項
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |        :數據庫的版本
| dchecks                    |        :檢測  在自動發現中用的 system.uname  d可以理解為discover的縮寫
| dhosts                     || drules                     |
| dservices                  |
| escalations                |        :報警升級
| event_recovery             |        :恢復的事件
| event_suppress             |        :廢棄的事件
| event_tag                  |        :事件的標簽
| events                     |        :事件
| expressions                |        :正則表達式  就是web中管理中的一般中的正則表達式
| functions                  |        :要跟着triggers 一起看  如下:
###########################################################################################
MariaDB [zabbix]> select * from triggers where triggerid=16255\G;
*************************** 1. row ***************************
          triggerid: 16255
         expression: {18498}>0
        description: /etc/passwd has been changed on {HOST.NAME}
                url: 
             status: 0
              value: 0
           priority: 2
         lastchange: 0
           comments: 
              error: 
         templateid: 10016
               type: 0
              state: 0
              flags: 0
      recovery_mode: 0
recovery_expression: 
   correlation_mode: 0
    correlation_tag: 
       manual_close: 0
            details: 
1 row in set (0.00 sec)


MariaDB [zabbix]> desc functions;
+------------+---------------------+------+-----+---------+-------+
| Field      | Type                | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+-------+
| functionid | bigint(20) unsigned | NO   | PRI | NULL    |       |
| itemid     | bigint(20) unsigned | NO   | MUL | NULL    |       |
| triggerid  | bigint(20) unsigned | NO   | MUL | NULL    |       |
| name       | varchar(12)         | NO   |     |         |       |
| parameter  | varchar(255)        | NO   |     | 0       |       |
+------------+---------------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

MariaDB [zabbix]> select * from functions where functionid=18498\G;
*************************** 1. row ***************************
functionid: 18498
    itemid: 29826
 triggerid: 16255
      name: diff
 parameter: 0
1 row in set (0.00 sec)


MariaDB [zabbix]> 
MariaDB [zabbix]> select * from triggers where triggerid=16250\G;
*************************** 1. row ***************************
          triggerid: 16250
         expression: {18493}>20
        description: Disk I/O is overloaded on {HOST.NAME}
                url: 
             status: 0
              value: 0
           priority: 2
         lastchange: 0
           comments: OS spends significant time waiting for I/O (input/output) operations. It could be indicator of performance issues with storage system.
              error: 
         templateid: 13243
               type: 0
              state: 0
              flags: 0
      recovery_mode: 0
recovery_expression: 
   correlation_mode: 0
    correlation_tag: 
       manual_close: 0
            details: 
1 row in set (0.00 sec)

ERROR: No query specified

MariaDB [zabbix]> select * from functions where functionid=18493\G;
*************************** 1. row ***************************
functionid: 18493
    itemid: 29812
 triggerid: 16250
      name: avg
 parameter: 5m
1 row in set (0.00 sec)

#################################################################################################

| globalmacro                |        :全局的宏
| globalvars                 |        :全局變量
| graph_discovery            |        :圖形的發現
| graph_theme                |        :圖形的主題
| graphs                     |        :圖形
| graphs_items               |        :圖形的監控項
| group_discovery            || group_prototype            |        :組的模型
| history                    |        :存的是浮點數
| history_log                |        :存的是日志
| history_str                |
| history_text               |
| history_uint               |        :存的是無符號的正整數
| host_discovery             |
| host_inventory             |        :資產
| host_tag                   || hostmacro                  |        :主機的宏
| hosts                      |        :主機
| hosts_groups               |        :主機組
| hosts_templates            |        :主機模板
| housekeeper                |        :定期去清數據庫的歷史數據
####################################################################################################
[root@zabbix ~]# ps -ef | grep zabbix_server
zabbix    39375      1  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix    39380  39375  0 15:05 ?        00:00:08 /usr/sbin/zabbix_server: configuration syncer [synced configuration in 0.024709 sec, idle 60 sec]
zabbix    39381  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: housekeeper [deleted 2287 hist/trends, 0 items/triggers, 160 events, 0 sessions, 0 alarms, 0 audit items, 0 records in 0.099492 sec, idle for 1
zabbix    39382  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.000923 sec, idle 59 sec]
zabbix    39383  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000993 sec, idle 5 sec]
zabbix    39385  39375  0 15:05 ?        00:00:04 /usr/sbin/zabbix_server: discoverer #1 [processed 1 rules in 3.025297 sec, performing discovery]
zabbix    39387  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000024 sec, idle 1 sec]
zabbix    39388  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: history syncer #2 [processed 0 values, 0 triggers in 0.000093 sec, idle 1 sec]
zabbix    39389  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000016 sec, idle 1 sec]
zabbix    39390  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: history syncer #4 [processed 1 values, 0 triggers in 0.002126 sec, idle 1 sec]
zabbix    39391  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001176 sec, idle 3 sec]
zabbix    39392  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000069 sec, idle 5 sec]
zabbix    39393  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000015 sec, idle 1 sec]
zabbix    39394  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000318 sec, idle 5 sec]
zabbix    39395  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000010 sec, idle 5 sec]
zabbix    39396  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000020 sec, idle 5 sec]
zabbix    39397  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000010 sec, idle 5 sec]
zabbix    39398  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000032 sec, idle 5 sec]
zabbix    39399  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000039 sec, idle 5 sec]
zabbix    39400  39375  0 15:05 ?        00:00:03 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000043 sec, idle 5 sec]
zabbix    39408  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000346 sec, waiting for connection]
zabbix    39409  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000768 sec, waiting for connection]
zabbix    39410  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000767 sec, waiting for connection]
zabbix    39411  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000578 sec, waiting for connection]
zabbix    39412  39375  0 15:05 ?        00:00:02 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.001200 sec, waiting for connection]
zabbix    39413  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000029 sec, idle 5 sec]
zabbix    39414  39375  0 15:05 ?        00:00:03 /usr/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.008432 sec during 5.008528 sec]
zabbix    39415  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: alerter #1 started
zabbix    39416  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: alerter #2 started
zabbix    39417  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: alerter #3 started
zabbix    39418  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 0 values, idle 5.005733 sec during 5.006085 sec]
zabbix    39419  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: preprocessing worker #1 started
zabbix    39425  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: preprocessing worker #2 started
zabbix    39426  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: preprocessing worker #3 started
zabbix    39427  39375  0 15:05 ?        00:00:01 /usr/sbin/zabbix_server: lld manager #1 [processed 0 LLD rules during 5.008159 sec]
zabbix    39428  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: lld worker #1 [processed 1 LLD rules, idle 750.002220 sec during 750.031470 sec]
zabbix    39429  39375  0 15:05 ?        00:00:00 /usr/sbin/zabbix_server: lld worker #2 [processed 1 LLD rules, idle 748.993248 sec during 749.006637 sec]
#####################################################################################################################

| hstgrp                     |        :主機群組
| httpstep                   || httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |        :圖標
| icon_mapping               || ids                        || images                     |
| interface                  |        :接口
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |        :監控項
| items_applications         |
| lld_macro_path             |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |        :映射值
| media                      |        :媒體
| media_type                 |        :媒體類型
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |        :就是跟99.99%相關的
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |        :系統圖
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |        :趨勢圖
| trends_uint                |
| trigger_depends            |        :觸發器依賴
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
146 rows in set (0.01 sec)

MariaDB [zabbix]> select * from acknowledges;
+---------------+--------+---------+------------+-----------------+--------+--------------+--------------+
| acknowledgeid | userid | eventid | clock      | message         | action | old_severity | new_severity |
+---------------+--------+---------+------------+-----------------+--------+--------------+--------------+
|             1 |      1 |    5405 | 1566893083 | 主機不存在      |      4 |            0 |            0 |
+---------------+--------+---------+------------+-----------------+--------+--------------+--------------+

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM