root / plugins / drupal / drupal_files_total.php @ 29bdf34e
Historique | Voir | Annoter | Télécharger (1,94 ko)
| 1 | 98e396b3 | Liran Tal | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php
|
||
| 3 | /**
|
||
| 4 | * Drupal Files Total
|
||
| 5 | * Munin plugin to count total files uploads
|
||
| 6 | *
|
||
| 7 | * It's required to define a container entry for this plugin in your
|
||
| 8 | * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
|
||
| 9 | *
|
||
| 10 | * @example Example entry for configuration:
|
||
| 11 | * [drupal*]
|
||
| 12 | daac83c4 | Mohammad Shokri | * env.db drupal
|
| 13 | * env.user mysql_user
|
||
| 14 | * env.pass mysql_pass
|
||
| 15 | * env.host localhost
|
||
| 16 | * env.port 3306
|
||
| 17 | * env.table_prefix drupal_
|
||
| 18 | 98e396b3 | Liran Tal | *
|
| 19 | * @author Liran Tal <liran.tal@hp.com>
|
||
| 20 | * @version 1.0 2013
|
||
| 21 | *
|
||
| 22 | */
|
||
| 23 | |||
| 24 | |||
| 25 | /**
|
||
| 26 | * Environment variabels are set by munin's configuration
|
||
| 27 | * @see /etc/munin/plugin-conf.d/munin-node
|
||
| 28 | */
|
||
| 29 | $db = getenv('db'); |
||
| 30 | $host = getenv('host'); |
||
| 31 | $user = getenv('user'); |
||
| 32 | $pass = getenv('pass'); |
||
| 33 | $port = getenv('port'); |
||
| 34 | if (!$port) |
||
| 35 | $port = 3306; |
||
| 36 | |||
| 37 | $graph_period = getenv('graph_period'); |
||
| 38 | |||
| 39 | if(count($argv) == 2 && $argv[1] == 'autoconf') { |
||
| 40 | echo "yes\n"; |
||
| 41 | exit(0); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (count($argv) === 2 && $argv[1] === 'config') { |
||
| 45 | echo "graph_title Drupal Total Files\n"; |
||
| 46 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 47 | echo "graph_vlabel Files Count / ${graph_period}\n"; |
||
| 48 | 29bdf34e | dipohl | echo "graph_category cms\n"; |
| 49 | 98e396b3 | Liran Tal | echo "graph_scale no\n"; |
| 50 | echo "graph_info Displays the online files uploaded to your Drupal site\n"; |
||
| 51 | |||
| 52 | echo "files_total.label total files\n"; |
||
| 53 | echo "files_total.type GAUGE\n"; |
||
| 54 | echo "files_total.min 0\n"; |
||
| 55 | |||
| 56 | exit(0); |
||
| 57 | } |
||
| 58 | |||
| 59 | // Connect to database
|
||
| 60 | $dbh = new mysqli($host, $user, $pass, $db, $port); |
||
| 61 | if (mysqli_connect_errno()) {
|
||
| 62 | echo "Connecction failed: ".mysqli_connect_error(). PHP_EOL; |
||
| 63 | exit(1); |
||
| 64 | } |
||
| 65 | |||
| 66 | // Print out the actual values
|
||
| 67 | $total_files = (int) get_all_files($dbh); |
||
| 68 | echo "files_total.value $total_files\n"; |
||
| 69 | |||
| 70 | $dbh->close();
|
||
| 71 | |||
| 72 | |||
| 73 | /**
|
||
| 74 | * Get count for all online users
|
||
| 75 | * @return integer $count total online users
|
||
| 76 | */
|
||
| 77 | function get_all_files(&$dbh = NULL) { |
||
| 78 | |||
| 79 | $table_prefix = getenv('table_prefix'); |
||
| 80 | |||
| 81 | $sql = "SELECT COUNT(fid) AS count FROM {$table_prefix}files"; |
||
| 82 | $result = $dbh->query($sql); |
||
| 83 | $row = $result->fetch_assoc(); |
||
| 84 | |||
| 85 | return (int) $row['count']; |
||
| 86 | |||
| 87 | } |
