Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / minecraft / minecraft-jsonapi-ramusage @ 9066b8ff

Historique | Voir | Annoter | Télécharger (1,43 ko)

1 bed58152 Jonas Friedmann
#!/usr/bin/php  
2
<?php
3
/**
4
 * Bukkit RAM usage Munin plugin
5
 * ---------------------------------
6
 *
7
 * Shows the current RAM usage of your Minecraft process
8
 * an the total RAM (parsed via JSONAPI)
9
 * 
10
 * Read more about my plugins on my blog: 
11
 * http://s.frd.mn/XJsryR
12
 *
13
 * Author: Jonas Friedmann (http://frd.mn)
14
 * 
15
 */
16
17
/**
18
 * JSONAPI configuration
19 007c2825 Jonas Friedmann
 * (get the SDK php file here: https://github.com/alecgorge/jsonapi/raw/master/sdk/php/JSONAPI.php)
20 bed58152 Jonas Friedmann
 */
21
22 007c2825 Jonas Friedmann
$apisdk   = '/var/cache/munin/JSONAPI.php';
23 bed58152 Jonas Friedmann
$hostname = 'your-hostname';
24
$username = 'your-username';
25
$password = 'your-password';
26
$salt     = 'your-salt';
27
$port     = 20059;
28
29
/**
30
 * !!! DO NOT EDIT THIS PART BELOW !!!
31
 */
32
33
if ((count($argv) > 1) && ($argv[1] == 'config'))
34
{
35 007c2825 Jonas Friedmann
  print("graph_title Bukkit / JSONAPI - RAM usage
36 bed58152 Jonas Friedmann
graph_category bukkit_jsonapi
37
graph_vlabel RAM usage in GB
38
graph_args --base 1024 -l 0
39
total.label total
40
total.type GAUGE
41
used.label used
42
used.type GAUGE
43
");
44 007c2825 Jonas Friedmann
  exit();
45 bed58152 Jonas Friedmann
}
46
47 007c2825 Jonas Friedmann
// Include JSONAPI.php
48
require($apisdk);
49 bed58152 Jonas Friedmann
50
// Prepare API call
51
$api = new JSONAPI($hostname, $port, $username, $password, $salt);
52
$result = $api->callMultiple(array(
53
  "system.getJavaMemoryUsage",
54
  "system.getJavaMemoryTotal"
55
  ), array(
56
  array(),
57
  array(),
58
));
59
60
// Check for success
61
if ($result['result'] == 'success'){
62
  // Print values
63
  print('used.value ' . round($result['success'][0]['success']/1000,2) . "\n");
64
  print('total.value ' . round($result['success'][1]['success']/1000,2) . "\n");
65
}
66
?>