0

I know that there are many similar threads like this in StackOverflow - but the only reason I'm creating this is because though the question title is similar but the question is different.

READ THE WHOLE QUESTION BEFORE MAKING IT DUPLICATE!

I was using the latest cPanel update and one thing that intrigued me was the CPU/RAM usage.

cPanel screenshot

Now one of the great thing about this section saw - it shows the meter depending upon the available resources in your account.

So if you are using a cloudlinux based system and you are allocated certain CPU/RAM the meter will work on that. On the other hand if you are in a simple linux environment - it will account the whole system resource.

I know that most of cPanel code was written in perl, but I was wondering if it is possible to retrieve these same data to develop a similar meter like it in PHP.

Any help will be highly appreciated.

EDIT: I already created an web app to retrieve the load average from the server. But I hope after reading the question above you guys already understood that I'm not looking for the load average. :)

EDIT 2 : I know how to retrieve the load average in php - but it is not going to help me here as first of all load avg is not just about the cpu (it includes many other variables) on the other hand there is no way to get the maximum load avg value so that I can create an percentage. So, please don't share the link of load average thread in the comment.

iSaumya
  • 1,503
  • 5
  • 21
  • 50
  • There is no fundamental difference between what you can implement in a specific programming language. They are all equally mighty. You obviously have to grant access (so read permission) to the process, but that is not a question of the language you use, but of how you handle system rights management. So it is unclear what your actual question here is. If it can be done in perl than certainly it can also be done in php if you want to reinvent the wheel. – arkascha Jul 25 '15 at 06:55
  • can use http://stackoverflow.com/questions/22949295/how-do-you-get-server-cpu-usage-and-ram-usage-with-php – sadegh Jul 25 '15 at 06:59
  • @arkascha yes I know that its not upto the programming language, but what I was asking is if there is a way to retrieve this kind of info using php. If there is, then please share. As you can see that the `server load average` wont help me in this case. – iSaumya Jul 25 '15 at 07:11
  • @sadegh I hope you haven't read my edited part of the question. I now how to retrieve the load average in php - but it is not going to help me here as first of all load avg is not just about the cpu on the other hand there is no way to get the maximum load avg value so that I can create an percentage. Hope you get that. – iSaumya Jul 25 '15 at 07:13
  • 1
    So your questions is _not_ about how to implement that in php, but how to access that information / where to find it? Why don't you say so in the question? I suggest you take a look at the `/proc` pseudo file system. You will find many many examples for that on the internet. Even in combination with php. That pseudo file system allows you to read all types of information directly fro the kernel. You get back text which you have to parse. There are libraries for that, but the format is pretty stable, so you can simply use a regex for extraction. Start with that: `cat /proc/meminfo`... – arkascha Jul 25 '15 at 07:17
  • @arkascha exactly this is what I was looking for. Thanks a lot. Can you give me some helpful article link where some tutorials & information has been provided about how to fetch these values, what are the different parameters there that I can use. etc. Some heads up article will be really helpful. Now a days internet has been fulled of junk its hard to find a good helpful article. – iSaumya Jul 25 '15 at 07:21
  • @arkascha also if possible, please let me know what exact permission do I need to what exact thing. So that I can pass it on to me host. – iSaumya Jul 25 '15 at 07:23
  • The most precise information about system resources on unixoid systems _always_ are the local man pages. So have a try with this: `man 5 proc` (asuming that you have installed the man pages). About the permission: think again: `/proc` is a _pseudo file system_. You use normal file based operations to access the content. Therefore file permission rules apply to the access. Just take a look at them by using `ls -l` :-) – arkascha Jul 25 '15 at 07:23
  • @arkascha `cat /proc/meminfo` shows the ram and other details of the entire server, not what allocated to my account only. Like what shows in cpanel. – iSaumya Jul 25 '15 at 07:27

0 Answers0