cPanel plugin - add entries to statistics
Hi there,
I'm starting to grow fond of the way to develop for cPanel! Now that I'm slowly getting the hang of it I'd like to create some UI that will help the end-user use my plugin. Part of this is custom pages in the cPanel dashboard (this is done), but the second part is adding to the "statistics" sidebar of the user on his cPanel start page.
I'd like to add a number of extra 'counters' there for some resources that my plugin is using (similar to MySQL). Is there a way I can extend this statistics template without changing the core template? I want it to integrate as neatly as possible.
I see it's using the angular statisticsController to foreach through a list of ::statistics, which I suppose are apps and/or packages that toggle this behaviour. How can I added my 'custom' app statistics to this list?
-
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 -
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 -
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 -
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 -
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 -
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 } [CODE0 -
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 -
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 -
Thank you! 0
Please sign in to leave a comment.
Comments
10 comments