Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- use DBI;
- use JSON;
- my $dsn = "dbi:mysql:performance_schema";
- $dsn .= ";mysql_socket=/usr/mysql/5.7.18/data/mysql.sock";
- my $user= "root";
- my $pass= "";
- my $conn= DBI->connect($dsn, $user, $pass);
- if ($ENV{MACKEREL_AGENT_PLUGIN_META})
- {
- print("# mackerel-agent-plugin\n");
- my $metric_column= $conn->selectall_arrayref("SELECT CONCAT(table_schema, '.', table_name) AS object FROM information_schema.tables WHERE table_schema NOT IN ('mysql', 'sys', 'performance_schema', 'information_schema')");
- my @metrics = map { {name => $_->[0], label => $_->[0]} } @$metric_column;
- my $meta=
- {
- graphs =>
- {
- "tables.count_read" =>
- {
- label => "count_read",
- unit => "integer",
- metrics =>
- [
- @metrics,
- ]
- },
- "tables.count_write" =>
- {
- label => "count_write",
- unit => "integer",
- metrics =>
- [
- @metrics,
- ]
- },
- }
- };
- print(to_json($meta));
- }
- else
- {
- my $time = time();
- my $result= $conn->selectall_hashref("SELECT CONCAT(object_schema, '.', object_name) AS object, count_read, count_write FROM table_io_waits_summary_by_table WHERE object_schema NOT IN ('mysql', 'sys', 'performance_schema', 'information_schema')", ["object"]);
- foreach (keys(%$result))
- {
- printf("tables.count_read.%s\t%d\t%s\n", $_, $result->{$_}->{count_read}, $time);
- printf("tables.count_write.%s\t%d\t%s\n", $_, $result->{$_}->{count_write}, $time);
- }
- }
- $conn->disconnect;
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement