Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. use DBI;
  7. use JSON;
  8.  
  9. my $dsn = "dbi:mysql:performance_schema";
  10. $dsn .= ";mysql_socket=/usr/mysql/5.7.18/data/mysql.sock";
  11. my $user= "root";
  12. my $pass= "";
  13. my $conn= DBI->connect($dsn, $user, $pass);
  14.  
  15. if ($ENV{MACKEREL_AGENT_PLUGIN_META})
  16. {
  17. print("# mackerel-agent-plugin\n");
  18. 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')");
  19. my @metrics = map { {name => $_->[0], label => $_->[0]} } @$metric_column;
  20. my $meta=
  21. {
  22. graphs =>
  23. {
  24. "tables.count_read" =>
  25. {
  26. label => "count_read",
  27. unit => "integer",
  28. metrics =>
  29. [
  30. @metrics,
  31. ]
  32. },
  33. "tables.count_write" =>
  34. {
  35. label => "count_write",
  36. unit => "integer",
  37. metrics =>
  38. [
  39. @metrics,
  40. ]
  41. },
  42. }
  43. };
  44.  
  45. print(to_json($meta));
  46. }
  47. else
  48. {
  49. my $time = time();
  50. 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"]);
  51.  
  52. foreach (keys(%$result))
  53. {
  54. printf("tables.count_read.%s\t%d\t%s\n", $_, $result->{$_}->{count_read}, $time);
  55. printf("tables.count_write.%s\t%d\t%s\n", $_, $result->{$_}->{count_write}, $time);
  56. }
  57. }
  58.  
  59. $conn->disconnect;
  60.  
  61. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement