Jump to content

ProcessDiagnostics


netcarver

Recommended Posts

@soma

Thanks for the catch. Actually, that was me being a bit too liberal with copy-and-paste and remember this was only a proof-of-concept 2 days ago ;)  I'll redefine the Diagnostic providers so they all 'extend Wire implement Module' rather than having them be process modules. Having said that, I'll keep Nico's module extending 'Process' as it needs the js and css loading provided by the Process::init() method that I don't want to have to duplicate. I don't think any other diagnostic provider needs this special treatment.

@apeisa

Yes, there is a naming convention for the diagnostic provider modules. I'll update the opening post and add it to the repo's readme file soon but it goes like this...

Firstly: Have your module hook the ProcessDiagnostics::collectDiagnostics() method so it can inject its diagnoses into the results array.

Then either:

  1. Make your module an autoload module and call it whatever you need to call it.
  2. Don't make your module autoload but the name must start with "Diagnose" in order for ProcessDiagnostics to load it when it is initialised.

Here's the code from the new "DiagnoseExample" provider module that makes it about as simple as it can...

<?php

/**
 * Hooks into ProcessDiagnostics to add additional example information.
 */
class DiagnoseExample extends Wire implements Module
{

    public static function getModuleInfo()
    {
        return array(
            'title'     => __('Example Diagnostics Provider', __FILE__),
            'summary'   => __('Demonstrates how to write a simple diagnostics provider module', __FILE__),
            'version'   => 1,
            'permanent' => false,
            'autoload'  => false,
            'singular'  => true,
            'requires'  => 'ProcessDiagnostics',
            'installs'  => 'ProcessDiagnostics',
            'author'    => 'Stephen Dickinson, QBox',
        );
    }

    public function init()
    {
        $this->addHookAfter('ProcessDiagnostics::collectDiagnostics', $this, 'AppendDiagnostics');
    }

    /**
     * Collects Diagnostics.
     */
    public function GetDiagnostics()
    {
        $results[] = array(
            'title'  => $this->_('Thing diagnosed'),
            'value'  => $this->_('Bad value!'),
            'status' => ProcessDiagnostics::$fail, // other valid values are ::$warn and ::$ok.
            'action' => $this->_('Describe how to correct the bad value.'),
        );

        return $results;
    }

    public function AppendDiagnostics($event)
    {
        $results = $event->return;
        $results[$this->_('Example Diagnostics')] = $this->GetDiagnostics();
        $event->return = $results;
    }
}

Obviously, it takes the 2nd route I mentioned above (doesn't autoload.)

Let me know if you need any more information.

  • Like 1
Link to comment
Share on other sites

@steve: with the new version 0.2.0 I get an fatal error becuase of a missing method in ProcessDiagnostic. The missing function is this (from @adrian):

        /**
         * returns if function is disabled in php
         *
         * @return boolean: true, false
         */
        static protected function isDisabled($function) {
            $disabled_functions = explode(',' , str_replace(' ', '', strtolower(ini_get('disable_functions'))));
            return in_array(strtolower($function), $disabled_functions);
        }

@steve & @Nico:

I have a question with the modules module: I don't want it to query all versions every time I call the diagnostics page. So, yes, I can uninstall it and only install it on demand. But would it not be better if this module has a button that I can press to execute the query and an option that lets select a time period (e.g. 1 week) that let run it via lazy cron at least once in the given time period?

  • Like 1
Link to comment
Share on other sites

Well I included a cache at first - but then forgot to reimplement it after using ajax. It wouldn't be that hard for my to reimplement it but would be nice to know if this module is going to be alive in the future or will be eaten by Soma's module (because Soma already use caching) :)

Link to comment
Share on other sites

@Nico: I can't follow in full, :) but simply stay to what I have said before:
 

I don't want it to query all versions every time I call the diagnostics page!
 
So, yes, I can uninstall it and only install it on demand. But would it not be better if this module has a button that I can press to execute the query and an option that lets select a time period (e.g. 1 week) that let run it via lazy cron at least once in the given time period?

PS: Well, I remember a day back (or two), you have said it would be really useful to have this, regardless of the existence of somas modules.

And well, others have agreed with you. So, now we want to have a functional module. That's all. :P

Edited by horst
  • Like 1
Link to comment
Share on other sites

Hmm, well, I messed up something on my server - looks like Apache2 is serving php files as plain text now  :blink:

Note to self: Never, I said never, accidentily delete the first line ("<?php") of PW's index.php file and save it!

Punishment: On next trip to post office collect, fill out and submit form id10t. In triplicate.

  • Like 5
Link to comment
Share on other sites

Just pushed up some improvements to the DiagnoseDatabase module. It now takes more time poking around with character sets, collations and table information.

Here's a couple of screenshots...

post-465-0-83785900-1401284370_thumb.png post-465-0-69274300-1401284384_thumb.png

Hope these might eventually help someone out.

  • Like 5
Link to comment
Share on other sites

Uups, have copied the latest version over my previous installed one, where a file of Diagnose Modules exists but is not installed! After login, when trying to go to the Modules-Tab of the Backend, I get this:

Fatal error: Can't use method return value in write context in DOC_ROOT\site\modules\ProcessDiagnostics\DiagnoseModules.module on line 102

Makes my Modules Backend unusable :'(   (PW 2.4.2) - Haven't investigated further. @Nico: Do you need more infos?

-----------

DiagnoseDatabase module works fine!

I have some of these Warnings: 'Repair table to reclaim space.'

What's about a Button that lets the user directly execute an optimize / repair?  $query = 'OPTIMIZE NO_WRITE_TO_BINLOG TABLE ' . implode(', ', $tableNames);

Edited by horst
  • Like 1
Link to comment
Share on other sites

@horst

You read my mind. I'm out until tomorrow evening but that happens to be next on my to-do-list for DiagnoseDatabase.

@Martijn

Thank you! It's really nice to have input from Nico, horst and Manfred62. Hope it is useful to folks!

  • Like 2
Link to comment
Share on other sites

@horst

Just pushed a new version of ProcessDiagnostics and DiagnoseDatabase that should now allow you to optimize any table that has overhead. The new code allows any Diagnose module to provide custom actions via a hook. Here's how I've done it for optimizing tables but there might be a better way. Please let me know if this works for you.

  • Like 6
Link to comment
Share on other sites

@Steve: works perfect! Have optimized 10 tables successfully.
 
- Maybe one optionally can have one button invoking optimize for all tables at once, instead of doing it repeatedly one by one?
 
- And I have encountered a table that was created as InnoDB and not MyISAM. It shows Overhead 23MB, is this correct? This one get not optimized by clicking the link.
 
screen_123.png

Link to comment
Share on other sites

I have no phpmyadmin installed, I used another tool and it first said: Table does not support optimize, doing recreate + analyze instead.

than it said: status ok.

But when I come back to the DiagnoseModule it is unchanged.

Does phpmyadmin display info for overhead? Should I install it?

Link to comment
Share on other sites

tested latest version: the optimizing is nice and function well.

for better translation use new line for the second string and better place the blank after the closing a (see code)

136:   $warnings[] = '<a href="?owner='.__CLASS__.'&action=optimize&table='.$t_Name.'">'.$this->_('Optimize').'</a> ' .
137:   $this->_('table to reclaim space and reorganize indexes.');
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...