-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zabbix MySQL replication bridge local DB cache and refresh. #175
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
049d6eb
Initial pass at Zabbix MySQL replication bridge for item metrics.
christianchristensen 30fb346
Zabbix MySQL replication: additional notes and begin item key lookup.
christianchristensen 817a69e
Zabbix replication: lookup itemid:key hostname map.
christianchristensen 79be6b7
Cleanup using priv drop and get more tunables into config.
christianchristensen 8d1a68a
Support only resume (live) replication events (for now).
christianchristensen f99268a
[#MON-3137] TODO list for zabbix_bridge.
8859cc6
Merge branch 'master' of github.com:OpenTSDB/tcollector
christianchristensen 5302c62
Explicitly load collectors list, rather than yielding.
christianchristensen c42c3c1
Use a local SQLite DB cache (instead of in-memory); reload periodical…
christianchristensen 958b89a
Fixup Zabbix bridge SQLite cache.
christianchristensen 0df2cc8
Zabbix bridge cache executable.
christianchristensen 0066da3
Add internal metrics for log position, drift, and key miss.
christianchristensen e2ccc65
Support in memory sqlite db refreshed periodically from filesystem DB.
christianchristensen feb6519
Remove TODO list.
christianchristensen 31e2653
Index on id column for perf.
christianchristensen b999269
Rm sqlite3 error handling as it's part of the standard py libs.
christianchristensen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (C) 2014 The tcollector Authors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. This program is distributed in the hope that it | ||
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
# General Public License for more details. You should have received a copy | ||
# of the GNU Lesser General Public License along with this program. If not, | ||
# see <http://www.gnu.org/licenses/>. | ||
# | ||
# Dump all replication item/metric insert events from a zabbix mysql server | ||
# to a local sqlite cache (that can also be shared). | ||
# | ||
|
||
import os | ||
import re | ||
import sqlite3 | ||
import sys | ||
import time | ||
try: | ||
import pymysql | ||
except ImportError: | ||
pymysql = None # This is handled gracefully in main() | ||
|
||
from collectors.etc import zabbix_bridge_conf | ||
from collectors.lib import utils | ||
|
||
|
||
def main(): | ||
utils.drop_privileges() | ||
if pymysql is None: | ||
utils.err("error: Python module `pymysql' is missing") | ||
return 1 | ||
settings = zabbix_bridge_conf.get_settings() | ||
|
||
db_filename = settings['sqlitedb'] | ||
db_is_new = not os.path.exists(db_filename) | ||
dbcache = sqlite3.connect(db_filename) | ||
|
||
if db_is_new: | ||
utils.err("Zabbix bridge SQLite DB file does not exist; creating: %s" % (db_filename)) | ||
cachecur = dbcache.cursor() | ||
cachecur.execute('''CREATE TABLE zabbix_cache | ||
(id integer, key text, host text, proxy text)''') | ||
dbcache.commit() | ||
else: | ||
utils.err("Zabbix bridge SQLite DB exists @ %s" % (db_filename)) | ||
|
||
|
||
dbzbx = pymysql.connect(**settings['mysql']) | ||
zbxcur = dbzbx.cursor() | ||
zbxcur.execute("SELECT i.itemid, i.key_, h.host, h2.host AS proxy FROM items i JOIN hosts h ON i.hostid=h.hostid LEFT JOIN hosts h2 ON h2.hostid=h.proxy_hostid") | ||
# Translation of item key_ | ||
# Note: http://opentsdb.net/docs/build/html/user_guide/writing.html#metrics-and-tags | ||
disallow = re.compile(settings['disallow']) | ||
cachecur = dbcache.cursor() | ||
print('tcollector.zabbix_bridge.deleterows %d %s' % | ||
(int(time.time()), cachecur.execute('DELETE FROM zabbix_cache').rowcount)) | ||
rowcount = 0 | ||
for row in zbxcur: | ||
cachecur.execute('''INSERT INTO zabbix_cache(id, key, host, proxy) VALUES (?,?,?,?)''', | ||
(row[0], re.sub(disallow, '_', row[1]), re.sub(disallow, '_', row[2]), row[3])) | ||
rowcount += 1 | ||
|
||
print('tcollector.zabbix_bridge.rows %d %s' % (int(time.time()), rowcount)) | ||
zbxcur.close() | ||
dbcache.commit() | ||
|
||
dbzbx.close() | ||
dbcache.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.stdin.close() | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change doing?