[R] Reg : R : How to capture cpu usage, memory usage and disks info using R language

jim holtman jholtman at gmail.com
Sun Oct 16 17:07:27 CEST 2016


Here is a start on the solution.  This will create a VBS script that
will gather the CPU data and return it in a character vector that you
can extract the data from.  You can add to it to get the other data
you are looking for.

########################
> temp <- tempfile(fileext = '.vbs')  # get a temp file
>
> # create the VBS file to collect processor data
> writeLines('Set objWMIService = GetObject("winmgmts:\\\\localhost\\root\\CIMV2")
+ Set CPUInfo = objWMIService.ExecQuery("SELECT * FROM
Win32_PerfFormattedData_PerfOS_Processor",,48)
+ For Each Item in CPUInfo
+     Wscript.Echo "PercentProcessorTime: " & Item.PercentProcessorTime & _
+          "  processor:" & Item.Name
+ Next',
+  temp)
>
> results <- shell(paste("cscript", temp), intern = TRUE)  # execute using 'cscript'
> results # all the data
[1] "Microsoft (R) Windows Script Host Version 5.8"
[2] "Copyright (C) Microsoft Corporation. All rights reserved."
[3] ""
[4] "PercentProcessorTime: 18  processor:0"
[5] "PercentProcessorTime: 6  processor:1"
[6] "PercentProcessorTime: 6  processor:2"
[7] "PercentProcessorTime: 0  processor:3"
[8] "PercentProcessorTime: 7  processor:_Total"
> grep("processor:", results, value = TRUE)  # get just processor data
[1] "PercentProcessorTime: 18  processor:0"     "PercentProcessorTime:
6  processor:1"
[3] "PercentProcessorTime: 6  processor:2"      "PercentProcessorTime:
0  processor:3"
[5] "PercentProcessorTime: 7  processor:_Total"
>
>
#####################################


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Fri, Oct 14, 2016 at 5:37 AM, Manohar Reddy <manu.reddy52 at gmail.com> wrote:
> Hi,
>
> Is there any possibility that we can capture cpu usage ,memory usage and
> disks info using R language on *windows family OS* ?
>
>
>
>   I would like to see data that’s looks like
> a
>  below
>
>
>
>    Cpu usage : 70 %
>
>    Memory usage  : 80 %
>
>    Disks        : C drive – 40 % full,D dive – 60 %,full E drive – 30 % full
>
>
>    for more info please find the attachement.
>
>
>  Thanks in Advance ,Manu.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list