Compare commits
4 Commits
060c5cd2db
...
monitored
| Author | SHA1 | Date | |
|---|---|---|---|
| bcd2bd627e | |||
| 9e53259e61 | |||
| a61f2bdf30 | |||
| 66b1cc036b |
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.4.1] - 2025-12-16
|
||||||
|
### Added
|
||||||
|
- **CLI**: Added `--verbose` / `-v` flag to switch between INFO (default) and DEBUG logging levels.
|
||||||
|
- **CLI**: Added `-r` short flag for `--dry-run`.
|
||||||
|
|
||||||
## [0.4.0] - 2025-12-16
|
## [0.4.0] - 2025-12-16
|
||||||
### Added
|
### Added
|
||||||
- **Monitoring**: Added `--discovery` argument for Zabbix Low-Level Discovery (LLD) of partitioned tables.
|
- **Monitoring**: Added `--discovery` argument for Zabbix Low-Level Discovery (LLD) of partitioned tables.
|
||||||
@@ -19,10 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [0.3.0] - 2025-12-14
|
## [0.3.0] - 2025-12-14
|
||||||
### Changed
|
### Changed
|
||||||
- **Refactor**: Complete rewrite of `zabbix_partitioning.py` using Class-based structure (`ZabbixPartitioner`).
|
- **Refactor**: Complete rewrite of `zabbix_partitioning.py` using Class-based structure (`ZabbixPartitioner`).
|
||||||
- **Configuration**: Switched to YAML configuration file (`zabbix_partitioning.conf`).
|
- **Configuration**: Extended comments in the configuration file (`zabbix_partitioning.conf`). The config file is self-explanatory now.
|
||||||
- **Safety**: Added checks to prevent partitioning of tables incompatible with Zabbix 7.0 schema (e.g., `auditlog` without `clock` in PK).
|
- **Docker**: Introduced Docker container support (`Dockerfile`, `entrypoint.py`). The script can be run in a stateless manner using Docker.
|
||||||
- **Docker**: Introduced Docker container support (`Dockerfile`, `entrypoint.py`).
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- **Optimization**: Added `initial_partitioning_start` option (`db_min` vs `retention`) to speed up initialization on large DBs.
|
- **Optimization**: Added `initial_partitioning_start` option (`db_min` vs `retention`) to speed up initialization on large DBs.
|
||||||
- **Reliability**: Use `pymysql` with robust connection handling and SSL support.
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
database:
|
database:
|
||||||
type: mysql
|
type: mysql
|
||||||
# host: Database server hostname or IP
|
# host: Database server hostname or IP
|
||||||
host: localhost
|
# host: localhost
|
||||||
# socket: Path to the MySQL unix socket (overrides host if set)
|
# socket: Path to the MySQL unix socket (overrides host if set)
|
||||||
socket: /var/run/mysqlrouter/mysql_rw.sock
|
socket: /var/run/mysqld/mysqld.sock
|
||||||
# port: Database port (default: 3306)
|
# port: Database port (default: 3306)
|
||||||
# port: 3306
|
# port: 3306
|
||||||
# credentials
|
# credentials
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from typing import Optional, Dict, List, Any, Union, Tuple
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
# Semantic Versioning
|
# Semantic Versioning
|
||||||
VERSION = '0.4.0'
|
VERSION = '0.4.1'
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
PART_PERIOD_REGEX = r'([0-9]+)(h|d|m|y)'
|
PART_PERIOD_REGEX = r'([0-9]+)(h|d|m|y)'
|
||||||
@@ -543,9 +543,9 @@ class ZabbixPartitioner:
|
|||||||
if mode != 'init' and not self.dry_run:
|
if mode != 'init' and not self.dry_run:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setup_logging(config_log_type: str):
|
def setup_logging(config_log_type: str, verbose: bool = False):
|
||||||
logger = logging.getLogger('zabbix_partitioning')
|
logger = logging.getLogger('zabbix_partitioning')
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG if verbose else logging.INFO)
|
||||||
|
|
||||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
@@ -562,7 +562,8 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(description='Zabbix Partitioning Manager')
|
parser = argparse.ArgumentParser(description='Zabbix Partitioning Manager')
|
||||||
parser.add_argument('-c', '--config', default='/etc/zabbix/zabbix_partitioning.conf', help='Config file path')
|
parser.add_argument('-c', '--config', default='/etc/zabbix/zabbix_partitioning.conf', help='Config file path')
|
||||||
parser.add_argument('-i', '--init', action='store_true', help='Initialize partitions')
|
parser.add_argument('-i', '--init', action='store_true', help='Initialize partitions')
|
||||||
parser.add_argument('--dry-run', action='store_true', help='Simulate queries')
|
parser.add_argument('-r', '--dry-run', action='store_true', help='Simulate queries')
|
||||||
|
parser.add_argument('-v', '--verbose', action='store_true', help='Enable debug logging')
|
||||||
|
|
||||||
# Monitoring args
|
# Monitoring args
|
||||||
parser.add_argument('--discovery', action='store_true', help='Output Zabbix LLD JSON')
|
parser.add_argument('--discovery', action='store_true', help='Output Zabbix LLD JSON')
|
||||||
@@ -604,12 +605,10 @@ def main():
|
|||||||
elif args.init: mode = 'init'
|
elif args.init: mode = 'init'
|
||||||
|
|
||||||
# Setup logging
|
# Setup logging
|
||||||
# If discovery or check, we mute info logs to stdout to keep output clean,
|
|
||||||
# unless errors happen.
|
|
||||||
if mode in ['discovery', 'check']:
|
if mode in ['discovery', 'check']:
|
||||||
logging.basicConfig(level=logging.ERROR) # Only show critical errors
|
logging.basicConfig(level=logging.ERROR) # Only show critical errors
|
||||||
else:
|
else:
|
||||||
setup_logging(config.get('logging', 'console'))
|
setup_logging(config.get('logging', 'console'), verbose=args.verbose)
|
||||||
|
|
||||||
logger = logging.getLogger('zabbix_partitioning')
|
logger = logging.getLogger('zabbix_partitioning')
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ zabbix_export:
|
|||||||
version: '7.0'
|
version: '7.0'
|
||||||
template_groups:
|
template_groups:
|
||||||
- uuid: e29f7cbf75cf41cb81078cb4c10d584a
|
- uuid: e29f7cbf75cf41cb81078cb4c10d584a
|
||||||
name: 'Templates/Databases'
|
name: Templates/Databases
|
||||||
templates:
|
templates:
|
||||||
- uuid: 69899eb3126b4c62b70351f305b69dd9
|
- uuid: 69899eb3126b4c62b70351f305b69dd9
|
||||||
template: 'Zabbix Partitioning Monitor'
|
template: 'Zabbix Partitioning Monitor'
|
||||||
@@ -16,39 +16,35 @@ zabbix_export:
|
|||||||
UserParameter=zabbix.partitioning.check[*], /usr/local/bin/zabbix_partitioning.py -c $1 --check-days $2
|
UserParameter=zabbix.partitioning.check[*], /usr/local/bin/zabbix_partitioning.py -c $1 --check-days $2
|
||||||
|
|
||||||
Or use Docker wrapper scripts.
|
Or use Docker wrapper scripts.
|
||||||
|
|
||||||
groups:
|
groups:
|
||||||
- name: 'Templates/Databases'
|
- name: Templates/Databases
|
||||||
items:
|
items:
|
||||||
- uuid: bc753e750cc2485f917ba1f023c87d05
|
- uuid: bc753e750cc2485f917ba1f023c87d05
|
||||||
name: 'Partitioning Last Run Status'
|
name: 'Partitioning Last Run Status'
|
||||||
type: TRAP
|
type: ZABBIX_ACTIVE
|
||||||
key: partitioning.run.status
|
key: 'log[/var/log/syslog,zabbix_partitioning]'
|
||||||
delay: 0
|
|
||||||
history: 7d
|
history: 7d
|
||||||
|
value_type: LOG
|
||||||
trends: '0'
|
trends: '0'
|
||||||
value_type: TEXT
|
|
||||||
description: 'Send "Success" or "Failed" via zabbix_sender or check log file'
|
|
||||||
triggers:
|
triggers:
|
||||||
- uuid: 25497978dbb943e49dac8f3b9db91c29
|
- uuid: 25497978dbb943e49dac8f3b9db91c29
|
||||||
expression: 'find(/Zabbix Partitioning Monitor/partitioning.run.status,,"like","Failed")=1'
|
expression: 'find(/Zabbix Partitioning Monitor/log[/var/log/syslog,zabbix_partitioning],,"like","Failed")=1'
|
||||||
name: 'Zabbix Partitioning Failed'
|
name: 'Partitioning Script Failed'
|
||||||
priority: HIGH
|
priority: HIGH
|
||||||
description: 'The partitioning script reported a failure.'
|
description: 'The partitioning script reported a failure.'
|
||||||
tags:
|
tags:
|
||||||
- tag: services
|
- tag: services
|
||||||
value: database
|
value: database
|
||||||
|
|
||||||
discovery_rules:
|
discovery_rules:
|
||||||
- uuid: 097c96467035468a80ce5c519b0297bb
|
- uuid: 097c96467035468a80ce5c519b0297bb
|
||||||
name: 'Partitioning Discovery'
|
name: 'Partitioning Discovery'
|
||||||
key: 'zabbix.partitioning.discovery[/etc/zabbix/zabbix_partitioning.conf]'
|
key: 'zabbix.partitioning.discovery[{$PATH.TO.CONFIG}]'
|
||||||
delay: 1h
|
delay: 1d
|
||||||
description: 'Discover partitioned tables'
|
description: 'Discover partitioned tables'
|
||||||
item_prototypes:
|
item_prototypes:
|
||||||
- uuid: 1fbff85191c244dca956be7a94bf08a3
|
- uuid: 1fbff85191c244dca956be7a94bf08a3
|
||||||
name: 'Partitions remaining: {#TABLE}'
|
name: 'Days remaining: {#TABLE}'
|
||||||
key: 'zabbix.partitioning.check[/etc/zabbix/zabbix_partitioning.conf, {#TABLE}]'
|
key: 'zabbix.partitioning.check[{$PATH.TO.CONFIG}, {#TABLE}]'
|
||||||
delay: 12h
|
delay: 12h
|
||||||
history: 7d
|
history: 7d
|
||||||
description: 'Days until the last partition runs out for {#TABLE}'
|
description: 'Days until the last partition runs out for {#TABLE}'
|
||||||
@@ -59,7 +55,13 @@ zabbix_export:
|
|||||||
value: '{#TABLE}'
|
value: '{#TABLE}'
|
||||||
trigger_prototypes:
|
trigger_prototypes:
|
||||||
- uuid: da23fae76a41455c86c58267d6d9f86d
|
- uuid: da23fae76a41455c86c58267d6d9f86d
|
||||||
expression: 'last(/Zabbix Partitioning Monitor/zabbix.partitioning.check[/etc/zabbix/zabbix_partitioning.conf, {#TABLE}])<=3'
|
expression: 'last(/Zabbix Partitioning Monitor/zabbix.partitioning.check[{$PATH.TO.CONFIG}, {#TABLE}])<={$PARTITION.DAYS}'
|
||||||
name: 'Partitioning critical: {#TABLE} has less than 3 days of partitions'
|
name: 'Partitioning critical: {#TABLE} has less than {$PARTITION.DAYS} days in partition'
|
||||||
priority: HIGH
|
opdata: 'Days till Zabbix server will crash: {ITEM.LASTVALUE}'
|
||||||
|
priority: DISASTER
|
||||||
description: 'New partitions are not being created. Check the script logs.'
|
description: 'New partitions are not being created. Check the script logs.'
|
||||||
|
macros:
|
||||||
|
- macro: '{$PARTITION.DAYS}'
|
||||||
|
value: '3'
|
||||||
|
- macro: '{$PATH.TO.CONFIG}'
|
||||||
|
value: /etc/zabbix/scripts/zabbix_partitioning.conf
|
||||||
Reference in New Issue
Block a user