[WEB/MISC] Minecraft munin v0.2

Discussion in 'Bukkit Tools' started by Jørgen André Ervilsæter, Mar 17, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Erviker

    Minecraft munin - The Minecraft munin link:
    Version: v0.2

    Requires:
    Linux
    MCstats2
    Munin


    Install:
    Debian/Ubuntu
    Show (open)

    In this tutorial I assume that you have MCstats2 install and working properly and that you have root access

    If you have an web server and php5 install on your system you can skip this step
    This step will install apache2 whit php5 and python whit json ;)
    Code:
    sudo apt-get install libapache2-mod-php5 python-anyjson
    
    Then install munin
    Code:
    sudo apt-get install munin
    
    Then download the plugings
    Code:
    wget http://home.erviker.hackz0r.net/minecraft/zip/minecraft_.zip
    
    Then extract the files
    Code:
    unzip minecraft_.zip
    

    Symlink MCstats2 stats so the munin plugin can access it ( this will allow make the html file available form the web server )
    Code:
    sudo ln -s /path/to/minecraft/server/plugins/MCStats2/stats/ /var/www/
    
    if you are using vhost (open)

    edit the files
    Code:
     $url="http://127.0.0.1/stats/mcstats.json";  
    to where your mcstats.json is hosted



    Add the files into folder, in /path/to/munin/plugins/ ( Debian/Ubuntu /usr/share/munin/plugins/ )
    Code:
    cp minecraft_blocks /usr/share/munin/plugins/
    cp minecraft_players /usr/share/munin/plugins/
    cp minecraft_blocks_per_type /usr/share/munin/plugins/
    cp minecraft_blocks_per_user_destroyed /usr/share/munin/plugins/
    cp minecraft_blocks_per_user_placed /usr/share/munin/plugins/
    cp minecraft_playtime /usr/share/munin/plugins/
    
    Then symlink the script to /path/to/munin/plugins/that/is/activated/ ( Debian/Ubuntu /etc/munin/plugins/ )
    Code:
    ln -s /usr/share/munin/plugins/minecraft_blocks /etc/munin/plugins/minecraft_blocks
    ln -s /usr/share/munin/plugins/minecraft_players /etc/munin/plugins/minecraft_players
    ln -s /usr/share/munin/plugins/minecraft_blocks_per_type /etc/munin/plugins/minecraft_blocks_per_type
    ln -s /usr/share/munin/plugins/minecraft_blocks_per_user_destroyed /etc/munin/plugins/minecraft_blocks_per_user_destroyed
    ln -s /usr/share/munin/plugins/minecraft_blocks_per_user_placed /etc/munin/plugins/minecraft_blocks_per_user_placed
    ln -s /usr/share/munin/plugins/minecraft_playtime /etc/munin/plugins/minecraft_playtime
     
    
    Restart munin
    Code:
    /etc/init.d/munin-node restart
    
    Finaly allow users to view munin stats
    edit /etc/apache2/conf.d/munin
    change
    Code:
    Allow from localhost 127.0.0.0/8 ::1
    
    to
    Code:
    Allow from all
    
    and restart apache
    Code:
    /etc/init.d/apache2 restart
    
    the graph will now appear at http://yourserver/munin

    Features:
    • Making graphs over how many blocks are distroyd and placed
    • Making graphs over how many players are online
    Download


    Change log:
    Version 0.2
    • more graphs!
    Version 0.1

    • Making Documentation for forum
    • Making the plugin working
    TO-DO:
    • making the script more dynamic and user friendly
    • FIX: reading json larger then 200KB( help??? any one ) itwhas just an error whit the data sett i used for testing
    • Setting up/choosing and bug tracker
    • Multi server
    • MORE GRAPH! MORE GRAPHS!
    If you have fixes or request pleas contact me :)
     

    Attached Files:

  2. Offline

    compwhizii

    Munin graphs for minecraft, what a great idea :D

    I <3 munin
     
  3. Offline

    Erviker

    me to :D munin is that shit
     
  4. Offline

    fffizzz

    Guess I'll work on setting this up today, great idea.. although i thought it wasd MRTG at first.
     
  5. Offline

    h0us3cat

    Can u make this work for windows?
     
  6. Offline

    Rilly

    Hi - I can't seem to get this working :( I know I'm doing something wrong..
    I have munin installed and working.. it is accessible via /var/www/munin
    My MCstats are also accessible via internet in folder /var/www/stats
    So... how do I make munin find those stats? I symlinked the stats folder so that its in /var/www/munin/stats but that isn't adding any charts to munin - i only have the standard charts.

    using ubuntu 10.04

    EDIT: OK.. nvm.. the minecraft chart is there now... Just had to do ctl-f5 about 4 times - no data though, so I'm assuming I'm not linking the mcstats correctly?

    hmmmm.. actually - none of my munin charts have any data..

    EDIT2: Ok.. last edit... it appears the numbers are coming now.. i didn't realize munin started counting from date of installation (thought maybe it polled some historical data elsewhere heh...).. Thanks! - so.. appears to be working
     
  7. Offline

    Erviker

    you can run the MCstats2 script on windows but munin i dont belive munin can run on windows..

    what i recommend is use xampp or something like that to host the mcstats.json
    you can run the munin plugin on an other server and edit the $url in the files
    Code:
    $url="http://my-windows-server/stats/mcstats.json";
    
     
  8. Offline

    Xstasy

    I like the third demo a lot! Can't wait for it actually, if you can, please release a dev version of it.
     
  9. Offline

    Erviker

    I just released that one!

    2 more on the way! later to day!

    NOW NEW RELEASE! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  10. Offline

    Nijikokun

  11. Offline

    Erviker

    graphs is the simply epic
     
  12. Offline

    Nijikokun

    Space in your symbolic link:
    ln -s /usr/share/munin/plugins/minecraft_blocks _blocks_per_type /etc/munin/plugins/minecraft_blocks_blocks_per_type

    Specifics:
    blocks _blocks
     
  13. Offline

    Erviker

    sorry its
    ln -s /usr/share/munin/plugins/minecraft_blocks_per_type /etc/munin/plugins/minecraft_blocks_per_type
    its fixt in the main post
     
  14. Offline

    Nijikokun

    http://alfenia.com

    Enjoy :D

    Error in minecraft_players, line 37 "playsers"

    Btw, the python ones don't work... bug or ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  15. Offline

    Erviker

    define don't work :p
    it works here...
     
  16. Offline

    Nijikokun

    Ah, missing module simplejson and json :<

    Code:
    Traceback (most recent call last):
      File "/etc/munin/plugins/minecraft_playtime", line 3, in ?
        import sys, simplejson, urllib2, re
    ImportError: No module named simplejson
    2011/03/23-16:12:04 Plugin "minecraft_playtime" exited with status 256. ----
    Traceback (most recent call last):
      File "/etc/munin/plugins/minecraft_blocks_per_user_destroyed", line 3, in ?
        import sys, json, urllib2
    ImportError: No module named json
    2011/03/23-16:12:04 Plugin "minecraft_blocks_per_user_destroyed" exited with status 256. ----
     
  17. Offline

    Erviker

    hmmm.. have editetd the file that used simplejson to use json

    .....have to add that to apt-get install in the tutorial

    but apt-get install python-simpejson to fixit
     
  18. Offline

    Xgkkp

    ahh hilarious, I've been running munin for a while now but will have to try and get this working!
     
  19. Offline

    Xstasy

    Lightning sucks, sorry to hear that your server went out, do you need a new host?
     
  20. Offline

    Erviker

    hehe have allredy got an new one but have to find time to configrue it :) so will be back online in by to 18.00 it now 11.00 here :)
     
  21. Offline

    Nijikokun

    Rewrote into cleaner PHP:
    minecraft_blocks (open)
    PHP:
    #!/usr/bin/php  
    <?php
    /* 
     * Original By Alexander Hansen (alexander@hackz0r.net) - with help from Erviker
     * Rewrote into PHP by Nijikokun <nijikokun@gmail.com>
     */
     
    // Configuration
    $url "http://127.0.0.1/stats/mcstats.json";

    // Functions
    function out($string) {
        print(
    $string "\n");
    }

    function 
    objectToArray($object) {
        if( !
    is_object($object) && !is_array($object) ) { return $object; }
        if( 
    is_object($object) ) { $object get_object_vars($object); }
        return 
    array_map('objectToArray'$object);
    }

    function 
    config() {
        
    out("graph_title Minecraft Blocks");
        
    out("graph_category Minecraft");
        
    out("graph_vlabel Blocks");
        
    out("graph_scale yes");
        
    out("graph_args --base 1000 -l 0");
        
    out("destroyed.type GAUGE");
        
    out("placed.type GAUGE");
        
    out("destroyed.label Destroyed Blocks");
        
    out("placed.label Placed Blocks");
    }

    // Do not edit if you dont know what you are doing
    if ((count($argv) > 1) && ($argv[1] == 'config')) {
        
    config();
        exit();
    }

    $json = (array) json_decode(file_get_contents($url));

    $playerStats objectToArray($json['playerStats']);

    $blocksDestroyed 0;
    $blocksPlaced 0;

    foreach (
    $playerStats as $tempone) {
        foreach (
    $tempone as $key => $temptwo)  {
            if (
    $key == "blocksDestroyed") {
                
    $blocksDestroyed $blocksDestroyed $temptwo;
            }
            
            if (
    $key == "blocksPlaced") {
                
    $blocksPlaced $blocksPlaced $temptwo;
            }
        }    
    }

    out('destroyed.value ' $blocksDestroyed);
    out('placed.value ' $blocksPlaced);

    ?>


    I re-wrote the python ones into php if you would like, since I couldn't get them to work as it kept giving issues with simplejson :/

    minecraft_playtime (open)
    PHP:
    #!/usr/bin/php  
    <?php
    /* 
     * Original By Alexander Hansen (alexander@hackz0r.net) - with help from Erviker
     * Rewrote into PHP by Nijikokun <nijikokun@gmail.com>
     */
     
    // Configuration
    $url "http://127.0.0.1/stats/mcstats.json";

    // Functions
    function out($string) {
        print(
    $string "\n");
    }

    function 
    objectToArray($object) {
        if( !
    is_object($object) && !is_array($object) ) { return $object; }
        if( 
    is_object($object) ) { $object get_object_vars($object); }
        return 
    array_map('objectToArray'$object);
    }

    function 
    config() {
        
    out("graph_title Total playtime per user");
        
    out("graph_category Minecraft");
        
    out("graph_vlabel playtime (seconds)");
        
    out("graph_args --base 1000 -l 0");
    }

    function 
    get_data() {
        global 
    $url;
        
        
    $json = (array) json_decode(file_get_contents($url));
        return 
    objectToArray($json['playerStats']);
    }

    function 
    data_config() {
        foreach (
    get_data() as $player) {
            
    out("playtime_"$player['playerName'] .".type GAUGE");
            
    out("playtime_"$player['playerName'] .".draw AREASTACK");
            
    out("playtime_"$player['playerName'] .".label "$player['playerName']);
        }
    }

    function 
    data_values() {
        foreach (
    get_data() as $player) {
            
    out("playtime_"$player['playerName'] .".value "$player['totalPlaytimeSeconds']);
        }
    }

    // Do not edit if you dont know what you are doing
    if ((count($argv) > 1) && ($argv[1] == 'config')) {
        
    config();
        
    data_config();
        exit();
    }

    data_values();
    ?>
     
  22. Offline

    Erviker

    nice :)
    i will commit that when im are up and running!
    configuring servers atm!
     
  23. Offline

    Nijikokun

    Use github or google code for code source / collab; I have tons of these made :p

    Insightful tip about symbolic links:
    Code:
    ln -s /usr/share/munin/plugins/minecraft_* /etc/munin/plugins/
    Will create one for all matching minecraft_(whatever)
     
  24. Offline

    wolfnet

    How do I set a different port?
     
  25. Offline

    Simanova

    Resolving home.erviker.hackz0r.net... failed: Name or service not known.
    wget: unable to resolve host address âhome.erviker.hackz0r.netâ

    Your download Link is broken
     
  26. Offline

    wolfnet

    Forums download!
     
  27. Offline

    Simanova

    Ive got a functional debian6, apache and munin - so i tried to setup "minecraft munin"
    I followed your manual to setup "minecraft munin".

    But its not working atm.
    I guess i have to adjust the "/etc/munin/plugin-conf.d/munin-node" file.

    But this is not explained by your tutorial.


    ======================================

    PS: ITS NOW WORKING
    I had to grant rights for munin in /usr/share/munin/plugins

    /var/log/munin/munin-node.log shows:

    did i miss something?


    PS: I sloved this problem by installing simplejson :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  28. Offline

    vYN

    Hi. i can't get this to work. i have symlinked the stats folder to my /var/www. But i can't access that folder from my webbrowser.. not sure what to do.
    when i try to open it in my webbrowser:
    Code:
    Access forbidden!
    
    You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
    
    If you think this is a server error, please contact the webmaster.
    Error 403
    mc.homiecraft.com
    Wed 12 Oct 2011 06:09:17 AM CEST
    Apache/2.2.21 (Unix) DAV/2 mod_ssl/2.2.21 OpenSSL/1.0.0c PHP/5.3.8 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5 Perl/v5.10.1 
    and i have this in my munin-node.log file (don't know if this have anything to do with it.)

    Code:
    Error output from yum:
    Can't open /var/lib/munin/plugin-state/yum.state for reading: No such file or directory
     
  29. Offline

    vYN


    how did u grant it access there? i can't get this to work... i have also symlinked the stats folder to my /var/www
     
  30. Offline

    someoneB

    seems like someone had the same idea before ^^
    I like graphs - i like munin.
    But as your download link seems not to work, i keep wondering HOW do you query bukkit for information?
    have you had a .jar that dumps the interesting information to a txt for your munin plugins to read, or how did you get your data?
     
Thread Status:
Not open for further replies.

Share This Page