(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
Developing INFORMATION_SCHEMA Plugins Mark Leith Support Manager, Americas [email_address]
Overview INFORMATION_SCHEMA overview Plugin Overview Developing a simple Hello World I_S table Building and installing  Interacting with another program Interacting with another library
INFORMATION_SCHEMA Specified within the SQL Standard  (ISO/IEC 9075-11:2003) ‏ Virtual tables which give database metadata MySQL implements a subset of the Standard http://dev.mysql.com/doc/refman/5.1/en/information-schema.html http://www. xcdsql .org/MySQL/information_schema/5.1/MySQL_5_1_INFORMATION_SCHEMA.html
 
Plugins A means to load shared libraries in to a running MySQL instance Developed in C/C++ http://dev.mysql.com/doc/refman/5.1/en/plugin-api.html User Defined Functions Storage Engines Fulltext parsers Daemons INFORMATION_SCHEMA Tables!
Located in include/mysql/plugin.h The Plugin Interface struct  st_mysql_plugin {  int  type;  /* the plugin type (a MYSQL_XXX_PLUGIN value)  */   void  *info;  /* pointer to type-specific plugin descriptor  */   const   char  *name;  /* plugin name  */   const   char  *author;  /* plugin author (for SHOW PLUGINS)  */   const   char  *descr;  /* general descriptive text (for SHOW PLUGINS )  */   int  license;  /* the plugin license (PLUGIN_LICENSE_XXX)  */   int  (*init)( void  *);  /* the function to invoke when plugin is loaded  */   int  (*deinit)( void  *) /* the function to invoke when plugin is unloaded  */   unsigned   int  version;  /* plugin version (for SHOW PLUGINS)  */   struct  st_mysql_show_var *status_vars;  struct  st_mysql_sys_var **system_vars;  void  * __reserved1;  /* reserved for dependency checking  */ };
Plugin Types Define the plugin type (types listed below) Used within plugin functions such as plugin_foreach() MYSQL_UDF_PLUGIN   0  /* User-defined function  */ MYSQL_STORAGE_ENGINE_PLUGIN   1  /* Storage Engine  */ MYSQL_FTPARSER_PLUGIN   2  /* Full-text parser plugin  */ MYSQL_DAEMON_PLUGIN   3  /* The daemon/raw plugin type */ MYSQL_INFORMATION_SCHEMA_PLUGIN  4  /* The I_S plugin type  */ I_S plugins loaded within sql/sql_show.cc int  schema_tables_add(THD *thd, List<LEX_STRING> *files,  const   char  *wild) { … if  (plugin_foreach(thd, add_schema_table, MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))  DBUG_RETURN( 1 );
Starting a HELLO_WORLD Table Must have MySQL source tree Create a new plugin/hello_world/hello_world.cc file plugin.h and mysql_priv.h includes required Add a prototype for schema_table_store_record() /* Required for schema_table_store_record() * / #include &quot;mysql_priv.h&quot; #include <mysql/plugin.h> bool  schema_table_store_record(THD *thd, TABLE *table);
Define the Table Structure Uses an array of  ST_FIELD_INFO  structs field_name Column name field_length Column length or display length field_type Column datatype value Not used within I_S plugins field_flags Set NULL / UNSIGNED attributes old_name Internal mapping for I_S tables to SHOW output open_method Open table using supplied method Last entry in the array is an end marker ST_FIELD_INFO hello_world_fields[]= { { &quot;HELLO&quot; ,  10 , MYSQL_TYPE_STRING,  0 ,  0 ,  &quot;Hello&quot; ,  0 }, { &quot;WORLD&quot; ,  10 , MYSQL_TYPE_STRING,  0 ,  0 ,  &quot;World&quot; ,  0 }, { 0 ,  0 , MYSQL_TYPE_NULL,  0 ,  0 ,  0 ,  0 } };
A Closer Look Field_type Field_flags Open_method VARCHAR INT BIGINT DECIMAL DATETIME MYSQL_TYPE_STRING MYSQL_TYPE_LONG MYSQL_TYPE_LONGLONG MYSQL_TYPE_DECIMAL MYSQL_TYPE_DATETIME MY_I_S_MAYBE_NULL MY_I_S_UNSIGNED SKIP_OPEN_TABLE  OPEN_FRM_ONLY OPEN_FULL_TABLE
Define Function to Fill Table Called every time the table is accessed Fills the virtual table with data int  fill_hello_world(THD *thd, TABLE_LIST *tables, COND *cond) { DBUG_ENTER( &quot;fill_hello_world_is_plugin&quot; ); CHARSET_INFO *scs= system_charset_info; TABLE *table= tables->table; int  rc=  0 ; table->field[ 0 ]->store( &quot;Hello&quot; , strlen( &quot;Hello&quot; ), scs); table->field[ 1 ]->store( &quot;World&quot; , strlen( &quot;World&quot; ), scs); if  (schema_table_store_record(thd, table)) rc=  1 ; DBUG_RETURN(rc); }
Create the Init Function Runs when the plugin is installed/loaded ST_SCHEMA_TABLE  is an internal table representation Points to the  ST_FIELD_INFO  struct / table definition Points to the function to fill the table Manages any other init needed for the plugin int  hello_world_plugin_init( void  *p) { DBUG_ENTER( &quot;init_hello_world_is_plugin&quot; ); ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE*) p;  schema->fields_info= hello_world_fields; schema->fill_table= fill_hello_world; DBUG_RETURN( 0 ); }
Create the Deinit Function Run when the plugin is unloaded Does nothing for HELLO_WORLD Use this function to do any clean up in your plugin int  hello_world_plugin_deinit( void  *p) { DBUG_ENTER( &quot;deinit_info_schema_example_plugin&quot; ); DBUG_RETURN( 0 ); }
Create the Plugin Definition  Info struct points to the interface version built against struct  st_mysql_information_schema hello_world_plugin_info= { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };  mysql_declare_plugin(hello_world_plugin) { MYSQL_INFORMATION_SCHEMA_PLUGIN, &hello_world_plugin_info,  /* Pointer to info struct */ &quot;HELLO_WORLD&quot; ,  /* Plugin Name (used in INSTALL PLUGIN) */ &quot;Mark Leith, MySQL AB&quot; ,  /* Plugin Author */ &quot;HELLO_WORLD example plugin&quot; , /* Plugin Description */ PLUGIN_LICENSE_GPL,  /* _GPL, _BSD or _PROPRIETARY */ hello_world_plugin_init,  /* Pointer to plugin init function */ hello_world_plugin_deinit,  /* Pointer to plugin deinit function */ 0x0100 ,  /* 1.0 */ NULL ,  /* status variables */ NULL ,  /* system variables */ NULL   /* config options */ } mysql_declare_plugin_end;
Build the Plugin Define MYSQL_DYNAMIC_PLUGIN Make shared Include the  sql  and  include  source directories g++ -DMYSQL_DYNAMIC_PLUGIN -shared > -I/home/leithal/mysql/mysql-5.1/include > -I/home/leithal/mysql/mysql-5.1/sql > -o is_hello_world.so hello_world.cc ls -l total 16 -rw-r--r-- 1 leithal leithal 1712 2008-04-11 14:20 hello_world.cc -rwxr-xr-x 1 leithal leithal 8226 2008-04-11 14:27 is_hello_world.so cp is_hello_world.so /usr/local/mysql/lib/mysql/plugin
Install and Use! mysql> INSTALL PLUGIN HELLO_WORLD SONAME 'is_hello_world.so'; Query OK, 0 rows affected (0.01 sec) mysql> USE INFORMATION_SCHEMA; Database changed mysql> SHOW TABLES LIKE 'HELL%'; +--------------------------------------+ | Tables_in_information_schema (HELL%) | +--------------------------------------+ | HELLO_WORLD  | +--------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM HELLO_WORLD; +-------+-------+ | HELLO | WORLD | +-------+-------+ | Hello | World | +-------+-------+ 1 row in set (0.00 sec)
So We'll Do Something Interesting How's the disk space doing on my db server? root@achilles:~# df -h Filesystem  Size  Used Avail Use% Mounted on /dev/hda1  4.6G  3.5G  886M  81% / varrun  126M  84K  125M  1% /var/run varlock  126M  0  126M  0% /var/lock procbususb  10M  76K  10M  1% /proc/bus/usb udev  10M  76K  10M  1% /dev devshm  126M  0  126M  0% /dev/shm lrm  126M  18M  108M  14% /lib/modules/2.6.17-12-generic/volatile If I can get this in a table I can track it over time I can also report on it easily How about an I_S table with events to catalog?
Create Template & Table Structure  Add stdio.h,string.h and stdlib.h includes Mirror init, deinit and info functions Fill in the plugin declaration scruct appropriately Define the new table: ST_FIELD_INFO fs_info_schema_fields[]= { { &quot;FILESYSTEM&quot; ,  120 , MYSQL_TYPE_STRING,  0 ,  0 ,  &quot;Filesystem&quot; ,  0 }, { &quot;SIZE&quot; ,  8 , MYSQL_TYPE_LONGLONG,  0 ,  0 ,  &quot;Mountpoint Size&quot; ,  0 }, { &quot;USED&quot; ,  8 , MYSQL_TYPE_LONGLONG,  0 ,  0 ,  &quot;Used Space&quot; ,  0 }, { &quot;AVAILABLE&quot; ,  8 , MYSQL_TYPE_LONGLONG,  0 ,  0 ,  &quot;Available Space&quot; ,  0 }, { &quot;CAPACITY&quot; ,  4 , MYSQL_TYPE_STRING,  0 ,  0 ,  &quot;Percent Used&quot; ,  0 }, { &quot;MOUNTED_ON&quot; ,  120 , MYSQL_TYPE_STRING,  0 ,  0 ,  &quot;Filesystem Mounted On&quot;  ,  0 }, { 0 ,  0 , MYSQL_TYPE_STRING,  0 ,  0 ,  0 ,  0 } };
Running Other Programs Open with popen() and read in the results /* get filesystem information from df on linux like systems */ FILE *f; char  buf[ 128 ]; char   *c, *s, *size; const   char  delim[]=  &quot; &quot; ; unsigned   long   long  uli; double  d; if  ( NULL  != (f= popen( &quot;/bin/df -h&quot; ,  &quot;r&quot; ))) { int  ln=  0 ; while (!feof(f)) { fgets(buf,  sizeof (buf), f); switch (ln++)  {
Tokenize and Push Results Can do this how you like /* skip the header line of df */ case   0 :  break ; default : c= buf;  /* hack to stop processing when falling off the end of output */   if  (strchr(c,  ' ' ) ==  NULL ) break ;  /* Filesystem */   s= strtok(c, delim); table->field[ 0 ]->store(s, strlen(s), scs); /* Size */   s= strtok( NULL , delim);  d= strtod(s, &size);  uli= get_bytes(d, size); table->field[ 1 ]->store(uli,  TRUE );  … .
Store the Row and Finish up /* Use% */ s= strtok( NULL , delim); table->field[ 4 ]->store(s, strlen(s), scs); /* Mountpoint */ s= strtok( NULL , delim); stripnl(s); table->field[ 5 ]->store(s, strlen(s), scs); /* store the row */ if  (schema_table_store_record(thd, table)) rc=  1 ; break ; } } pclose(f); } else   rc=  1 ; DBUG_RETURN(rc); }
Build, Install, Try.. Build as before and try it out! mysql> select * from file_system_mountpoints; +------------+------------+------------+-----------+----------+-----------------------------------------+ | FILESYSTEM | SIZE  | USED  | AVAILABLE | CAPACITY | MOUNTED_ON  | +------------+------------+------------+-----------+----------+-----------------------------------------+ | /dev/hda1  | 4939212390 | 3758096384 | 930086912 | 81%  | /  |  | varrun  |  132120576 |  86016 | 131072000 | 1%  | /var/run  |  | varlock  |  132120576 |  0 | 132120576 | 0%  | /var/lock  |  | procbususb |  10485760 |  77824 |  10485760 | 1%  | /proc/bus/usb  |  | udev  |  10485760 |  77824 |  10485760 | 1%  | /dev  |  | devshm  |  132120576 |  0 | 132120576 | 0%  | /dev/shm  |  | lrm  |  132120576 |  18874368 | 113246208 | 14%  | /lib/modules/2.6.17-12-generic/volatile |  +------------+------------+------------+-----------+----------+-----------------------------------------+ 7 rows in set (0.06 sec) mysql> desc file_system_mountpoints; +------------+--------------+------+-----+---------+-------+ | Field  | Type  | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | FILESYSTEM | varchar(120) | NO  |  |  |  |  | SIZE  | bigint(11)  | NO  |  | 0  |  |  | USED  | bigint(11)  | NO  |  | 0  |  |  | AVAILABLE  | bigint(11)  | NO  |  | 0  |  |  | CAPACITY  | varchar(4)  | NO  |  |  |  |  | MOUNTED_ON | varchar(120) | NO  |  |  |  |  +------------+--------------+------+-----+---------+-------+ 6 rows in set (0.01 sec)
Now Let's Use another Library The SIGAR library from Hyperic Lets us do cross platform OS stats monitoring Released under GPL Again, start with the same base functions etc. as before
Include Lib Header, Use Lib in Fill sigar_t *t; sigar_open(&t); sigar_file_system_list_t fslist; sigar_file_system_list_get(t, &fslist); for  (uint i =  0 ; i < fslist.number; i++)  { sigar_file_system_t fs = fslist.data[i]; sigar_file_system_usage_t fsusage; rc= sigar_file_system_usage_get(t, fs.dir_name, &fsusage); if  (fs.type ==  2  || fs.type ==  3 ) { table->field[ 0 ]->store(fs.dir_name, strlen(fs.dir_name), scs); table->field[ 1 ]->store(fsusage.total,  TRUE ); table->field[ 2 ]->store(fsusage.used,  TRUE ); table->field[ 3 ]->store(fsusage.free,  TRUE ); table->field[ 4 ]->store(fsusage.files,  TRUE ); if  (schema_table_store_record(thd, table)) rc=  1 ; } } sigar_file_system_list_destroy(t, &fslist); sigar_close(t);
Building and Including the Library -lsigar links the library Use -rpath to pass in library location  This is for runtime Can also use LD_LIBRARY_PATH  -L (linker) and -I (include) paths  -L points to the directory with the built library g++ -DMYSQL_DYNAMIC_PLUGIN -Wall -shared -lsigar -Wl,-rpath -Wl,/home/leithal/os_stats_info_schema/sigar/ -L/home/leithal/os_stats_info_schema/sigar/ -I/home/leithal/os_stats_info_schema/sigar/include/ -I/home/leithal/mysql/mysql-5.1/include -I/home/leithal/mysql/mysql-5.1/sql -o os_stats_info_schema.so os_stats_info_schema.cc
Try it out! mysql> INSTALL PLUGIN os_disk_usage SONAME 'os_stats_info_schema.so'; Query OK, 0 rows affected (0.00 sec) mysql> SHOW TABLES LIKE 'OS%'; +------------------------------------+ | Tables_in_information_schema (OS%) | +------------------------------------+ | OS_DISK_USAGE  |  +------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM OS_DISK_USAGE; +------------+---------+---------+---------+--------+ | FILESYSTEM | SIZE  | USED  | FREE  | FILES  | +------------+---------+---------+---------+--------+ | /  | 4799024 | 3656800 | 1142224 | 610432 |  +------------+---------+---------+---------+--------+ 1 row in set (0.00 sec)
Resources and Questions! http://www.markleith.co.uk/?p=18 http://rpbouman.blogspot.com/2008/02/mysql-information-schema-plugins-best.html http://rpbouman.blogspot.com/2008/02/reporting-mysql-internals-with.html  (Great resource for monitoring server internals) Questions?

