Commit 404d574c authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

zabbix-agent: add memcached monitoring

parent 9a4bed23
......@@ -32,6 +32,7 @@ zabbix_agent_templates:
- Template App SSH Service
- Template App Zabbix Server
- Template App PostgreSQL
- Template App Memcached
zabbix_agent_host_groups:
- Linux servers
......
......@@ -57,3 +57,6 @@ runner2.archlinux.org
[reproduciblebuilds]
repro1.pkgbuild.com
repro2.pkgbuild.com
[memcached]
apollo.archlinux.org
#!/usr/bin/python
'''
Metrics:
- uptime - time memcached is alive
- listen_disabled_num - the number of times: the max number of connections is reachedand:ii
- conn_yields - Number of times a client connection was throttled.
- hits - get_hits / cmd_get. It indicates how efficient your Memcached server is.
- fill - used bytes / limit_maxbytes - Fill percentage
- evictions - an eviction is when an item that still has time to live is removed from the cache because a brand new item needs to be allocated
- command flush - the flush_all command invalidates all items in the database
- connections_total - total number of connections
'''
import argparse
import json
import os
from memcache import Client
SOCKET_DIR = '/run/memcached'
def stats(socket):
client = Client([f'unix://{SOCKET_DIR}/{socket}'])
stats = client.get_stats()
if not stats:
print(json.dumps({}))
else:
print(json.dumps(stats[0][1]))
def discover():
sockets = []
for loc in os.listdir(SOCKET_DIR):
if not loc.endswith('.sock'):
continue
sockets.append({"{#SOCKET}": loc})
print(json.dumps({"data": sockets}))
def main():
parser = argparse.ArgumentParser(description='memcached statistics dumptool (in json)')
parser.add_argument('--discover', action='store_true', help='discover memcached sockets')
parser.add_argument('--socket', type=str, help='the memcached socket location')
args = parser.parse_args()
if args.discover:
discover()
if args.socket:
stats(args.socket)
if __name__ == "__main__":
main()
......@@ -25,6 +25,17 @@
pacman: name=perl-dbi,perl-dbd-pg,perl-json
when: "'postgresql-servers' in group_names"
- name: install memcached monitoring packages
pacman: name=python-memcached
when: "'memcached' in group_names"
- name: adding existing zabbix-agent to memcached group
user:
name: zabbix-agent
groups: memcached
append: yes
when: "'memcached' in group_names"
- file: path=/etc/zabbix state=directory owner=root group=root mode=755
- name: create host PSK
......@@ -83,6 +94,7 @@
- mysql-dbsize-stats.pl
- postgresql-dbsize-stats.pl
- postgresql-user-stats.pl
- memcached-stats.py
- name: Install helper scripts
copy: src=nginx-zabbix.pl dest=/usr/local/bin/nginx-zabbix.pl mode=0755 owner=root group=root
......
zabbix-agent ALL=(root) NOPASSWD: /usr/local/bin/borg list --json --format {start}{end} --sort-by timestamp --last 1, /usr/local/bin/mysql-dbsize-stats.pl
zabbix-agent ALL=(root) NOPASSWD: /usr/local/bin/borg list --json --format {start}{end} --sort-by timestamp --last 1, /usr/local/bin/mysql-dbsize-stats.pl, /usr/local/bin/memcached-stats.py
zabbix-agent ALL=(postgres) NOPASSWD: /usr/local/bin/postgresql-dbsize-stats.pl, /usr/local/bin/postgresql-user-stats.pl
......@@ -63,3 +63,7 @@ UserParameter=linux.pressure,perl -MJSON -E 'my %h; for my $filename (@ARGV) {op
UserParameter=arch_audit.data,arch-audit -u | grep -v "from testing repos"
UserParameter=arch_archive.db_count,echo 'select count(*) from files;' | sqlite3 /home/archive/archive-uploader.sqlite
UserParameter=memcached.stats[*],sudo /usr/local/bin/memcached-stats.py --socket '$1'
UserParameter=memcached.stats_discover,/usr/local/bin/memcached-stats.py --discover
#UserParameter=postgresql.dbsize_discover,sudo -u postgres /usr/local/bin/postgresql-dbsize-stats.pl discover
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment