Skip to content

# Tag: python

## oak-hook-general-log: streaming general log

MySQL logs openark kit python scripts March 21, 2010March 21, 2010

I’m seeking input on a new openark kit utility I’ve started to implement.

The tool, oak-hook-general-log, will hook up to a MySQL (>= 5.1) server, and stream the general log into standard output. It looks like this:

>     bash$ python src/oak/oak-hook-general-log.py --socket=/tmp/mysql.sock --user=root
>     2010-03-21 10:18:42     root[root] @ localhost []       79      1       Query   SELECT COUNT(*) FROM City
>     2010-03-21 10:18:48     root[root] @ localhost []       79      1       Query   DELETE FROM City WHERE id=1000
>     2010-03-21 10:18:54     root[root] @ localhost []       79      1       Query   SHOW PROCESSLIST
>     2010-03-21 10:19:06     root[root] @ localhost []       79      1       Quit
>     2010-03-21 10:19:07     root[root] @ localhost []       93      1       Connect root@localhost on
>     2010-03-21 10:19:07     root[root] @ localhost []       93      1       Query   select @@version_comment limit 1
>     2010-03-21 10:22:33     root[root] @ localhost []       93      1       Query   SELECT City.Name, Country.Name FROM Country JOIN City ON Country.Capit
>     2010-03-21 10:22:58     root[root] @ localhost []       93      1       Quit

Since output is written to stdout, one can further:

>     bash$ python src/oak/oak-hook-general-log.py --socket=/tmp/mysql.sock --user=root | grep Connect
>     bash$ python src/oak/oak-hook-general-log.py --socket=/tmp/mysql.sock --user=root | grep webuser@webhost

What the tool does is to enable table logs, and periodically rotate the mysql.general_log table, read and dump its content.

Continue reading » “oak-hook-general-log: streaming general log”

## Proper SQL table alias use conventions

MySQL Java Opinions python SQL Syntax March 11, 2010March 11, 2010

After seeing quite some SQL statements over the years, something is bugging me: there is no consistent convention as for how to write an SQL query.

I’m going to leave formatting, upper/lower-case issues aside, and discuss a small part of the SQL syntax: table aliases. Looking at three different queries, I will describe what I find to be problematic table alias use.

Using the sakila database, take a look at the following queries: Continue reading » “Proper SQL table alias use conventions”

## mycheckpoint rev. 76: OS monitoring, auto deploy, brief HTML and 24/7 reports

MySQL Graphs Linux Monitoring mycheckpoint python scripts January 5, 2010January 5, 2010

Revision 76 of mycheckpoint comes with quite a few improvements, including:

- OS monitoring (CPU, load average, memory)
- Auto-deploy
- Improved charting
- Brief HTML reports
- 24/7 charts

#### OS Monitoring

When monitoring the local machine, mycheckpoint now monitors CPU utilization, load average, memory and swap space.

This only applies to the Linux operating system; there is currently no plan to work this out for other operating systems.

Examples:

>     mysql> SELECT os_cpu_utilization_percent FROM sv_report_chart_sample;

>     mysql> SELECT ts, os_loadavg FROM mycheckpoint.sv_report_sample;
>     +---------------------+------------+
>     | 2009-12-27 11:45:01 |       1.78 |
>     | 2009-12-27 11:50:01 |       2.48 |
>     | 2009-12-27 11:55:01 |       2.35 |
>     ...
>     +---------------------+------------+

>     mysql> SELECT report FROM mycheckpoint.sv_report_human_sample ORDER BY id DESC LIMIT 1 \G
>     *************************** 1. row ***************************
>     report:
>     Report period: 2009-12-27 13:20:01 to 2009-12-27 13:25:01. Period is 5 minutes (0.08 hours)
>     Uptime: 100.0% (Up: 334 days, 06:37:28 hours)

