zabbix歷史數據相關表研究

zabbix歷史數據相關表研究

history和trends相關表

history和trends都是存儲歷史數據的地方。通常是經過監控項(item)配置裏、匹配更新監控項(item)和設置HouseKeeper tasks來設置保留數據的時長。前端

Housekeeper 會按期刪除過時的數據。若是不是特別有意義,建議你把保留時間設置短一些, 若是想看之前的數 據圖怎麼辦?這裏趨勢數據就派上用場了,通常只要小時平均便可這樣話趨勢據保留久一點便可,趨勢數據的計算源數據來自history表。若是將history設置爲0那麼就只會獲取item的值而後用於觸發器,不會存歷史數據到數據庫。數據庫

監控項前端配置:dom

  • history相關表ui

    MariaDB [rtm]> show tables like 'history%';
    +--------------------------+
    | Tables_in_rtm (history%) |
    +--------------------------+
    | history                  |
    | history_log              |
    | history_str              |
    | history_text             |
    | history_uint             |
    +--------------------------+
    • history日誌

      history 表存放信息類型爲浮點數的監控項歷史數據,類型在配置監控項是指定code

      itemid: 監控項惟一標識idblog

      clock: 時間戳整數部分it

      value: 監控項的值event

      ns: 納秒數table

      MariaDB [rtm]> desc history;
      +--------+---------------------+------+-----+---------+-------+
      | Field  | Type                | Null | Key | Default | Extra |
      +--------+---------------------+------+-----+---------+-------+
      | itemid | bigint(20) unsigned | NO   | MUL | NULL    |       |
      | clock  | int(11)             | NO   |     | 0       |       |
      | value  | double(16,4)        | NO   |     | 0.0000  |       |
      | ns     | int(11)             | NO   |     | 0       |       |
      +--------+---------------------+------+-----+---------+-------+
      
      
      MariaDB [rtm]> select * from history limit 10;
      +-----------+------------+---------+----+
      | itemid    | clock      | value   | ns |
      +-----------+------------+---------+----+
      | 300161484 | 1545404400 |  1.9616 |  0 |
      | 300161484 | 1545379200 |  2.3494 |  0 |
      | 300161484 | 1545382800 |  2.7355 |  0 |
      | 300161484 | 1545386400 |  3.3068 |  0 |
      | 300161484 | 1545390000 |  3.2508 |  0 |
      | 300161484 | 1545393600 |  4.2648 |  0 |
      | 300161484 | 1545397200 |  4.0263 |  0 |
      | 300161484 | 1545400800 |  2.7983 |  0 |
      | 300161485 | 1545404400 | 16.8910 |  0 |
      | 300161485 | 1545379200 | 20.5173 |  0 |
      +-----------+------------+---------+----+
    • history_log

      history_log 表存放信息類型爲日誌的監控項歷史數據,類型在配置監控項是指定

      MariaDB [rtm]> desc history_log;
      +------------+---------------------+------+-----+---------+-------+
      | Field      | Type                | Null | Key | Default | Extra |
      +------------+---------------------+------+-----+---------+-------+
      | id         | bigint(20) unsigned | NO   | PRI | NULL    |       |
      | itemid     | bigint(20) unsigned | NO   | MUL | NULL    |       |
      | clock      | int(11)             | NO   |     | 0       |       |
      | timestamp  | int(11)             | NO   |     | 0       |       |
      | source     | varchar(64)         | NO   |     |         |       |
      | severity   | int(11)             | NO   |     | 0       |       |
      | value      | text                | NO   |     | NULL    |       |
      | logeventid | int(11)             | NO   |     | 0       |       |
      | ns         | int(11)             | NO   |     | 0       |       |
      +------------+---------------------+------+-----+---------+-------+
    • history_str

      history_str 表存放信息類型爲字符的監控項歷史數據,類型在配置監控項是指定

      MariaDB [rtm]> desc history_str;
      +--------+---------------------+------+-----+---------+-------+
      | Field  | Type                | Null | Key | Default | Extra |
      +--------+---------------------+------+-----+---------+-------+
      | itemid | bigint(20) unsigned | NO   | MUL | NULL    |       |
      | clock  | int(11)             | NO   |     | 0       |       |
      | value  | varchar(255)        | NO   |     |         |       |
      | ns     | int(11)             | NO   |     | 0       |       |
      +--------+---------------------+------+-----+---------+-------+
      
      
      MariaDB [rtm]> select * from history_str limit 2\G;
      *************************** 1. row ***************************
      itemid: 23307
       clock: 1545384507
       value: localhost.localdomain
          ns: 410719216
      *************************** 2. row ***************************
      itemid: 23312
       clock: 1545384512
       value: Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64
          ns: 411996428
    • history_text

      history_text 表存放信息類型爲文本的監控項歷史數據,類型在配置監控項是指定

      MariaDB [rtm]> desc history_text;
      +--------+---------------------+------+-----+---------+-------+
      | Field  | Type                | Null | Key | Default | Extra |
      +--------+---------------------+------+-----+---------+-------+
      | id     | bigint(20) unsigned | NO   | PRI | NULL    |       |
      | itemid | bigint(20) unsigned | NO   | MUL | NULL    |       |
      | clock  | int(11)             | NO   |     | 0       |       |
      | value  | text                | NO   |     | NULL    |       |
      | ns     | int(11)             | NO   |     | 0       |       |
      +--------+---------------------+------+-----+---------+-------+
      
      
      MariaDB [rtm]> select * from history_text limit 10;
      +---------+--------+------------+---------------------+-----------+
      | id      | itemid | clock      | value               | ns        |
      +---------+--------+------------+---------------------+-----------+
      | 1937748 |  30436 | 1545381354 | 10/11/2017 14:28:06 | 892072527 |
      | 1937749 |  28311 | 1545381364 | N/A                 | 146021861 |
      | 1937750 |  27186 | 1545381374 | N/A                 | 934199968 |
      | 1937751 |  26936 | 1545381376 | N/A                 | 146546842 |
      | 1937752 |  28936 | 1545381378 | N/A                 | 189324808 |
      | 1937753 |  24686 | 1545381380 | N/A                 |  89381118 |
      | 1937754 |  25061 | 1545381383 | N/A                 | 484549259 |
      | 1937755 |  28061 | 1545381385 | N/A                 | 699330874 |
      | 1937756 |  27061 | 1545381389 | N/A                 | 559602805 |
      | 1937757 |  30686 | 1545381391 | N/A                 | 303467948 |
      +---------+--------+------------+---------------------+-----------+
    • history_uint

      history_unit 表存放信息類型爲數字(無正負)的監控項歷史數據,類型在配置監控項是指定

      MariaDB [rtm]> desc history_uint;
      +--------+---------------------+------+-----+---------+-------+
      | Field  | Type                | Null | Key | Default | Extra |
      +--------+---------------------+------+-----+---------+-------+
      | itemid | bigint(20) unsigned | NO   | MUL | NULL    |       |
      | clock  | int(11)             | NO   |     | 0       |       |
      | value  | bigint(20) unsigned | NO   |     | 0       |       |
      | ns     | int(11)             | NO   |     | 0       |       |
      +--------+---------------------+------+-----+---------+-------+
      
      MariaDB [rtm]> select * from history_uint limit 10;
      +-----------+------------+-------+----+
      | itemid    | clock      | value | ns |
      +-----------+------------+-------+----+
      | 100029541 | 1545404700 |  4311 |  0 |
      | 100029541 | 1545405000 |  4276 |  0 |
      | 100029541 | 1545405300 |  4242 |  0 |
      | 100029541 | 1545405600 |  4207 |  0 |
      | 100029541 | 1545405900 |  4172 |  0 |
      | 100029541 | 1545406200 |  4137 |  0 |
      | 100029541 | 1545406500 |  4102 |  0 |
      | 100029541 | 1545406800 |  4067 |  0 |
      | 100029541 | 1545407100 |  4032 |  0 |
      | 100029541 | 1545407400 |  3997 |  0 |
      +-----------+------------+-------+----+
  • trends相關表

    MariaDB [rtm]> show tables like 'trends%';
    +-------------------------+
    | Tables_in_rtm (trends%) |
    +-------------------------+
    | trends                  |
    | trends_uint             |
    +-------------------------+
    • trends

      itemid: 監控項惟一標識id

      clock: 時間戳整數部分

      num: 該小時內用了多少數據用於計算平均值、最小值、最大值

      value_min: 趨勢時間內最小值(趨勢數據時間間隔爲一小時)

      value_avg: 趨勢時間內平均值(趨勢數據時間間隔爲一小時)

      value_max: 趨勢時間內最大值(趨勢數據時間間隔爲一小時)

      MariaDB [rtm]> desc trends;
      +-----------+---------------------+------+-----+---------+-------+
      | Field     | Type                | Null | Key | Default | Extra |
      +-----------+---------------------+------+-----+---------+-------+
      | itemid    | bigint(20) unsigned | NO   | PRI | NULL    |       |
      | clock     | int(11)             | NO   | PRI | 0       |       |
      | num       | int(11)             | NO   |     | 0       |       |
      | value_min | double(16,4)        | NO   |     | 0.0000  |       |
      | value_avg | double(16,4)        | NO   |     | 0.0000  |       |
      | value_max | double(16,4)        | NO   |     | 0.0000  |       |
      +-----------+---------------------+------+-----+---------+-------+
      
      
      MariaDB [rtm]> select * from trends limit 10;
      +--------+------------+-----+-----------+-----------+-----------+
      | itemid | clock      | num | value_min | value_avg | value_max |
      +--------+------------+-----+-----------+-----------+-----------+
      |  23252 | 1538211600 |  60 |    0.0000 |    0.0006 |    0.0169 |
      |  23252 | 1538215200 |  60 |    0.0000 |    0.0008 |    0.0169 |
      |  23252 | 1538218800 |  60 |    0.0000 |    0.0008 |    0.0169 |
      |  23252 | 1538222400 |  60 |    0.0000 |    0.0003 |    0.0169 |
      |  23252 | 1538226000 |  60 |    0.0000 |    0.0008 |    0.0169 |
      |  23252 | 1538229600 |  60 |    0.0000 |    0.0017 |    0.0508 |
      |  23252 | 1538233200 |  60 |    0.0000 |    0.0011 |    0.0169 |
      |  23252 | 1538236800 |  60 |    0.0000 |    0.0014 |    0.0169 |
      |  23252 | 1538240400 |  60 |    0.0000 |    0.0008 |    0.0169 |
      |  23252 | 1538244000 |  60 |    0.0000 |    0.0003 |    0.0169 |
      +--------+------------+-----+-----------+-----------+-----------+
    • trends_unit

      MariaDB [rtm]> desc trends_uint;
      +-----------+---------------------+------+-----+---------+-------+
      | Field     | Type                | Null | Key | Default | Extra |
      +-----------+---------------------+------+-----+---------+-------+
      | itemid    | bigint(20) unsigned | NO   | PRI | NULL    |       |
      | clock     | int(11)             | NO   | PRI | 0       |       |
      | num       | int(11)             | NO   |     | 0       |       |
      | value_min | bigint(20) unsigned | NO   |     | 0       |       |
      | value_avg | bigint(20) unsigned | NO   |     | 0       |       |
      | value_max | bigint(20) unsigned | NO   |     | 0       |       |
      +-----------+---------------------+------+-----+---------+-------+
      
      
      MariaDB [rtm]> select * from trends_uint limit 10;
      +--------+------------+-----+-----------+-----------+-----------+
      | itemid | clock      | num | value_min | value_avg | value_max |
      +--------+------------+-----+-----------+-----------+-----------+
      |  23271 | 1538211600 |   6 |         0 |         0 |         0 |
      |  23271 | 1538215200 |   6 |         0 |         0 |         0 |
      |  23271 | 1538218800 |   6 |         0 |         0 |         0 |
      |  23271 | 1538222400 |   6 |         0 |         0 |         0 |
      |  23271 | 1538226000 |   6 |         0 |         0 |         0 |
      |  23271 | 1538229600 |   6 |         0 |         0 |         0 |
      |  23271 | 1538233200 |   6 |         0 |         0 |         0 |
      |  23271 | 1538236800 |   6 |         0 |         0 |         0 |
      |  23271 | 1538240400 |   6 |         0 |         0 |         0 |
      |  23271 | 1538244000 |   6 |         0 |         0 |         0 |
      +--------+------------+-----+-----------+-----------+-----------+
相關文章
相關標籤/搜索