Compare commits
2 Commits
064b0ab6ca
...
fd4fa07884
| Author | SHA1 | Date | |
|---|---|---|---|
| fd4fa07884 | |||
| 0452982fe5 |
28
partitioning/CHANGELOG.md
Normal file
28
partitioning/CHANGELOG.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
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/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.4.0] - 2025-12-16
|
||||||
|
### Added
|
||||||
|
- **Monitoring**: Added `--discovery` argument for Zabbix Low-Level Discovery (LLD) of partitioned tables.
|
||||||
|
- **Monitoring**: Added `--check-days` argument to calculate days remaining until partition buffer exhaustion.
|
||||||
|
- **CLI**: Added `--version` / `-V` flag to display script version.
|
||||||
|
- **Docker**: Added `RUN_MODE=discovery` and `RUN_MODE=check` support to `entrypoint.py`.
|
||||||
|
- **Templates**: Added Zabbix 7.0 compatible template `zabbix_partitioning_template.yaml`.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- **CLI**: Removed unimplemented `--delete` / `-d` argument.
|
||||||
|
|
||||||
|
## [0.3.0] - 2025-12-14
|
||||||
|
### Changed
|
||||||
|
- **Refactor**: Complete rewrite of `zabbix_partitioning.py` using Class-based structure (`ZabbixPartitioner`).
|
||||||
|
- **Configuration**: Switched to YAML configuration file (`zabbix_partitioning.conf`).
|
||||||
|
- **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`).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **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.
|
||||||
@@ -267,8 +267,64 @@ docker run --rm \
|
|||||||
| `RETENTION_TRENDS` | 365d | Retention for `trends*` tables |
|
| `RETENTION_TRENDS` | 365d | Retention for `trends*` tables |
|
||||||
| `RETENTION_AUDIT` | 365d | Retention for `auditlog` (if enabled) |
|
| `RETENTION_AUDIT` | 365d | Retention for `auditlog` (if enabled) |
|
||||||
| `ENABLE_AUDITLOG_PARTITIONING` | false | Set to `true` to partition `auditlog` |
|
| `ENABLE_AUDITLOG_PARTITIONING` | false | Set to `true` to partition `auditlog` |
|
||||||
| `RUN_MODE` | maintenance | `init` (initialize), `maintenance` (daily run), or `dry-run` |
|
| `RUN_MODE` | maintenance | `init`, `maintenance`, `dry-run`, `discovery`, `check` |
|
||||||
|
| `CHECK_TARGET` | - | Required if `RUN_MODE=check`. Table name to check (e.g. `history`). |
|
||||||
| `PARTITION_DAILY_[TABLE]` | - | Custom daily retention (e.g., `PARTITION_DAILY_mytable=30d`) |
|
| `PARTITION_DAILY_[TABLE]` | - | Custom daily retention (e.g., `PARTITION_DAILY_mytable=30d`) |
|
||||||
| `PARTITION_WEEKLY_[TABLE]` | - | Custom weekly retention |
|
| `PARTITION_WEEKLY_[TABLE]` | - | Custom weekly retention |
|
||||||
| `PARTITION_MONTHLY_[TABLE]` | - | Custom monthly retention |
|
| `PARTITION_MONTHLY_[TABLE]` | - | Custom monthly retention |
|
||||||
|
|
||||||
|
#### Scenario F: Monitoring (Discovery)
|
||||||
|
Output Zabbix LLD JSON for table discovery.
|
||||||
|
```bash
|
||||||
|
docker run --rm \
|
||||||
|
-e DB_HOST=zabbix-db \
|
||||||
|
-e RUN_MODE=discovery \
|
||||||
|
zabbix-partitioning
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Scenario G: Monitoring (Health Check)
|
||||||
|
Check days remaining for a specific table (e.g., `history`). Returns integer days.
|
||||||
|
```bash
|
||||||
|
docker run --rm \
|
||||||
|
-e DB_HOST=zabbix-db \
|
||||||
|
-e RUN_MODE=check \
|
||||||
|
-e CHECK_TARGET=history \
|
||||||
|
zabbix-partitioning
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. Monitoring
|
||||||
|
The script includes built-in features for monitoring the health of your partitions via Zabbix.
|
||||||
|
|
||||||
|
### 10.1 CLI Usage
|
||||||
|
- **Discovery (LLD)**:
|
||||||
|
```bash
|
||||||
|
./zabbix_partitioning.py --discovery
|
||||||
|
# Output: [{"{#TABLE}": "history", "{#PERIOD}": "daily"}, ...]
|
||||||
|
```
|
||||||
|
- **Check Days**:
|
||||||
|
```bash
|
||||||
|
./zabbix_partitioning.py --check-days history
|
||||||
|
# Output: 30 (integer days remaining)
|
||||||
|
```
|
||||||
|
- **Version**:
|
||||||
|
```bash
|
||||||
|
./zabbix_partitioning.py --version
|
||||||
|
# Output: zabbix_partitioning.py 0.3.1-test
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.2 Zabbix Template
|
||||||
|
A Zabbix 7.0 template is provided: `zabbix_partitioning_template.yaml`.
|
||||||
|
|
||||||
|
**Setup**:
|
||||||
|
1. Import the YAML template into Zabbix.
|
||||||
|
2. Install the script on the Zabbix Server or Proxy.
|
||||||
|
3. Add the `UserParameter` commands to your Zabbix Agent config (see Template description).
|
||||||
|
4. Link the template to the host running the script.
|
||||||
|
|
||||||
|
**Features**:
|
||||||
|
- **Discovery**: Automatically finds all partitioned tables.
|
||||||
|
- **Triggers**: Alerts if a table has less than 3 days of future partitions pre-created.
|
||||||
|
- **Log Monitoring**: Alerts on script execution failures.
|
||||||
|
|
||||||
|
|||||||
10
partitioning/script/zabbix_partitioning.py
Normal file → Executable file
10
partitioning/script/zabbix_partitioning.py
Normal file → Executable file
@@ -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.3.0'
|
VERSION = '0.4.0'
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
PART_PERIOD_REGEX = r'([0-9]+)(h|d|m|y)'
|
PART_PERIOD_REGEX = r'([0-9]+)(h|d|m|y)'
|
||||||
@@ -521,11 +521,6 @@ class ZabbixPartitioner:
|
|||||||
self.check_compatibility()
|
self.check_compatibility()
|
||||||
premake = self.config.get('premake', 10)
|
premake = self.config.get('premake', 10)
|
||||||
|
|
||||||
if mode == 'delete':
|
|
||||||
self.logger.warning("Delete Mode: Removing ALL partitioning from configured tables is not fully implemented in refactor yet.")
|
|
||||||
# Implement if needed, usually just ALTER TABLE REMOVE PARTITIONING
|
|
||||||
return
|
|
||||||
|
|
||||||
for period, tables in partitions_conf.items():
|
for period, tables in partitions_conf.items():
|
||||||
if not tables:
|
if not tables:
|
||||||
continue
|
continue
|
||||||
@@ -567,12 +562,12 @@ 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('-d', '--delete', action='store_true', help='Remove partitions (Not implemented)')
|
|
||||||
parser.add_argument('--dry-run', action='store_true', help='Simulate queries')
|
parser.add_argument('--dry-run', action='store_true', help='Simulate queries')
|
||||||
|
|
||||||
# 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')
|
||||||
parser.add_argument('--check-days', type=str, help='Check days of future partitions left for table', metavar='TABLE')
|
parser.add_argument('--check-days', type=str, help='Check days of future partitions left for table', metavar='TABLE')
|
||||||
|
parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {VERSION}', help='Show version and exit')
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@@ -607,7 +602,6 @@ def main():
|
|||||||
mode = 'check'
|
mode = 'check'
|
||||||
target = args.check_days
|
target = args.check_days
|
||||||
elif args.init: mode = 'init'
|
elif args.init: mode = 'init'
|
||||||
elif args.delete: mode = 'delete'
|
|
||||||
|
|
||||||
# Setup logging
|
# Setup logging
|
||||||
# If discovery or check, we mute info logs to stdout to keep output clean,
|
# If discovery or check, we mute info logs to stdout to keep output clean,
|
||||||
|
|||||||
Reference in New Issue
Block a user