More Related Content

What's hot

Getting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorGetting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise Monitor
Mark Leith
 
Mysql tech day_paris_ps_and_sys
Mysql tech day_paris_ps_and_sysMysql tech day_paris_ps_and_sys
Mysql tech day_paris_ps_and_sys
Mark Leith
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
Mark Leith
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
Mark Leith
 
MySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench IntegrationMySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench Integration
Mario Beck
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
Ted Wennmark
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
Mark Leith
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
Mark Leith
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
Sveta Smirnova
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
Padraig O'Sullivan
 
Oracle Database 11g Product Family
Oracle Database 11g Product FamilyOracle Database 11g Product Family
Oracle Database 11g Product Family
N/A
 
What's next after Upgrade to 12c
What's next after Upgrade to 12cWhat's next after Upgrade to 12c
What's next after Upgrade to 12c
Guatemala User Group
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry Osborne
Enkitec
 
MySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaMySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance Schema
Sveta Smirnova
 
REST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using RESTREST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using REST
Christian Gohmann
 
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
Alex Zaballa
 
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Alex Zaballa
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
Pluggable database tutorial 2
Pluggable database tutorial 2Pluggable database tutorial 2
Pluggable database tutorial 2
Osama Mustafa
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
Ronald Bradford
 

