PostgreSQL的监视代理

mamonsu的Python项目详细描述


生成状态

https://travis-ci.org/postgrespro/mamonsu.svg?branch=master

许可证

开发版本,在github上提供,在bsd 3子句下发布。

安装

预构建包:

Linux distros: https://packagecloud.io/postgrespro/mamonsu

Windows installers

通过PIP安装:

$ pip install mamonsu

从git安装:

$ git clone ... &&cd mamonsu && python setup.py build && python setup.py install

建立deb:

$ apt-get install make dpkg-dev debhelper python-dev python-setuptools
$ git clone ... &&cd mamonsu && make deb && dpkg -i mamonsu*.deb

生成转速:

$ yum install make rpm-build python2-devel python-setuptools
$ git clone ... &&cd mamonsu && make rpm && rpm -i mamonsu*.rpm

构建win32 exe:(与python v3.{4,5}:py2exe v0.9.2.2和pywin32 v220或python v2.7:py2exev0.6.9和pywin32 v220一起工作):

$ git clone ... &&cd mamonsu && python setup_win32.py py2exe
$ cp dist\{mamonsu, service_win32}.exe c:\mamonsu
$ c:\mamonsu\mamonsu.exe -w c:\mamonsu\agent.conf
$ c:\mamonsu\service_win32.exe -install
$ net start mamonsu

构建NSIS安装程序:

$ git clone ... &&cd mamonsu && python setup_win32.py py2exe
$ nsis packaging/win/mamonsu.nsis

配置

Zabbix的导出模板:

$ mamonsu export template template.xml --add-plugins /etc/mamonsu/plugins
or
$ wget https://raw.githubusercontent.com/postgrespro/mamonsu/master/packaging/conf/template.xml
or
$ cp /usr/share/mamonsu/template.xml .

在zabbix的web界面中导入此文件:configuration=>;templates=>;import,或与mamonsu一起部署:

$ mamonsu zabbix template export /usr/share/mamonsu/template.xml --url=http://zabbix/ --user=Admin --password=zabbix

在监视主机上添加此模板,如postgrespro linux,或使用mamonsu创建主机:

$ mamonsu zabbix host create <client name> <hostgroup id> <template id> <ip> --url=http://zabbix/ --user=Admin --password=zabbix

在监视主机上生成配置(或使用预安装):

$ mamonsu export config /etc/mamonsu/agent.conf --add-plugins /etc/mamonsu/plugins

更改以前的zabbix服务器地址和客户端主机名:

$ vim /etc/mamonsu/agent.conf

$ cat /etc/mamonsu/agent.conf

[zabbix]; enabled by default
enabled= True
client= zabbix_client_host_name
address= zabbix_server_ip

[postgres]; enabled by default
enabled= True
user= mamonsu
database= mamonsu
; empty password
password= None
port=5432query_timeout=10[system]; enabled by default
enabled= True

[log]file= /var/log/mamonsu/agent.log
level= INFO

用于监视的引导DDL(如果要监视而不具有超级用户权限)

$ createdb mamonsu
$ createuser mamonsu
$ mamonsu bootstrap -U postgres -d mamonsu

编写插件

所有插件都必须存在于配置文件中定义的插件目录中。

有关其他信息,请参见examples

添加新插件后,必须重新导出模板并将此文件导入zabbix。

第三方

运行

$ service mamonsu start
or by hand:
$ mamonsu -d -a /etc/mamonsu/plugins -c /etc/mamonsu/agent.conf -p /var/run/mamonsu.pid

指标:PostgreSQL

