mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
Workshop plugin
This commit is contained in:
1
plugin/proc_info/CMakeLists.txt
Normal file
1
plugin/proc_info/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
MYSQL_ADD_PLUGIN(PROC_INFO proc_info.cc RECOMPILE_FOR_EMBEDDED)
|
||||
3
plugin/proc_info/mysql-test/proc_info/basic.test
Normal file
3
plugin/proc_info/mysql-test/proc_info/basic.test
Normal file
@@ -0,0 +1,3 @@
|
||||
SHOW CREATE TABLE INFORMATION_SCHEMA.PROC_MEMINFO;
|
||||
query_vertical SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='proc_meminfo';
|
||||
SELECT * FROM INFORMATION_SCHEMA.PROC_MEMINFO;
|
||||
1
plugin/proc_info/mysql-test/proc_info/suite.opt
Normal file
1
plugin/proc_info/mysql-test/proc_info/suite.opt
Normal file
@@ -0,0 +1 @@
|
||||
--plugin-load-add=$PROC_INFO_SO --plugin-proc-meminfo=ON
|
||||
13
plugin/proc_info/mysql-test/proc_info/suite.pm
Normal file
13
plugin/proc_info/mysql-test/proc_info/suite.pm
Normal file
@@ -0,0 +1,13 @@
|
||||
package My::Suite::Proc_info;
|
||||
|
||||
@ISA = qw(My::Suite);
|
||||
|
||||
return "No PROC_INFO plugin" unless
|
||||
$ENV{PROC_INFO_SO} or
|
||||
$::mysqld_variables{'proc-info'} eq "ON";
|
||||
|
||||
return "Not run for embedded server" if $::opt_embedded_server;
|
||||
|
||||
sub is_default { 1 }
|
||||
|
||||
bless { };
|
||||
76
plugin/proc_info/proc_info.cc
Normal file
76
plugin/proc_info/proc_info.cc
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <my_global.h>
|
||||
#include <table.h>
|
||||
#include <sql_show.h>
|
||||
#include <sql_class.h>
|
||||
#include <mysql/plugin.h>
|
||||
|
||||
|
||||
static ST_FIELD_INFO fields[]=
|
||||
{
|
||||
{ "NAME", 100, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE },
|
||||
{ "VALUE", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, 0, SKIP_OPEN_TABLE },
|
||||
{ 0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static int fill(MYSQL_THD thd, TABLE_LIST *tables, COND *cond)
|
||||
{
|
||||
TABLE *table= tables->table;
|
||||
char name[1024];
|
||||
unsigned long value;
|
||||
FILE *fp;
|
||||
int res;
|
||||
|
||||
if (!(fp= fopen("/proc/meminfo", "r")))
|
||||
return 1;
|
||||
|
||||
while ((res= fscanf(fp, "%[^:]: %lu kB\n", name, &value)) != EOF)
|
||||
{
|
||||
if (res != 2)
|
||||
continue;
|
||||
table->field[0]->store(name, strlen(name), system_charset_info);
|
||||
table->field[1]->store(value);
|
||||
if (schema_table_store_record(thd, table))
|
||||
{
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int init(void *p)
|
||||
{
|
||||
ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *) p;
|
||||
|
||||
schema->fields_info= fields;
|
||||
schema->fill_table= fill;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct st_mysql_information_schema plugin=
|
||||
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
|
||||
|
||||
|
||||
maria_declare_plugin(proc_info)
|
||||
{
|
||||
MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
|
||||
&plugin, /* information schema */
|
||||
"PROC_MEMINFO", /* name */
|
||||
"" , /* author */
|
||||
"Useful information from /proc", /* description */
|
||||
PLUGIN_LICENSE_BSD, /* license */
|
||||
init, /* init callback */
|
||||
0, /* deinit callback */
|
||||
0x0100, /* version as hex */
|
||||
NULL, /* status variables */
|
||||
NULL, /* system variables */
|
||||
"1.0", /* version as a string */
|
||||
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL
|
||||
}
|
||||
maria_declare_plugin_end;
|
||||
Reference in New Issue
Block a user