What's hot (20)

Getting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorGetting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise Monitor
 
Mysql tech day_paris_ps_and_sys
Mysql tech day_paris_ps_and_sysMysql tech day_paris_ps_and_sys
Mysql tech day_paris_ps_and_sys
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
 
MySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench IntegrationMySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench Integration
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
 
Oracle Database 11g Product Family
Oracle Database 11g Product FamilyOracle Database 11g Product Family
Oracle Database 11g Product Family
 
What's next after Upgrade to 12c
What's next after Upgrade to 12cWhat's next after Upgrade to 12c
What's next after Upgrade to 12c
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry Osborne
 
MySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaMySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance Schema
 
REST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using RESTREST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using REST
 
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
 
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
 
Pluggable database tutorial 2
Pluggable database tutorial 2Pluggable database tutorial 2
Pluggable database tutorial 2
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
 

Similar to Developing Information Schema Plugins

Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
olegmmiller
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
Amit Kumar Singh
 
MySQL 5.5
MySQL 5.5MySQL 5.5
MySQL 5.5
Ligaya Turmelle
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
Gordon Forsythe
 
Php
PhpPhp
Php frameworks
Php frameworksPhp frameworks
Php frameworks
Anil Kumar Panigrahi
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
Harsha Nagaraj
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
Federico Razzoli
 
