Skip to main content

cPanel plugin - add entries to statistics

Comments

10 comments

  • cPanelKenneth
    Hi, We added the ability to include custom information in the statsbar in version 70 of cPanel & WHM. You can find the documentation here How to Create a Pluggable Statistics Module - cPanel Knowledge Base - cPanel Documentation
    0
  • CloudNexus
    You guys are awesome, seriously. I do find it (sometimes) hard to find the right information in your developers documentation, but I believe this is being worked on! Thanks so much and thanks again!
    0
  • cPanelKenneth
    You guys are awesome, seriously. I do find it (sometimes) hard to find the right information in your developers documentation, but I believe this is being worked on! Thanks so much and thanks again!

    Thank you for the praise :) Yes we are working on improving our documentation. Its navigation and discoverability are two areas of concern, especially with our developer documentation.
    0
  • CloudNexus
    Thank you for the praise :) Yes we are working on improving our documentation. Its navigation and discoverability are two areas of concern, especially with our developer documentation.

    I've got this working properly now, but only one last thing I found: When you set the "before" or "after", CPanel's api ([server]:2083/cpsess[number]/execute/ResourceUsage/get_usages) returns all of the statistics items in the correct order (the json order is correct), so the API adheres to the given order of things. However, on the front-end, the angular code that is used to generate the actual items, does not adhere to the order in the JSON. E.g. With my plugin set "before" mysql_databases it renders before the MySQL disk stats (cachedmysqldiskusage). When I set to to "After" mysql_databases, it renders at the start of the list. Is this an issue on my side? I am thinking its not (because the json is in the correct order, when it comes from the cpanel api). Is this a bug?
    0
  • cPanelMichael
    Hi @CloudNexus, Can you post the specific code you are using for the custom module so we can attempt to reproduce it on a test environment? Thank you.
    0
  • CloudNexus
    Yes of course - it's quite simple really: package Cpanel::ResourceUsage::Custom::NexuscoreStats; use strict; use warnings; use Cpanel (); use Cpanel::API (); use Cpanel::Locale (); use Cpanel::Logger (); # This feature expects each custom module to contain a "get_usages" function # that returns an array of hashes, with each hash matching the parameters below: sub get_usages { my ($username) = @_; my $enabled = 'y'; # this will return a number (positive) my $maxEntries = _get_package_variable($username,"some_metric_1"); # this will return a number (positive) my $currentEntryCount = get_package_variable($username,"some_metric_2"); if($sqlEnabled eq 'y') { return ( { id => 'nexuscore_entry_limit', description => 'My package description', usage => $currentEntryCount, maximum => $maxEntries, before => 'mysql_databases', url => 'myplugin/index.live.php', }, ); } return; } sub _get_package_variable { return 5; } 1;
    In this case it will appear before the "mysql disk stats". If I change "before" to "after", my plugin ends up in the start of the list. JSON returned from the api (viewed in the chrome network tab) is in the correct order. See attached picture. Returned json ( { "formatter":null, "description":"My package description", "maximum":"5", "url":"myplugin/index.live.php", "usage":5, "id":"nexuscore_entry_limit" }, { "usage":4, "id":"mysql_databases", "description":"MySQL" Databases", "maximum":null, "formatter":null, "url":"sql/index.html" } ], "status":1, "errors":null, "messages":null, "metadata":{ "transformed":1 }, "warnings":null } [CODE
    0
  • cPanelMichael
    Hello, Thank you for providing the requested information. Upon testing, I believe the issue you are experiencing relates to the notice found in the Sort Order category under Additional Information on the
    0
  • CloudNexus
    Dear Michael, Thanks again for your help. You are completely right. When removing the entry (maximum) it does show on the correct place. THing is however, that even if I set it to 1/100 (1% usage) it will end up above the mysql statistics in my case, meaning that basically anything with a limit other than unlimited will be shown 'higher' than unlimited items. THanks for the fast help once again, this at least explains most of this. I should rtfm! Thanks!
    0
  • cPanelMichael
    Hello, You're very welcome!
    THing is however, that even if I set it to 1/100 (1% usage) it will end up above the mysql statistics in my case, meaning that basically anything with a limit other than unlimited will be shown 'higher' than unlimited items.

    That's currently the designed behavior, as any setting with an unlimited value technically means it's usage is at 0%. Thank you.
    0
  • CloudNexus
    Thank you!
    0

Please sign in to leave a comment.