https://nagios-plugins.org/doc/guidelines.html

nagios检测信息

host

GPING OK – rtt min/avg/max/mdev = 0.897/0.897/0.897/0.000 ms|time=0.897ms;20;40;; ok=1

service

cpu_user:OK-0% cpu_system:OK-0% cpu_idle:WARNING-99>70% | cpu_user=0%;120;90; cpu_system=0%;100;70; cpu_idle=99%;100;70;

其中性能数据为|后面的斜体部分,格式如下:

'label'=value[UOM];[warn];[crit];[min];[max]

注意事项

1.空格分割标签/值对 例如cpu_user=0%;100;90; cpu_system=0%;100;70; cpu_idle=99%;100;70;

2.label可以包含任何字符

3.单引号可省略,如果label中使用空格、等号和单引号,则需要需要单引号把label括起来。例如’a ‘b’ = c’=0%;100;90;

4.标签可以为任意长度,但最好少于19个字符并且唯一,(RRD有相关方面的限制),并且需要注意NRPE的返回值的限制(译者:好像是4K限制)

5.两个单引号为指定的转义字符?

6.warn, crit, min or max 可以为空(比如,如果没有定义阀值,最大最小值则不适用)并且最后的分号可以省略

7.如果UOM为%,则不需要最大最小值

8.value, min and max只能为负号“-” “0到9” 和小数点“.” 并且单位必须统一 例如:cpu_user=0.5%;99.9;-9;

9.warn and crit必须在某个区间格式,参见2.5章。单位也必须统一

10.UOM必须为以下其中之一

如果未指定,默认为数字(整数和浮点数)(比如用户数,进程数,负载等)

s - 秒 (可以为纳秒us或毫秒ms) cpu_user=0s;100;90; cpu_system=0us;100;70; cpu_idle=0ms;100;70;

% - 百分号 cpu_user=0%;100;90; cpu_system=0%;100;70; cpu_idle=99%;100;70;

B - 字节(可以是KB MB GB TB)cpu_user=0KB;100;90; cpu_system=0MB;100;70; cpu_idle=0B;100;70;

C - 一个计数器 (比如网卡的流量)cpu_user=10c;100;90;

rrdtool 1.4.8以下有bug,会提示'rrdtool.create(rrdfile, '--step', '60', '--start', '-1y', dss, rra) TypeError: argument 5 must be string'

必须升级高版本,用下面这个源 gf-plus

yum install http://mirror.symnds.com/distributions/gf/el/6/gf/x86_64/gf-release-6-10.gf.el6.noarch.rpm

#!/usr/bin/env python
# -*- encoding: utf-8 -*- from flask import Blueprint, render_template, url_for, redirect
import os, re, time, json, rrdtool mod = Blueprint('graph', __name__, template_folder='templates') @mod.route('/', methods=['GET'])
def show_graph():
# hostname, service get from db
hostname = 'wx-j2-5-52'
services = [ \
'linux_connections', \
'linux_diskio_sda1', \
'linux_disk_opt', \
'linux_load', \
'linux_traffic_p1p1', \
'linux_cpu', \
'linux_diskio_sda3', \
'linux_disk_root', \
'linux_memory', \
'host_icmp' \
] return render_template('graph.html', hostname=hostname, services=sorted(services)) # Function create rrd
def create_rrd(rrd_file, perfdata):
ds = []
for label, value, unit in perfdata:
if unit in ['b/s', 'B', 'B/s', 's', 'ms', '']:
ds.append('DS:' + str(label) + ':GAUGE:600:0:1000000000000')
elif unit in ['%']:
ds.append('DS:' + str(label) + ':GAUGE:600:0:100') rra = [
'RRA:AVERAGE:0.5:1:120', # hour
'RRA:AVERAGE:0.5:5:600', # day
'RRA:AVERAGE:0.5:30:700', # week
'RRA:AVERAGE:0.5:120:800', # month
'RRA:AVERAGE:0.5:1440:800', # year
'RRA:MAX:0.5:1:120', # hour
'RRA:MAX:0.5:5:600', # day
'RRA:MAX:0.5:30:700', # week
'RRA:MAX:0.5:120:800', # month
'RRA:MAX:0.5:1440:800', # year
'RRA:MIN:0.5:1:120', # hour
'RRA:MIN:0.5:5:600', # day
'RRA:MIN:0.5:30:700', # week
'RRA:MIN:0.5:120:800', # month
'RRA:MIN:0.5:1440:800', # year
] rrdtool.create(str(rrd_file), '--step', '60', ds, rra) # Function update rrd
def update_rrd(info):
rrd_path = os.path.join('/opt/rrd', 'wx', 'j2', info['host'])
if not os.path.exists(rrd_path):
os.mkdir(rrd_path) if info['type'] == 'host':
rrd_file = os.path.join(rrd_path, 'host_icmp') + '.rrd'
else:
rrd_file = os.path.join(rrd_path, info['service']) + '.rrd' # perfdata:
# rta=36.370ms;500.000;500.000;0; pl=0%;80;80;; rtmax=38.344ms;;;; rtmin=34.979ms;;;;
# or
# 'cached'=21857640448;;;0; 'buffer'=129105920;;;0; 'used'=1640251392;0.00:31974134374.40;0.00:31974134374.40;0;33656983552 perfdata = []
for entry in info['perfdata'].split(' '):
m = re.match("^\'?([\w\s]+)\'?=(\d+\.?\d*)(\D*)$", entry.split(';')[0])
perfdata.append((m.group(1), m.group(2), m.group(3))) if not os.path.exists(rrd_file):
create_rrd(rrd_file, perfdata) ds = ':'.join([ label for label, value, unit in perfdata])
rra = ':'.join([ value for label, value, unit in perfdata]) print rrd_file, ds, rra
rrdtool.update(str(rrd_file), '--template', str(ds), 'N:'+str(rra)) # Function fetch rrd
def fetch_rrd(hostname, service, period):
rrd_path = os.path.join('/opt/rrd', 'wx', 'j2', hostname)
#rrd_path = os.path.join('/home/ken/mule', hostname)
rrd_file = rrd_path + '/' + service + '.rrd' return rrdtool.fetch(str(rrd_file), 'AVERAGE', '--start', str(period))