Sah
SahSah
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
mohamed ashraf
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
Ranjan Kumar
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Tools of the CPAN Ninja
Tools of the CPAN NinjaTools of the CPAN Ninja
Tools of the CPAN Ninja
Aran Deltac
 
Raj mysql
Raj mysqlRaj mysql
Raj mysql
firstplanet
 
02 create first-map
02 create first-map02 create first-map
02 create first-map
Sébastien Deleuze
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
Nuvole
 

Similar to Developing Information Schema Plugins (20)

Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
 
MySQL 5.5
MySQL 5.5MySQL 5.5
MySQL 5.5
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Php
PhpPhp
Php
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
 
Sah
SahSah
Sah
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Tools of the CPAN Ninja
Tools of the CPAN NinjaTools of the CPAN Ninja
Tools of the CPAN Ninja
 
Raj mysql
Raj mysqlRaj mysql
Raj mysql
 
02 create first-map
02 create first-map02 create first-map
02 create first-map
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 

Recently uploaded

Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
anupriti
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
The Digital Insurer
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
anupriti
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
HackersList
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
Larry Smarr
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
crioux1
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
uuuot
 

Recently uploaded (20)

Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
 

Developing Information Schema Plugins

  • 1. Developing INFORMATION_SCHEMA Plugins Mark Leith Support Manager, Americas [email_address]
  • 2. Overview INFORMATION_SCHEMA overview Plugin Overview Developing a simple Hello World I_S table Building and installing Interacting with another program Interacting with another library
  • 3. INFORMATION_SCHEMA Specified within the SQL Standard (ISO/IEC 9075-11:2003) ‏ Virtual tables which give database metadata MySQL implements a subset of the Standard http://dev.mysql.com/doc/refman/5.1/en/information-schema.html http://www. xcdsql .org/MySQL/information_schema/5.1/MySQL_5_1_INFORMATION_SCHEMA.html
  • 4.  
  • 5. Plugins A means to load shared libraries in to a running MySQL instance Developed in C/C++ http://dev.mysql.com/doc/refman/5.1/en/plugin-api.html User Defined Functions Storage Engines Fulltext parsers Daemons INFORMATION_SCHEMA Tables!
  • 6. Located in include/mysql/plugin.h The Plugin Interface struct st_mysql_plugin { int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */ void *info; /* pointer to type-specific plugin descriptor */ const char *name; /* plugin name */ const char *author; /* plugin author (for SHOW PLUGINS) */ const char *descr; /* general descriptive text (for SHOW PLUGINS ) */ int license; /* the plugin license (PLUGIN_LICENSE_XXX) */ int (*init)( void *); /* the function to invoke when plugin is loaded */ int (*deinit)( void *) /* the function to invoke when plugin is unloaded */ unsigned int version; /* plugin version (for SHOW PLUGINS) */ struct st_mysql_show_var *status_vars; struct st_mysql_sys_var **system_vars; void * __reserved1; /* reserved for dependency checking */ };
  • 7. Plugin Types Define the plugin type (types listed below) Used within plugin functions such as plugin_foreach() MYSQL_UDF_PLUGIN 0 /* User-defined function */ MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */ MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */ MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */ MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */ I_S plugins loaded within sql/sql_show.cc int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild) { … if (plugin_foreach(thd, add_schema_table, MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data)) DBUG_RETURN( 1 );
  • 8. Starting a HELLO_WORLD Table Must have MySQL source tree Create a new plugin/hello_world/hello_world.cc file plugin.h and mysql_priv.h includes required Add a prototype for schema_table_store_record() /* Required for schema_table_store_record() * / #include &quot;mysql_priv.h&quot; #include <mysql/plugin.h> bool schema_table_store_record(THD *thd, TABLE *table);
  • 9. Define the Table Structure Uses an array of ST_FIELD_INFO structs field_name Column name field_length Column length or display length field_type Column datatype value Not used within I_S plugins field_flags Set NULL / UNSIGNED attributes old_name Internal mapping for I_S tables to SHOW output open_method Open table using supplied method Last entry in the array is an end marker ST_FIELD_INFO hello_world_fields[]= { { &quot;HELLO&quot; , 10 , MYSQL_TYPE_STRING, 0 , 0 , &quot;Hello&quot; , 0 }, { &quot;WORLD&quot; , 10 , MYSQL_TYPE_STRING, 0 , 0 , &quot;World&quot; , 0 }, { 0 , 0 , MYSQL_TYPE_NULL, 0 , 0 , 0 , 0 } };
  • 10. A Closer Look Field_type Field_flags Open_method VARCHAR INT BIGINT DECIMAL DATETIME MYSQL_TYPE_STRING MYSQL_TYPE_LONG MYSQL_TYPE_LONGLONG MYSQL_TYPE_DECIMAL MYSQL_TYPE_DATETIME MY_I_S_MAYBE_NULL MY_I_S_UNSIGNED SKIP_OPEN_TABLE OPEN_FRM_ONLY OPEN_FULL_TABLE
  • 11. Define Function to Fill Table Called every time the table is accessed Fills the virtual table with data int fill_hello_world(THD *thd, TABLE_LIST *tables, COND *cond) { DBUG_ENTER( &quot;fill_hello_world_is_plugin&quot; ); CHARSET_INFO *scs= system_charset_info; TABLE *table= tables->table; int rc= 0 ; table->field[ 0 ]->store( &quot;Hello&quot; , strlen( &quot;Hello&quot; ), scs); table->field[ 1 ]->store( &quot;World&quot; , strlen( &quot;World&quot; ), scs); if (schema_table_store_record(thd, table)) rc= 1 ; DBUG_RETURN(rc); }
  • 12. Create the Init Function Runs when the plugin is installed/loaded ST_SCHEMA_TABLE is an internal table representation Points to the ST_FIELD_INFO struct / table definition Points to the function to fill the table Manages any other init needed for the plugin int hello_world_plugin_init( void *p) { DBUG_ENTER( &quot;init_hello_world_is_plugin&quot; ); ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE*) p; schema->fields_info= hello_world_fields; schema->fill_table= fill_hello_world; DBUG_RETURN( 0 ); }
  • 13. Create the Deinit Function Run when the plugin is unloaded Does nothing for HELLO_WORLD Use this function to do any clean up in your plugin int hello_world_plugin_deinit( void *p) { DBUG_ENTER( &quot;deinit_info_schema_example_plugin&quot; ); DBUG_RETURN( 0 ); }
  • 14. Create the Plugin Definition Info struct points to the interface version built against struct st_mysql_information_schema hello_world_plugin_info= { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; mysql_declare_plugin(hello_world_plugin) { MYSQL_INFORMATION_SCHEMA_PLUGIN, &hello_world_plugin_info, /* Pointer to info struct */ &quot;HELLO_WORLD&quot; , /* Plugin Name (used in INSTALL PLUGIN) */ &quot;Mark Leith, MySQL AB&quot; , /* Plugin Author */ &quot;HELLO_WORLD example plugin&quot; , /* Plugin Description */ PLUGIN_LICENSE_GPL, /* _GPL, _BSD or _PROPRIETARY */ hello_world_plugin_init, /* Pointer to plugin init function */ hello_world_plugin_deinit, /* Pointer to plugin deinit function */ 0x0100 , /* 1.0 */ NULL , /* status variables */ NULL , /* system variables */ NULL /* config options */ } mysql_declare_plugin_end;
  • 15. Build the Plugin Define MYSQL_DYNAMIC_PLUGIN Make shared Include the sql and include source directories g++ -DMYSQL_DYNAMIC_PLUGIN -shared > -I/home/leithal/mysql/mysql-5.1/include > -I/home/leithal/mysql/mysql-5.1/sql > -o is_hello_world.so hello_world.cc ls -l total 16 -rw-r--r-- 1 leithal leithal 1712 2008-04-11 14:20 hello_world.cc -rwxr-xr-x 1 leithal leithal 8226 2008-04-11 14:27 is_hello_world.so cp is_hello_world.so /usr/local/mysql/lib/mysql/plugin
  • 16. Install and Use! mysql> INSTALL PLUGIN HELLO_WORLD SONAME 'is_hello_world.so'; Query OK, 0 rows affected (0.01 sec) mysql> USE INFORMATION_SCHEMA; Database changed mysql> SHOW TABLES LIKE 'HELL%'; +--------------------------------------+ | Tables_in_information_schema (HELL%) | +--------------------------------------+ | HELLO_WORLD | +--------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM HELLO_WORLD; +-------+-------+ | HELLO | WORLD | +-------+-------+ | Hello | World | +-------+-------+ 1 row in set (0.00 sec)
  • 17. So We'll Do Something Interesting How's the disk space doing on my db server? root@achilles:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/hda1 4.6G 3.5G 886M 81% / varrun 126M 84K 125M 1% /var/run varlock 126M 0 126M 0% /var/lock procbususb 10M 76K 10M 1% /proc/bus/usb udev 10M 76K 10M 1% /dev devshm 126M 0 126M 0% /dev/shm lrm 126M 18M 108M 14% /lib/modules/2.6.17-12-generic/volatile If I can get this in a table I can track it over time I can also report on it easily How about an I_S table with events to catalog?
  • 18. Create Template & Table Structure Add stdio.h,string.h and stdlib.h includes Mirror init, deinit and info functions Fill in the plugin declaration scruct appropriately Define the new table: ST_FIELD_INFO fs_info_schema_fields[]= { { &quot;FILESYSTEM&quot; , 120 , MYSQL_TYPE_STRING, 0 , 0 , &quot;Filesystem&quot; , 0 }, { &quot;SIZE&quot; , 8 , MYSQL_TYPE_LONGLONG, 0 , 0 , &quot;Mountpoint Size&quot; , 0 }, { &quot;USED&quot; , 8 , MYSQL_TYPE_LONGLONG, 0 , 0 , &quot;Used Space&quot; , 0 }, { &quot;AVAILABLE&quot; , 8 , MYSQL_TYPE_LONGLONG, 0 , 0 , &quot;Available Space&quot; , 0 }, { &quot;CAPACITY&quot; , 4 , MYSQL_TYPE_STRING, 0 , 0 , &quot;Percent Used&quot; , 0 }, { &quot;MOUNTED_ON&quot; , 120 , MYSQL_TYPE_STRING, 0 , 0 , &quot;Filesystem Mounted On&quot; , 0 }, { 0 , 0 , MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 } };
  • 19. Running Other Programs Open with popen() and read in the results /* get filesystem information from df on linux like systems */ FILE *f; char buf[ 128 ]; char *c, *s, *size; const char delim[]= &quot; &quot; ; unsigned long long uli; double d; if ( NULL != (f= popen( &quot;/bin/df -h&quot; , &quot;r&quot; ))) { int ln= 0 ; while (!feof(f)) { fgets(buf, sizeof (buf), f); switch (ln++) {
  • 20. Tokenize and Push Results Can do this how you like /* skip the header line of df */ case 0 : break ; default : c= buf; /* hack to stop processing when falling off the end of output */ if (strchr(c, ' ' ) == NULL ) break ; /* Filesystem */ s= strtok(c, delim); table->field[ 0 ]->store(s, strlen(s), scs); /* Size */ s= strtok( NULL , delim); d= strtod(s, &size); uli= get_bytes(d, size); table->field[ 1 ]->store(uli, TRUE ); … .
  • 21. Store the Row and Finish up /* Use% */ s= strtok( NULL , delim); table->field[ 4 ]->store(s, strlen(s), scs); /* Mountpoint */ s= strtok( NULL , delim); stripnl(s); table->field[ 5 ]->store(s, strlen(s), scs); /* store the row */ if (schema_table_store_record(thd, table)) rc= 1 ; break ; } } pclose(f); } else rc= 1 ; DBUG_RETURN(rc); }
  • 22. Build, Install, Try.. Build as before and try it out! mysql> select * from file_system_mountpoints; +------------+------------+------------+-----------+----------+-----------------------------------------+ | FILESYSTEM | SIZE | USED | AVAILABLE | CAPACITY | MOUNTED_ON | +------------+------------+------------+-----------+----------+-----------------------------------------+ | /dev/hda1 | 4939212390 | 3758096384 | 930086912 | 81% | / | | varrun | 132120576 | 86016 | 131072000 | 1% | /var/run | | varlock | 132120576 | 0 | 132120576 | 0% | /var/lock | | procbususb | 10485760 | 77824 | 10485760 | 1% | /proc/bus/usb | | udev | 10485760 | 77824 | 10485760 | 1% | /dev | | devshm | 132120576 | 0 | 132120576 | 0% | /dev/shm | | lrm | 132120576 | 18874368 | 113246208 | 14% | /lib/modules/2.6.17-12-generic/volatile | +------------+------------+------------+-----------+----------+-----------------------------------------+ 7 rows in set (0.06 sec) mysql> desc file_system_mountpoints; +------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | FILESYSTEM | varchar(120) | NO | | | | | SIZE | bigint(11) | NO | | 0 | | | USED | bigint(11) | NO | | 0 | | | AVAILABLE | bigint(11) | NO | | 0 | | | CAPACITY | varchar(4) | NO | | | | | MOUNTED_ON | varchar(120) | NO | | | | +------------+--------------+------+-----+---------+-------+ 6 rows in set (0.01 sec)
  • 23. Now Let's Use another Library The SIGAR library from Hyperic Lets us do cross platform OS stats monitoring Released under GPL Again, start with the same base functions etc. as before
  • 24. Include Lib Header, Use Lib in Fill sigar_t *t; sigar_open(&t); sigar_file_system_list_t fslist; sigar_file_system_list_get(t, &fslist); for (uint i = 0 ; i < fslist.number; i++) { sigar_file_system_t fs = fslist.data[i]; sigar_file_system_usage_t fsusage; rc= sigar_file_system_usage_get(t, fs.dir_name, &fsusage); if (fs.type == 2 || fs.type == 3 ) { table->field[ 0 ]->store(fs.dir_name, strlen(fs.dir_name), scs); table->field[ 1 ]->store(fsusage.total, TRUE ); table->field[ 2 ]->store(fsusage.used, TRUE ); table->field[ 3 ]->store(fsusage.free, TRUE ); table->field[ 4 ]->store(fsusage.files, TRUE ); if (schema_table_store_record(thd, table)) rc= 1 ; } } sigar_file_system_list_destroy(t, &fslist); sigar_close(t);
  • 25. Building and Including the Library -lsigar links the library Use -rpath to pass in library location This is for runtime Can also use LD_LIBRARY_PATH -L (linker) and -I (include) paths -L points to the directory with the built library g++ -DMYSQL_DYNAMIC_PLUGIN -Wall -shared -lsigar -Wl,-rpath -Wl,/home/leithal/os_stats_info_schema/sigar/ -L/home/leithal/os_stats_info_schema/sigar/ -I/home/leithal/os_stats_info_schema/sigar/include/ -I/home/leithal/mysql/mysql-5.1/include -I/home/leithal/mysql/mysql-5.1/sql -o os_stats_info_schema.so os_stats_info_schema.cc
  • 26. Try it out! mysql> INSTALL PLUGIN os_disk_usage SONAME 'os_stats_info_schema.so'; Query OK, 0 rows affected (0.00 sec) mysql> SHOW TABLES LIKE 'OS%'; +------------------------------------+ | Tables_in_information_schema (OS%) | +------------------------------------+ | OS_DISK_USAGE | +------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM OS_DISK_USAGE; +------------+---------+---------+---------+--------+ | FILESYSTEM | SIZE | USED | FREE | FILES | +------------+---------+---------+---------+--------+ | / | 4799024 | 3656800 | 1142224 | 610432 | +------------+---------+---------+---------+--------+ 1 row in set (0.00 sec)
  • 27. Resources and Questions! http://www.markleith.co.uk/?p=18 http://rpbouman.blogspot.com/2008/02/mysql-information-schema-plugins-best.html http://rpbouman.blogspot.com/2008/02/reporting-mysql-internals-with.html (Great resource for monitoring server internals) Questions?