>     OS:
>      Load average: 1.67
>      CPU utilization: 25.2%
>      Memory: 7486.4MB used out of 7985.6484MB (Active: 6685.8906MB)
>      Swap: 3835.2MB used out of 8189.3750MB
>     ...

#### Auto-deploy

mycheckpoint now has a version recognition mechanism. There is no need to call mycheckpoint with the “deploy” argument on first install or after upgrade. mycheckpoint will recognize a change of version and will auto-deploy before moving on to monitoring your system.

Continue reading » “mycheckpoint rev. 76: OS monitoring, auto deploy, brief HTML and 24/7 reports”

## Announcing mycheckpoint: lightweight, SQL oriented monitoring for MySQL

MySQL Analysis Configuration Monitoring mycheckpoint python November 10, 2009

I’m proud to announce mycheckpoint, a monitoring utility for MySQL, with strong emphasis on user accessibility to monitored data.

mycheckpoint is a different kind of monitoring tool. It leaves the power in the user’s hand. It’s power is not with script-based calculations of recorded data. It’s with the creation of a view hierarchy, which allows the user to access computed metrics directly.

mycheckpoint is needed first, to deploy a monitoring schema. It may be needed next, so as to INSERT recorded data (GLOBAL STATUS, GLOBAL VARIABLES, MASTER STATUS, SLAVE STATUS) — but this is just a simple INSERT; anyone can do that, even another monitoring tool.

It is then that you do not need it anymore: everything is laid at your fingertips. Consider:

>     SELECT innodb_read_hit_percent, DML FROM sv_report_chart_hour;

mycheckpoint provides the views which take raw data (just innodb_buffer_pool_read_requests, com_select, innodb_buffer_pool_size, table_open_cache, seconds_behind_master etc.) and generate Google Charts URLs, HTML reports, human readable reports, or otherwise easily accessible data.

Continue reading » “Announcing mycheckpoint: lightweight, SQL oriented monitoring for MySQL”

## Announcing openark kit

MySQL openark kit python February 25, 2009March 13, 2009

It is my great pleasure to announce the availability of the openark kit, a set of lightweight utilities for MySQL, which eases every day tasks.

The available tools are:

- oak-apply-ri: apply referential integrity on two columns with parent-child relationship.
- oak-block-account: block or release MySQL users accounts, disabling them or enabling them to login.
- oak-kill-slow-queries: terminate long running queries.
- oak-modify-charset: change the character set (and collation) of a textual column.
- oak-purge-master-logs: purge master logs, depending on the state of replicating slaves.
- oak-security-audit: audit accounts, passwords, privileges and other security settings.
- oak-show-limits: show AUTO_INCREMENT “free space”.
- oak-show-replication-status: show how far behind are replicating slaves on a given master.

Continue reading » “Announcing openark kit”

## Using memcached functions for MySQL; an automated alternative to Query Cache

MySQL memcached python Query Cache Triggers December 15, 2008December 15, 2008

There’s a lot of buzz around memcached. memcached is widely used, and has clients for many programming languages and platforms. TangentOrg have developed a memcached client in the form of MySQL UDFs (User Defined Functions).

I wish to discuss the memcached functions for MySQL: if and how they should be used.

Disclaimer: I do not work with memcached functions for MySQL on a production system; all that is written here reflects my opinion on how things should be done.

With memcached functions for MySQL, we can do the following:

>     SELECT memc_set('mykey', 'The answer is 42');
>     SELECT memc_get('mykey');

(See my previous post on how to install memcached functions for MySQL).

#### In what scenario should we use these functions?

I believe memcached is the right tool for the application level. I am less enthusiastic about using it from MySQL. Sure, pushing it down to MySQL centralizes everything. Instead of having all my application code (PHP, Java etc.) access memcached separately, they can all access one single MySQL node, which gets to access memcached. I see two problems with this approach: Continue reading » “Using memcached functions for MySQL; an automated alternative to Query Cache”