python-rrdtool的更多相关文章

  1. Python——rrdtool模块的安装

    一.Centos环境yum命令安装 yum install rrdtool rrdtool-devel 二.源码安装 wget https://pypi.python.org/packages/99/ ...

  2. Python与rrdtool的结合模块

    rrdtool(round robin database)工具为环状数据库的存储格式,round robin是一种处理定量数据以及当前元素指针的技术.rrdtool主要用来跟踪对象的变化情况,生成这些 ...

  3. python使用rrdtool时 argument 0 must be string的问题

    在updatev rrdfile时, ret = rrdtool.updatev(filename, ds) 报了argument 0 must be string的异常,经查是因为python 的r ...

  4. Python中使用rrdtool结合Django进行带宽监控

    我们有个网关需要做下带宽监控,能获取这个数据的唯一方法就是登录到管理界面查看.然后咱就写了个模拟登录的爬虫,定时抓取数据用rrdtool存储,最后通过Django来展示.这里就涉及了python的rr ...

  5. rrdtool ubuntu python snmpwalk

    rrdtool install: apt-get install libpango1.0-dev libxml2-dev wget https://packages.debian.org/wheezy ...

  6. ubuntu下安装python各类运维用模块(以后补充用途)

    环境:ubuntu 16.04LTS,python3,python2 已安装:pip3,pip2 注:基于Python自动化运维这本书上介绍的各模块而来 1.python-rrdtool(just f ...

  7. python操作sqlite数据库

    root@cacti:~/box# cat convert.py #!/usr/bin/env python import sqlite3,time,rrdtool,os def boxstatus( ...

  8. Python 初学者 入门 应该学习 python 2 还是 python 3?

    许多刚入门 Python 的朋友都在纠结的的问题是:我应该选择学习 python2 还是 python3? 对此,咪博士的回答是:果断 Python3 ! 可是,还有许多小白朋友仍然犹豫:那为什么还是 ...

  9. python3 rrdtool 使用

    源自 python自动化运维:技术与最佳实践 并做略微修改 安装 yum install python-rrdtoolyum install rrdtool-devel #因为采集用了psutil模块 ...

  10. Python 运维

    1.python解释器提供提供的小工具 1.1 一秒钟启动一个下载服务器 进入要下载文件的目录(shift+鼠标右键可以很快的在当前目录打开一个cmd) python2: python2 -m Sim ...

随机推荐

  1. 树莓派使用 PPA 安装 Java 8

    前言 在树莓派上安装 Java 8,与这篇的操作类似,不过树莓派不支持用 add-apt-repository 自动添加 webupd8team 的源,所以要手动添加. 步骤 在 /etc/apt/s ...

  2. Solr学习笔记(1) —— Solr概述&Solr的安装

    一.概述 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字.分类.价格搜索商品信息,也可以根据价格进行排序. 1.1 实现方法 在一些大型门户网站.电子商务网站等都需要站内搜索功能,使用传统 ...

  3. 1001 害死人不偿命的(3n+1)猜想 (15)(15 分)

    卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数 ...

  4. Flask&&人工智能AI -- 8 HTML5+ 初识,HBuilder,夜神模拟器,Webview

    昨日内容回顾 1.增删改查: 增: db.collections.insert({a:1}) // 官方不推荐了 db.collections.insertMany([{a:1},{b:1}]) in ...

  5. javasript

    ECMAScript和JavaScript的关系 1996年11月,JavaScript的创造者--Netscape公司,决定将JavaScript提交给国际标准化组织ECMA,希望这门语言能够成为国 ...

  6. day22 正则表达式 re

    1. 正则表达式 正则表达式是对字符串操作的一种逻辑公式. 我们一般使用正则表达式对字符串进行匹配和过滤. 工具: 各大文本编辑器⼀般都有正则匹配功能. 我们也可以去http://tool.china ...

  7. linu samba服务

    关闭防火墙并且重启网络yum install samba  samba-client samba-commmon -ysystemctl start smb smbclient -L //172.25 ...

  8. 缓存方案:本地guavaCache, 远程redis?

    线程内部缓存:a. 局部变量HashMap, 方法间传递  b. 使用ThreadLocal 本地缓存:单jvm内共享 可以使用(Concurrent)HashMap自己实现,也可以使用GuavaCa ...

  9. spring aop execution用法

    代码结构: 1. "execution(* com.ebc..*.*(..))" 与 "execution(*  com.ebc..*(..))" 2019-0 ...

  10. SElinux学习记录

    1.SELinux:是一种基于域类型模型的强制访问控制安全系统,由NSA编写设计成内核模块包含到内核中,相应的某些安全相关的应用也被打了SE Linux补丁 查看Selinux: ps -Z #查看S ...