LoginSignup
0
0

vmstatのデータをVBAで取り込もう②

Posted at

第2弾

vmstatの結果をvbaでの取り込み

①まずはvmstatの結果をcsv化
※一度csvデータにしたほうが楽。

cat vmstat.txt | column -t | sed -r 's/\s+/,/g' > newvmstat.txt

できたvmstatデータ

2023年,11月,10日,金曜日,13:13:01,JST,procs,-----------memory----------,---swap--,-----io----,-system--,------cpu-----,
2023年,11月,10日,金曜日,13:13:01,JST,r,b,swpd,free,buff,cache,si,so,bi,bo,in,cs,us,sy,id,wa,st
2023年,11月,10日,金曜日,13:13:01,JST,0,0,0,3187260,3772,366100,0,0,92,13,80,108,0,0,99,0,0
2023年,11月,10日,金曜日,13:13:02,JST,0,0,0,3186488,3772,366132,0,0,0,0,337,358,0,1,99,0,0
2023年,11月,10日,金曜日,13:13:03,JST,0,0,0,3186616,3772,366132,0,0,0,0,139,189,0,0,100,0,0
2023年,11月,10日,金曜日,13:13:04,JST,0,0,0,3186636,3772,366132,0,0,0,0,204,239,1,0,100,0,0
2023年,11月,10日,金曜日,13:13:05,JST,0,0,0,3186616,3772,366132,0,0,0,0,181,219,0,0,100,0,0
2023年,11月,10日,金曜日,13:13:06,JST,0,0,0,3186672,3772,366132,0,0,0,0,216,269,0,1,100,0,0
2023年,11月,10日,金曜日,13:13:07,JST,0,0,0,3186672,3772,366132,0,0,0,0,180,221,0,0,100,0,0

csvファイルの内容をエクエルに取り込む


Sub test()

Open "C:\Users\kenke\OneDrive\デスクトップ\vba\newvmstat.txt" For Input As #1

'Dim usrcpu As Integer

'Dim syscpu As Integer


i = 0
k = 1


  Do Until EOF(1)
    Line Input #1, buf
    
   
   strsplit = Split(buf, ",") 'カンマ区切りで配列へ
   zzz = strsplit(6)
    
   If zzz = "procs" Then
   
     GoTo qqq
     
   
   
   ElseIf zzz = "r" Then
   
     GoTo qqq
   
   Else
   
   usrcpu = strsplit(18)
   syscpu = strsplit(19)
   
   timedate0 = strsplit(0)
   timedate1 = strsplit(1)
   timedate2 = strsplit(2)
   timedate4 = strsplit(4)
   
   timedate = timedate0 + timedate1 + timedate2 + timedate4
   
   
   
   
   End If
   
     
    'シートに数字を入れる
    
   Cells(k, "A") = timedate
   Cells(k, "B") = usrcpu
   Cells(k, "C") = syscpu
   
   k = k + 1
   
qqq:
   

    
  Loop

Close #1



End Sub



最後に

第3弾はグラフまで追加します。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0