iostat命令介紹及C++對其傳回值的提取處理

來源:互聯網
上載者:User

標籤:linux   營運   C++   

1、命令介紹

常用的命令為 iostat -xk

x參數表示返回全部參數

k參數表示返回的資料單位為kb

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util

vda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

vdb               0.00     0.00    0.00   71.00     0.00   284.00     8.00     0.07    0.96   0.04   0.30

每一列的內容分別為:

 

如果需要擷取即時數值 還需要再加兩個參數 

iostat -xk 10 2

10表示: 採樣間隔為10秒

2表示  : 採集兩次(第一次為總的,等同於直接調用 iostat -xk, 因此要擷取即時數值這個參數至少傳2 )

  • rrqm/s: 每秒對該裝置的讀請求被合并次數,檔案系統會對讀取同塊(block)的請求進行合并

  • wrqm/s: 每秒對該裝置的寫請求被合并次數

  • r/s: 每秒完成的讀次數

  • w/s: 每秒完成的寫次數

  • rkB/s: 每秒讀資料量(kB為單位)

  • wkB/s: 每秒寫資料量(kB為單位)

  • avgrq-sz:平均每次IO操作的資料量(扇區數為單位)

  • avgqu-sz: 平均等待處理的IO請求隊列長度

  • await: 平均每次IO請求等待時間(包括等待時間和處理時間,毫秒為單位)

  • svctm: 平均每次IO請求的處理時間(毫秒為單位)

  • %util: 採用周期內用於IO操作的時間比率,即IO隊列非空的時間比率

2、提取

這裡針對實現了兩個C++的函數

首先將傳回值按行分割開,可以用這個方法:

void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)     {                                                                                                 std::string::size_type pos1, pos2;                                                             pos2 = s.find(c);                                                                             pos1 = 0;                                                                                     while(std::string::npos != pos2) {                                                                 v.push_back(s.substr(pos1, pos2-pos1));                                                       pos1 = pos2 + c.size();                                                                       pos2 = s.find(c, pos1);                                                                   }                                                                                             if(pos1 != s.length()) {                                                                           v.push_back(s.substr(pos1));                                                               }                                                                                         }

分割之後每一行的提取就比較麻煩了,因為這些數值之間都是用不等數目的空格進行分割的,因此實現一個方法:

/* 讀取字串,提取其中的所有數字(包括小數) */std::vector<double> digDigit(const std::string& src) {    std::vector<double> ret;    std::string num = "";    bool hasPoint = false;    for(std::string::const_iterator s_it = src.begin(); s_it != src.end(); ++s_it) {        char cur = *s_it;        if( (cur >= '0' && cur <= '9') || cur == '.') {            if(cur == '.') {  // 小數點                if(hasPoint) {                    num = "";                    continue;                }else {                    hasPoint = true;                    num += cur;                }           }else {  // 數字               num += cur;           }        }else {            if(num != "") {                // std::cout << num << std::endl;                ret.push_back(atof(num.c_str()));                hasPoint = false;                num = "";            }        }    }    if(num != "") {        // std::cout << num << std::endl;        ret.push_back(atof(num.c_str()));    }    return ret;}


iostat命令介紹及C++對其傳回值的提取處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.