'PostgreSQL: ping': pgsql.ping[]'PostgreSQL: service uptime': pgsql.uptime[]'PostgreSQL: cache hit ratio': pgsql.cache[hit]'PostgreSQL: number of total connections': pgsql.connections[total]'PostgreSQL: number of waiting connections': pgsql.connections[waiting]'PostgreSQL: number of active connections': pgsql.connections[active]'PostgreSQL: number of idle connections': pgsql.connections[idle]'PostgreSQL: number of idle in transaction connections': pgsql.connections[idle_in_transaction]'PostgreSQL checkpoint: by timeout (in hour)': pgsql.checkpoint[count_timed]'PostgreSQL checkpoint: by wal (in hour)': pgsql.checkpoint[count_wal]'PostgreSQL checkpoint: write time': pgsql.checkpoint[write_time]'PostgreSQL checkpoint: sync time': pgsql.checkpoint[checkpoint_sync_time]'PostgreSQL bgwriter: buffers written during checkpoints': pgsql.bgwriter[buffers_checkpoint]'PostgreSQL bgwriter: buffers written': pgsql.bgwriter[buffers_clean]'PostgreSQL bgwriter: number of bgwriter stopped by max write count': pgsql.bgwriter[maxwritten_clean]'PostgreSQL bgwriter: buffers written directly by a backend': pgsql.bgwriter[buffers_backend]'PostgreSQL bgwriter: times a backend execute its own fsync': pgsql.bgwriter[buffers_backend_fsync]'PostgreSQL bgwriter: buffers allocated': pgsql.bgwriter[buffers_alloc]'PostgreSQL: count of autovacuum workers': pgsql.autovacumm.count[]'PostgreSQL transactions: total': pgsql.transactions[total]'PostgreSQL blocks: hit': pgsql.blocks[hit]'PostgreSQL blocks: read': pgsql.blocks[read]'PostgreSQL event: conflicts': pgsql.events[conflicts]'PostgreSQL event: deadlocks': pgsql.events[deadlocks]'PostgreSQL event: rollbacks': pgsql.events[xact_rollback]'PostgreSQL temp: bytes written': pgsql.temp[bytes]'PostgreSQL temp: files created': pgsql.temp[files]'PostgreSQL tuples: deleted': pgsql.tuples[deleted]'PostgreSQL tuples: fetched': pgsql.tuples[fetched]'PostgreSQL tuples: inserted': pgsql.tuples[inserted]'PostgreSQL tuples: returned': pgsql.tuples[returned]'PostgreSQL tuples: updated': pgsql.tuples[updated]'PostgreSQL: streaming replication lag in seconds': pgsql.replication_lag[sec]'PostgreSQL: wal write speed': pgsql.wal.write[]'PostgreSQL: count of xlog files': pgsql.wal.count[]'PostgreSQL statements: read bytes/s': pgsql.stat[read_bytes]'PostgreSQL statements: write bytes/s': pgsql.stat[write_bytes]'PostgreSQL statements: dirty bytes/s': pgsql.stat[dirty_bytes]'PostgreSQL statements: read io time': pgsql.stat[read_time]'PostgreSQL statements: write io time': pgsql.stat[write_time]'PostgreSQL statements: other (mostly cpu) time': pgsql.stat[other_time]'PostgreSQL locks: Read only queries': pgsql.pg_locks[accessshare]'PostgreSQL locks: SELECT FOR SHARE and SELECT FOR UPDATE': pgsql.pg_locks[rowshare]'PostgreSQL locks: Write queries': pgsql.pg_locks[rowexclusive]'PostgreSQL locks: VACUUM, ANALYZE, CREATE INDEX CONCURRENTLY': pgsql.pg_locks[shareupdateexclusive]'PostgreSQL locks: CREATE INDEX': pgsql.pg_locks[share]'PostgreSQL locks: Locks from application': pgsql.pg_locks[sharerowexclusive]'PostgreSQL locks: Locks from application or some operation on system catalogs': pgsql.pg_locks[exclusive]'PostgreSQL locks: ALTER TABLE, DROP TABLE, TRUNCATE, REINDEX, CLUSTER, VACUUM FULL, LOCK TABLE': pgsql.pg_locks[accessexclusive]'PostgreSQL oldest query running time': pgsql.oldest[query_time]'PostgreSQL age of oldest xid': pgsql.oldest[xid_age]'PostgreSQL waits: Lightweight locks': pgsql.all_lock[lwlock]'PostgreSQL waits: Heavyweight locks': pgsql.all_lock[hwlock]'PostgreSQL waits: Buffer locks': pgsql.all_lock[buffer]'PostgreSQL waits: lock on a relation': pgsql.hwlock[relation]'PostgreSQL waits: extend a relation': pgsql.hwlock[extend]'PostgreSQL waits: lock on a tuple': pgsql.hwlock[tuple]'PostgreSQL waits: transaction to finish': pgsql.hwlock[transactionid]'PostgreSQL waits: virtual xid lock': pgsql.hwlock[virtualxid]'PostgreSQL waits: speculative insertion lock': pgsql.hwlock[speculative_token]'PostgreSQL waits: lock on database object': pgsql.hwlock[object]'PostgreSQL waits: userlock': pgsql.hwlock[userlock]'PostgreSQL waits: advisory user lock': pgsql.hwlock[advisory]'PostgreSQL waits: XID access': pgsql.lwlock[xid]'PostgreSQL waits: WAL access': pgsql.lwlock[wal]'PostgreSQL waits: CLOG access': pgsql.lwlock[clog]'PostgreSQL waits: Replication Locks': pgsql.lwlock[replication]'PostgreSQL waits: Buffer operations': pgsql.lwlock[buffer]'PostgreSQL waits: Other operations': pgsql.lwlock[other]'Database {#DATABASE}: size': pgsql.database.size[{#DATABASE}]
'Count of bloating tables in database: {#DATABASE}': pgsql.database.bloating_tables[{#DATABASE}]
'Max age (datfrozenxid) in: {#DATABASE}': pgsql.database.bloating_tables[{#DATABASE}]

指标:Linux系统

'System uptime': system.uptime[]'System load average over 1 minute': system.la[1]'Processes: in state running': system.processes[running]'Processes: in state blocked': system.processes[blocked]'Processes: forkrate': system.processes[forkrate]'Opened files': system.open_files[]'CPU time spent by normal programs and daemons': system.cpu[user]'CPU time spent by nice(1)d programs': system.cpu[nice]'CPU time spent by the kernel in system activities': system.cpu[system]'CPU time spent by Idle CPU time': system.cpu[idle]'CPU time spent waiting for I/O operations': system.cpu[iowait]'CPU time spent handling interrupts': system.cpu[irq]'CPU time spent handling batched interrupts': system.cpu[softirq]'Block devices: read requests': system.disk.all_read[]'Block devices: write requests': system.disk.all_write[]'Apps: User-space applications': system.memory[apps]'Buffers: Block device cache and dirty': system.memory[buffers]'Swap: Swap space used': system.memory[swap]'Cached: Parked file data (file content) cache': system.memory[cached]'Free: Wasted memory': system.memory[unused]'Slab: Kernel used memory (inode cache)': system.memory[slab]'SwapCached: Fetched unmod yet swap pages': system.memory[swap_cache]'PageTables: Map bt virtual and physical': system.memory[page_tables]'VMallocUsed: vmaloc() allocated by kernel': system.memory[vmalloc_used]'Committed_AS: Total committed memory': system.memory[committed]'Mapped: All mmap()ed pages': system.memory[mapped]'Active: Memory recently used': system.memory[active]'Inactive: Memory not currently used': system.memory[inactive]'Mount point {#MOUNTPOINT}: used': system.vfs.used[{#MOUNTPOINT}]
'Mount point {#MOUNTPOINT}: free' system.vfs.free[{#MOUNTPOINT}]
'Mount point {#MOUNTPOINT}: free in percents': system.vfs.percent_free[{#MOUNTPOINT}]
'Mount point {#MOUNTPOINT}: free inodes in percent': system.vfs.percent_inode_free[{#MOUNTPOINT}]
'Block device {#BLOCKDEVICE}: utilization': system.disk.utilization[{#BLOCKDEVICE}]
'Block device {#BLOCKDEVICE}: read operations': system.disk.read[{#BLOCKDEVICE}]
'Block device {#BLOCKDEVICE}: write operations': system.disk.write[{#BLOCKDEVICE}]
'Block device {#BLOCKDEVICE}: read byte/s': system.disk.read_b[{#BLOCKDEVICE}]
'Block device {#BLOCKDEVICE}: write byte/s': system.disk.write_b[{#BLOCKDEVICE}]
'Net device {#NETDEVICE}: RX bytes/s': system.net.rx_bytes[{#NETDEVICE}]
'Net device {#NETDEVICE}: RX errors/s': system.net.rx_errors[{#NETDEVICE}]
'Net device {#NETDEVICE}: RX drops/s': system.net.rx_drops[{#NETDEVICE}]
'Net device {#NETDEVICE}: TX bytes/s': system.net.tx_bytes[{#NETDEVICE}]
'Net device {#NETDEVICE}: TX errors/s': system.net.tx_errors[{#NETDEVICE}]
'Net device {#NETDEVICE}: TX drops/s': system.net.tx_drops[{#NETDEVICE}]

指标:Windows系统

'Memory cached': system.memory[cache]'Memory available': system.memory[available]'Memory free': system.memory[free]'CPU user time': system.cpu[user_time]'CPU idle time': system.cpu[idle_time]'CPU privileged time': system.cpu[privileged_time]'Network bytes total': system.network[total_bytes]'Network output queue length': system.network[total_output_queue]

屏幕截图

https://raw.githubusercontent.com/postgrespro/mamonsu/master/examples/statistics-1.pnghttps://raw.githubusercontent.com/postgrespro/mamonsu/master/examples/statistics-2.pnghttps://raw.githubusercontent.com/postgrespro/mamonsu/master/examples/statistics-3.png

工具:报告

创建有关已用硬件和PostgreSQL的报告:

$ mamonsu report

工具:调谐

根据硬件信息对系统和PostgreSQL进行通用优化:

$ mamonsu tune

工具:模拟zabbix_get

$ mamonsu agent version
$ mamonsu agent metric-list
$ mamonsu agent metric-get <key>

工具:zabbix cli

简单的cli,用于控制zabbix服务器

$ exportZABBIX_USER=Admin
$ exportZABBIX_PASSWD=zabbix
$ exportZABBIX_URL='http://localhost/zabbix'

$ mamonsu zabbix template list
$ mamonsu zabbix template show <template name>
$ mamonsu zabbix template id <template name>
$ mamonsu zabbix template delete <template id>
$ mamonsu zabbix template export <file>

$ mamonsu zabbix host list
$ mamonsu zabbix host show <hostname>
$ mamonsu zabbix host id <hostname>
$ mamonsu zabbix host delete <host id>
$ mamonsu zabbix host create <host name> <hostgroup id> <template id> <ip>
$ mamonsu zabbix host info templates <host id>
$ mamonsu zabbix host info hostgroups <host id>
$ mamonsu zabbix host info graphs <host id>
$ mamonsu zabbix host info items <host id>

$ mamonsu zabbix hostgroup list
$ mamonsu zabbix hostgroup show <hostgroup name>
$ mamonsu zabbix hostgroup id <hostgroup name>
$ mamonsu zabbix hostgroup delete <hostgroup id>
$ mamonsu zabbix hostgroup create <hostgroup name>

$ mamonsu zabbix item error <host name>
$ mamonsu zabbix item lastvalue <host name>
$ mamonsu zabbix item lastclock <host name>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有字符串的java JNA调用与带有字节[]的java JNA调用的行为不同   java基于键列表获取子映射   重启后永久增加java堆大小?   JavaHTTPS服务器:相互SSL身份验证   java为什么接受接口的方法会拒绝该接口的实现?   片段中的java视图无法应用于()   ms access Java SQL更新命令不工作   java将web服务自动打包和部署到Oracle Application Server 10g   java有没有办法在安卓 studio中为安卓时钟设置多个警报?   位于FTP服务器上的文件上的Java校验和md5   在Java中创建类时遇到问题。有些方法不太确定   java错误:在类chrome\u驱动程序中找不到主方法   通用海图(Javascript\Java)