技术流ken

运维拯救世界

每天五分钟轻松学运维:zabbix自定义监控项目含变量–技术流ken

前言

在上一篇博文中,已经详细演示了如何自定义监控。

本篇博文将再详细演示如果使用传参的方式进行监控。

温故而知新

在模板当中我们可以发现自定义监控有如下两种形式:

1. UserParameter=key,command

2.UserParameter=key[*],command

两种格式的区别即第一个不能接受用户参数,第二个可以接受变量,更加灵活。

自定义监控传参演示

第一步:创建test2.conf文件

[root@ken-node1 ~]# cd /etc/zabbix/zabbix_agentd.d/

[root@ken-node1 zabbix_agentd.d]# ls

userparameter_mysql.conf

[root@ken-node1 zabbix_agentd.d]# touch test2.conf

[root@ken-node1 zabbix_agentd.d]# ls

test2.conf userparameter_mysql.conf

[root@ken-node1 zabbix_agentd.d]# vim test2.conf

第二步:查看内存相关信息

篇幅原因,截取部分

[root@ken-node1 zabbix_agentd.d]# cat /proc/meminfo

MemTotal: 481876 kB

MemFree: 13104 kB

MemAvailable: 117132 kB

Buffers: 32 kB

Cached: 103400 kB

SwapCached: 2180 kB

Active: 159300 kB

Inactive: 180848 kB

Active(anon): 105172 kB

Inactive(anon): 139836 kB

Active(file): 54128 kB

Inactive(file): 41012 kB

Unevictable: 0 kB

Mlocked: 0 kB

SwapTotal: 2097148 kB

SwapFree: 2073076 kB

第三步:编辑自定义文件

[root@ken-node1 zabbix_agentd.d]# vim test2.conf
UserParameter=check.meminfo[*],cat /proc/meminfo | awk -F " +" '/$1/{print $2}'

$1: 表示用户可以传递的参数

$$2: $2表示打印以空格分隔后的第2列,需要前面加个$进行转义,否则会当做用户传递的参数

比如我们想要查看Cached的大小就可以把$1替换为Cached

[root@ken-node1 ~]# cat /proc/meminfo | awk -F " +" '/^Cached/{print $2}'
101372

第四步:重启zabbix客户端

[root@ken-node1 ~]# systemctl restart zabbix-agent

第五步:zabbix服务器端添加监控项

把[]中括号里面的$1替换为你想要监控的项目即可

每天五分钟轻松学运维:zabbix自定义监控项目含变量--技术流ken
每天五分钟轻松学运维:zabbix自定义监控项目含变量--技术流ken
每天五分钟轻松学运维:zabbix自定义监控项目含变量--技术流ken

第六步:查看监控

每天五分钟轻松学运维:zabbix自定义监控项目含变量--技术流ken
每天五分钟轻松学运维:zabbix自定义监控项目含变量--技术流ken

9 thoughts on “每天五分钟轻松学运维:zabbix自定义监控项目含变量–技术流ken

  1. The next time I read a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I know it was my option to read, but I actually thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about something that you might fix when you werent too busy in search of attention.

  2. I am just commenting to let you understand what a awesome experience my wife’s daughter experienced going through your webblog. She came to understand a lot of pieces, including how it is like to possess an amazing helping mindset to let many people just fully grasp selected very confusing subject matter. You undoubtedly surpassed her desires. Many thanks for showing the necessary, healthy, educational as well as cool guidance on the topic to Julie.

  3. I actually wanted to post a small remark to appreciate you for all of the precious tips and tricks you are sharing here. My incredibly long internet search has at the end of the day been paid with reliable concept to go over with my colleagues. I would say that many of us visitors are extremely blessed to live in a remarkable website with many awesome professionals with valuable techniques. I feel quite fortunate to have used your web pages and look forward to some more brilliant moments reading here. Thank you once more for everything.

  4. I have to express some thanks to this writer for rescuing me from this problem. Because of checking through the internet and coming across thoughts which are not pleasant, I figured my entire life was over. Living without the presence of answers to the problems you have sorted out by way of your main short post is a serious case, as well as the kind which could have in a negative way affected my entire career if I hadn’t encountered the blog. Your actual competence and kindness in dealing with a lot of stuff was valuable. I am not sure what I would have done if I had not encountered such a solution like this. I am able to at this time look ahead to my future. Thanks very much for the high quality and result oriented help. I won’t hesitate to endorse your web blog to anybody who needs to have guide on this problem.

  5. I just wanted to construct a quick note to be able to express gratitude to you for those wonderful strategies you are placing at this site. My particularly long internet search has at the end been honored with really good know-how to write about with my friends. I would say that many of us site visitors actually are extremely blessed to dwell in a notable community with many special individuals with useful things. I feel very much privileged to have discovered your web pages and look forward to so many more brilliant moments reading here. Thank you once again for a lot of things.

  6. Thanks a lot for giving everyone an extremely splendid possiblity to read in detail from this blog. It is usually very pleasing and also packed with a lot of fun for me personally and my office fellow workers to search the blog at least three times a week to find out the new guides you have got. And of course, I’m so usually happy considering the surprising techniques you serve. Selected 4 points in this posting are in truth the most suitable we have had.

  7. I precisely needed to thank you very much once again. I do not know what I might have accomplished without the pointers contributed by you regarding such concern. Completely was the alarming setting for me personally, however , coming across a specialised style you solved that forced me to leap with happiness. I will be grateful for this help and wish you know what an amazing job you have been providing teaching many people using your websites. I am certain you have never encountered all of us.

  8. I in addition to my pals happened to be checking out the nice suggestions found on your site then immediately got a terrible suspicion I never thanked the site owner for those strategies. The boys are already so glad to study them and have certainly been loving these things. Thank you for being so thoughtful as well as for deciding on these kinds of remarkable subject areas most people are really wanting to understand about. My personal sincere regret for not expressing appreciation to you sooner.

  9. Thank you for your entire work on this site. My niece take interest in getting into internet research and it’s really easy to understand why. We learn all about the compelling ways you offer functional guidelines by means of your website and cause response from other people on the theme while our simple princess is being taught a whole lot. Have fun with the rest of the year. You have been performing a tremendous job.

发表评论

邮箱地址不会被公开。