zabbix历史数据相关表研究

zabbix历史数据相关表研究

history和trends相关表

history和trends都是存储历史数据的地方。一般是通过监控项(item)配置里、匹配更新监控项(item)和设置HouseKeeper tasks来设置保留数据的时长。

Housekeeper 会定期删除过期的数据。如果不是特别有意义,建议你把保留时间设置短一些, 如果想看以前的数 据图怎么办?这里趋势数据就派上用场了,一般只要小时平均即可这样话趋势据保留久一点即可,趋势数据的计算源数据来自history表。如果将history设置为0那么就只会获取item的值然后用于触发器,不会存历史数据到数据库。

监控项前端配置:

  • history相关表

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

      history 表存放信息类型为浮点数的监控项历史数据,类型在配置监控项是指定

      itemid: 监控项唯一标识id

      clock: 时间戳整数部分

      value: 监控项的值

      ns: 纳秒数

      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 |
      +--------+------------+-----+-----------+-----------+-----------+

原文地址:https://www.cnblogs.com/liao-lin/p/10207374.html

时间: 2024-10-28 22:03:02

zabbix历史数据相关表研究的相关文章

zabbix 历史数据清理及libdata1文件过大处理

一 历史数据清理 停止相关服务,避免写入数据 /etc/init.d/zabbix-server stop /etc/init.d/httpd stop 清空历史数据 mysql -uroot -p use zabbix; truncate tablehistory; optimize tablehistory; truncate tablehistory_uint; optimize tablehistory_uint; truncate tabletrends; optimize table

清理 zabbix 历史数据, 缩减 mysql 空间

zabbix 由于历史数据过大, 因此导致磁盘空间暴涨,  下面是结局方法步骤 1. 停止 ZABBIX SERER 操作 [plain] view plaincopyprint? [[email protected] ~]# killall zabbix_server [[email protected] ~]# lsof -i:10051 2. 停止 mysql 操作 [plain] view plaincopyprint? [[email protected] dbdat]# mysqla

zabbix历史数据清理

1.停止相关服务,避免写入数据 service zabbix_server stop service httpd stop ****************************************** $ sudo /etc/init.d/zabbix-server stop $ sudo /etc/init.d/apache2 stop ********************************************* 2.执行备份数据库脚本 sh dbbackup.sh 3.

清理zabbix历史数据

清理脚本 #!/bin/bash Date=`date -d $(date -d "-30 day" +%Y%m%d) +%s` /usr/local/mysql/bin/mysql --login-path=zabbix -e" use zabbix; DELETE FROM history WHERE 'clock' < $Date; optimize table history; DELETE FROM history_str WHERE 'clock' <

zabbix的历史数据存储到elasticsearch中

基本配置项 https://www.jianshu.com/p/bffca8128e8f 官方说这个实验性的功能支持es的版本是5.0.x - > 6.1.x,如果使用早期或更高版本的Elasticsearch,某些功能可能无法按预期工作. 测试环境的es版本是6.2.4,zabbix为4.0,也能完成zabbix的历史数据对接. 在zabbix server端配置historystorageurl为es数据库的url,同时在zabbix.conf.php中配值es的相关配置,zabbix历史数

ZABBIX企业监控实践(1):ZABBIX详细部署过程

前言: 从2014年15日,那时我刚刚开始接触ZABBIX,到现在刚好整整一年时间,这一年里,谈不上对ZABBIX进行深入研究,接触过两个ZABBIX的项目,平时或多或少的对这两个项目进行修修补补.直到最近的两个月内,公司决定采用ZABBIX进行二次开发成自己的产品(之前一直在SCOM与ZABBIX之间纠结),所以有了充足的时间对ZABBIX进行系统学习,逐步对ZABBIX有了更深入的了解,也积累了一些学习笔记. 最近打算整理一下笔记,对这年来关于ZABBIX的知识做一些梳理,并将尽量围绕项目要

zabbix报警逻辑初探

zabbix报警逻辑初探 首先贴出一张网上找的一张关于zabbix报警相关表结构及表关联逻辑图: actions表 actions表对应前端配置是动作(actions) action由condition(条件)和operations(操作)组成.当满足指定的条件,然后执行操作.发送内容在动作里配置(比如默认情况下没有加上报警产生时间,可以人为加上去). MariaDB [rtm]> desc actions; +---------------+---------------------+----

zabbix详解(一)

zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供柔软的通知机制以让系统管理员快速定位/解决存在的各种问题. zabbix由3部分构成,zabbixserver.可选组件zabbix proxy.可选组件zabbix agent. zabbix server可以通过SNMP,zabbix agent,,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功

zabbix 数据库数据清理

背景由于zabbix历史数据过大,导致占用过多磁盘空间,需清理数据,释放空间 1.查看表占用空间情况 SELECT table_name AS "Tables", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = 'zabbix' ORDER BY (data_length +