近期公司准备对zabbix监控告警进行完善,之前的好多阈值设置不合理,现在分配风控部门的同事与我合作,一块做这个事情;风控部门的同事主要对zabbix监控的历史数据进行分析,建模,以设定一个较合理的阈值;我的任务是先从zabbix数据库中取出相关监控项的历史数据,比如一个月的数据;之前不知道怎么取数,研究了两天,重于有点收获了,特此记录下取出历史数据的过程,如有错误,还请指出;

use zabbix;

1、先在hosts表中取出被监控主机的主机ip和主机id;

MariaDB [zabbix]> select host,hostid from hosts where host='10.20.8.100';
+-------------+--------+
| host        | hostid |
+-------------+--------+
| 10.20.8.100 |  10172 |
+-------------+--------+
1 row in set (0.00 sec)

2、利用上面查处的hostid在items表中查询该主机有那些监控项,itemid为监控项的id,name为监控项的名称,key_为键值,也就是表达式,怎么对监控项取值;

MariaDB [zabbix]> select itemid,name,key_ from items where hostid=10172;
+--------+------------------------------------------------------------------+-------------------------------------------+
| itemid | name                                                             | key_                                      |
+--------+------------------------------------------------------------------+-------------------------------------------+
|  36319 | Host name of zabbix_agentd running                               | agent.hostname                            |
|  36320 | Agent ping                                                       | agent.ping                                |
|  36321 | Version of zabbix_agent(d) running                               | agent.version                             |
|  36322 | Maximum number of opened files                                   | kernel.maxfiles                           |
|  36323 | Maximum number of processes                                      | kernel.maxproc                            |
|  36324 | Network interface discovery                                      | net.if.discovery                          |
|  39561 | Incoming network traffic on $1                                   | net.if.in[eno16777984]                    |
|  36325 | Incoming network traffic on $1                                   | net.if.in[{#IFNAME}]                      |
|  39562 | Outgoing network traffic on $1                                   | net.if.out[eno16777984]                   |
|  36326 | Outgoing network traffic on $1                                   | net.if.out[{#IFNAME}]                     |
|  52385 | nginx status server accepts                                      | nginx.status[accepts]                     |
|  52386 | nginx status connections active                                  | nginx.status[active]                      |
|  52387 | nginx status server handled                                      | nginx.status[handled]                     |
|  52388 | nginx status PING                                                | nginx.status[ping]                        |
|  52389 | nginx status connections reading                                 | nginx.status[reading]                     |
|  52390 | nginx status server requests                                     | nginx.status[requests]                    |
|  52391 | nginx status connections waiting                                 | nginx.status[waiting]                     |
|  52392 | nginx status connections writing                                 | nginx.status[writing]                     |
|  36327 | Number of running processes                                      | proc.num[,,run]                           |
|  36328 | Number of processes                                              | proc.num[]                                |
|  36329 | Host boot time                                                   | system.boottime                           |
|  36330 | Interrupts per second                                            | system.cpu.intr                           |
|  36331 | Processor load (15 min average per core)                         | system.cpu.load[all,avg15]                |
|  36332 | Processor load (1 min average per core)                          | system.cpu.load[all,avg1]                 |
|  36333 | Processor load (5 min average per core)                          | system.cpu.load[all,avg5]                 |
|  36334 | Context switches per second                                      | system.cpu.switches                       |
|  36335 | CPU $2 time                                                      | system.cpu.util[,idle]                    |
|  36336 | CPU $2 time                                                      | system.cpu.util[,interrupt]               |
|  36337 | CPU $2 time                                                      | system.cpu.util[,iowait]                  |
|  36338 | CPU $2 time                                                      | system.cpu.util[,nice]                    |
|  36339 | CPU $2 time                                                      | system.cpu.util[,softirq]                 |
|  36340 | CPU $2 time                                                      | system.cpu.util[,steal]                   |
|  36341 | CPU $2 time                                                      | system.cpu.util[,system]                  |
|  36342 | CPU $2 time                                                      | system.cpu.util[,user]                    |
|  36343 | Host name                                                        | system.hostname                           |
|  36344 | Host local time                                                  | system.localtime                          |
|  36345 | Free swap space                                                  | system.swap.size[,free]                   |
|  36346 | Free swap space in %                                             | system.swap.size[,pfree]                  |
|  36347 | System information                                               | system.uname                              |
|  36348 | System uptime                                                    | system.uptime                             |
|  36349 | Number of logged in users                                        | system.users.num                          |
| 128437 | tomcat报错                                                       | tomcat_monitor                            |
|  36350 | Checksum of $1                                                   | vfs.file.cksum[/etc/passwd]               |
|  36351 | Mounted filesystem discovery                                     | vfs.fs.discovery                          |
|  39563 | Free inodes on $1 (percentage)                                   | vfs.fs.inode[/,pfree]                     |
|  39564 | Free inodes on $1 (percentage)                                   | vfs.fs.inode[/boot,pfree]                 |
|  52913 | Free inodes on $1 (percentage)                                   | vfs.fs.inode[/data/lifeCircleMerch,pfree] |
|  36352 | Free inodes on $1 (percentage)                                   | vfs.fs.inode[{#FSNAME},pfree]             |
|  39565 | Free disk space on $1                                            | vfs.fs.size[/,free]                       |
|  39567 | Free disk space on $1 (percentage)                               | vfs.fs.size[/,pfree]                      |
|  39569 | Total disk space on $1                                           | vfs.fs.size[/,total]                      |
|  39571 | Used disk space on $1                                            | vfs.fs.size[/,used]                       |
|  39566 | Free disk space on $1                                            | vfs.fs.size[/boot,free]                   |
|  39568 | Free disk space on $1 (percentage)                               | vfs.fs.size[/boot,pfree]                  |
|  39570 | Total disk space on $1                                           | vfs.fs.size[/boot,total]                  |
|  39572 | Used disk space on $1                                            | vfs.fs.size[/boot,used]                   |
|  52914 | Free disk space on $1                                            | vfs.fs.size[/data/lifeCircleMerch,free]   |
|  52915 | Free disk space on $1 (percentage)                               | vfs.fs.size[/data/lifeCircleMerch,pfree]  |
|  52916 | Total disk space on $1                                           | vfs.fs.size[/data/lifeCircleMerch,total]  |
|  52917 | Used disk space on $1                                            | vfs.fs.size[/data/lifeCircleMerch,used]   |
|  36353 | Free disk space on $1                                            | vfs.fs.size[{#FSNAME},free]               |
|  36354 | Free disk space on $1 (percentage)                               | vfs.fs.size[{#FSNAME},pfree]              |
|  36355 | Total disk space on $1                                           | vfs.fs.size[{#FSNAME},total]              |
|  36356 | Used disk space on $1                                            | vfs.fs.size[{#FSNAME},used]               |
|  39676 | Inactive + cached + free memory                                  | vm.memory.size[available]                 |
|  39677 | Cache for things like file system metadata                       | vm.memory.size[buffers]                   |
|  39678 | Cache for various things                                         | vm.memory.size[cached]                    |
|  39679 | Memory that is readily available to any entity requesting memory | vm.memory.size[free]                      |
|  39680 | Inactive + cached + free memory in relation to 'total' in %      | vm.memory.size[pavailable]                |
|  39681 | Active + wired memory in relation to total in %                  | vm.memory.size[pused]                     |
|  39682 | Total physical memory available                                  | vm.memory.size[total]                     |
|  39683 | Active + wired memory                                            | vm.memory.size[used]                      |
+--------+------------------------------------------------------------------+-------------------------------------------+
72 rows in set (0.00 sec)

3、以下面的监控项为例子,进行取值历史数据

监控项:CPU user time
| itemid | name                                                             | key_                                      |
|  36342 | CPU $2 time                                                      | system.cpu.util[,user]                    |

Zabbix中存储历史数据的表是以history开头的,目前zabbix 4.2 中主要有以下几张表。

history Numeric(float)
history_log -log
history_str -Character
history_text -text
history_uint -Numeric(unsigned)

MariaDB [zabbix]> desc history;
+--------+---------------------+------+-----+---------+-------+
| Field  | Type                | Null | Key | Default | Extra |
+--------+---------------------+------+-----+---------+-------+
| itemid | bigint(20) unsigned | NO   | MUL | NULL    |监控项id|
| clock  | int(11)             | NO   |     | 0       |时间戳  |
| value  | double(16,4)        | NO   |     | 0.0000  |监控项值|
| ns     | int(11)             | NO   |     | 0       |       |
+--------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

查询半个月的数据

select itemid,from_unixtime(clock) as time,value from history where itemid=36342 and clock >= unix_timestamp('2019/05/01 00:00:00') and clock <= unix_timestamp('2019/05/16 00:00:00');
+--------+---------------------+---------+
| itemid | time                | value   |
+--------+---------------------+---------+
|  36342 | 2019-05-08 20:39:42 |  2.8362 |
|  36342 | 2019-05-08 20:40:42 |  3.4503 |
|  36342 | 2019-05-08 20:41:42 |  2.7704 |
|  36342 | 2019-05-08 20:42:42 |  2.5180 |
|  36342 | 2019-05-08 20:43:42 |  2.5769 |
|  36342 | 2019-05-08 20:44:42 |  2.7991 |
|  36342 | 2019-05-08 20:45:42 |  2.9668 |
|  36342 | 2019-05-08 20:46:42 |  2.4573 |
|  36342 | 2019-05-08 20:47:42 |  2.4801 |
|  36342 | 2019-05-08 20:48:42 |  2.4218 |
|  36342 | 2019-05-08 20:49:42 |  2.5934 |
|  36342 | 2019-05-08 20:50:42 |  3.5542 |
|  36342 | 2019-05-08 20:51:42 |  2.7452 |
|  36342 | 2019-05-08 20:52:42 |  2.4514 |
|  36342 | 2019-05-08 20:53:42 |  2.4313 |
|  36342 | 2019-05-08 20:54:42 |  2.4126 |
|  36342 | 2019-05-08 20:55:42 |  3.2328 |
|  36342 | 2019-05-08 20:56:42 |  2.7098 |
|  36342 | 2019-05-08 20:57:42 |  2.9196 |
|  36342 | 2019-05-08 20:58:42 |  2.5210 |
|  36342 | 2019-05-08 20:59:42 |  2.3487 |
|  36342 | 2019-05-08 21:00:42 |  2.6845 |
|  36342 | 2019-05-08 21:01:42 |  2.1861 |
|  36342 | 2019-05-08 21:02:42 |  2.1778 |
|  36342 | 2019-05-08 21:03:42 |  2.6672 |
|  36342 | 2019-05-08 21:04:42 |  2.4291 |
|  36342 | 2019-05-08 21:05:42 |  2.9483 |
|  36342 | 2019-05-08 21:06:42 |  2.3956 |
|  36342 | 2019-05-08 21:07:42 |  2.2232 |
|  36342 | 2019-05-08 21:08:42 |  2.4544 |
|  36342 | 2019-05-08 21:09:42 |  2.2823 |
|  36342 | 2019-05-08 21:10:42 |  2.8147 |
|  36342 | 2019-05-08 21:11:42 |  2.2619 |
|  36342 | 2019-05-08 21:12:42 |  3.3703 |
...............
此处以部分数据作为展示,数据太多

扩张:

from_unixtime()函数是将时间戳转换为格式化时间,人类可读;
unix_timestamp()函数是将格式化时间转换为时间戳,计算机可读;

MariaDB [zabbix]> select * from history limit 3;
+--------+------------+--------+-----------+
| itemid | clock      | value  | ns        |
+--------+------------+--------+-----------+
| 129524 | 1538271759 | 0.0000 | 208189217 |
| 129524 | 1538271879 | 0.0000 |  32806085 |
| 129524 | 1538271998 | 0.0000 | 965794957 |
+--------+------------+--------+-----------+
3 rows in set (0.00 sec)MariaDB [zabbix]> select from_unixtime('1538271759');
+-----------------------------+
| from_unixtime('1538271759') |
+-----------------------------+
| 2018-09-30 09:42:39         |
+-----------------------------+
1 row in set (0.00 sec)MariaDB [zabbix]> select unix_timestamp('2019/05/16 00:00:00');
+---------------------------------------+
| unix_timestamp('2019/05/16 00:00:00') |
+---------------------------------------+
|                            1557936000 |
+---------------------------------------+
1 row in set (0.01 sec)

完毕,待后续有其他的继续更新、、、

参考:https://blog.51cto.com/nanwangting/1048493

附:zabbix根据不同的时间段设置不同的阈值,例如早上09:00:00-晚上21:00:00为白天段;晚上21:00:00到第二天早上09:00:00为夜间段;

zabbix查询历史数据相关推荐

  1. maxwell 查询历史数据命令

    配置config.properties文件 # mysql login info host=hadoop110 user=maxwell password=123456 client_id=maxwe ...

  2. 利用python+zabbix查询服务器利用率

    需求:统计现有服务器的资源利用率,降本增效 方案: 利用现有zabbix监控信息,使用python检索zabbix的mysql库,筛选出可用信息进行计算,倒出表格 问题:zabbix mysql表信息 ...

  3. ctp交易接口股票怎么查询历史数据?

    针对于ctp交易接口股票历史数据的查询,其基本原理就是利用api接口开发子系统最终就是开发完成并暴露一个标准的HTTPAPI接口,并将接口注册和接入到API网关.API设计和开发的核心思想仍然应该是基 ...

  4. zabbix数据库历史数据清除

    2019独角兽企业重金招聘Python工程师标准>>> 线上zabbix用了有点时间了,再加上最近公司业务问题,想把生产上的zabbix数据库瘦身一下. 别说一找,还真有. 先暂停z ...

  5. zabbix清理历史数据

    #停止zabbix-server服务是停止向数据库写入数据,因为在数据清理优化过程中,mysql会锁表. systemctl stop zabbix-server 1. 时间戳转换 #取60天之前的时 ...

  6. Oracle 查询历史数据(转帖)

    回复误删除数据信息. 1.执行 alter table table_name enable row movement; 2.执行 FlashBack table table_name to times ...

  7. oracle 查询 历史数据,利用闪回查看Oracle表历史时刻数据

    利用闪回查看Oracle表历史时刻数据 1.查看表历史时刻数据 select * from tab_test AS OF TIMESTAMP to_timestamp( 利用闪回查看Oracle表历史 ...

  8. api查询所有记录 zabbix_利用zabbix—API查询zabbix监控项历史数据、均值、峰值详细讲解...

    前言: 查询监控项历史数据,最常见的办法就是在页面查询,但是页面只能展现最近的500个数值,如果要查询历史数据比较久远或要形成数据表格进行分析,这个办法就不适用了,但是利用zabbix-API查询za ...

  9. zabbix历史数据mysql_处理Zabbix历史数据库办法一

    一 问题描述 随着Zabbix监控的主机和监控项目增多,Zabbix的历史数据会越来越多,MySQL数据库磁盘空间很容易就爆满,同时Zabbix前端查询数据会变得越来越慢.特别是通过Zabbix的AP ...

  10. @zabbix数据库历史与趋势数据占用优化(mysql存储查询)

    文章目录 1.数据库大小查询 1)数据库大小查询 2)数据导入不记录binlog 3)数据库查看语句 4)mysqldump(逻辑备份) 2.zabbix案例 1)磁盘占用优化 2)优化表的大小 3) ...

最新文章

  1. indesign图片规定在左下角_详解InDesign基本使用方法
  2. AQS基础——多图详解CLH锁的原理与实现
  3. 俄罗斯方块游戏笔记(一)——砖块样式配置窗体
  4. centos7.2 安装mysql5.6_Centos7安装mysql5.6
  5. jQuery子页面刷新父页面--局部刷新+整体刷新 [转]
  6. 数据结构期末复习(四)
  7. CentOS 6.5上安装Confluence 5.4.4
  8. day-60Django
  9. Word如何快速绘制你需要的作文稿纸
  10. 研发管理学习笔记1-研发管理的目标是什么
  11. vue 数据看板大屏适配方案
  12. 黄金比例编程python_python实现黄金分割法
  13. 基于云的胜利冲锋队 团队团队展示
  14. 2022年Google play admob AdSense 第三方收款指南
  15. 子集和问题 算法_LeetCode 题解 | 78.子集
  16. 计算机开机需要注意什么,笔记本电脑第一次开机注意事项
  17. 算法 | 03 字符串(KMP)
  18. 万物皆可电商,生鲜的坎坷之路
  19. Windows7 war3宽屏解决方案
  20. Teamcenter二次开发客户端环境配置

热门文章

  1. 深度学习服务器?深度了解一下!
  2. Photoshop调出美女人体金黄色肌肤
  3. 网易云/QQ音乐歌单转移到Apple Music内
  4. JavaProperties文件操作
  5. 35岁的程序员何去何从?--记PMP考试感悟
  6. Java并发教程(Oracle官方资料) 分享
  7. 从0开发豆果美食小程序——tag组件
  8. 股票投资(炒股)之入门基础知识
  9. Gym - 100886D 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest D - Catenary
  10. 机器学习(课堂笔记)Day01:机器学习相关概念简介