VirtualBox

Ignore:
Timestamp:
Sep 27, 2012 8:28:59 AM (12 years ago)
Author:
vboxsync
Message:

Main/Metrics: Host network metrics, linux only (#6345)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp

    r37713 r43445  
    4040
    4141    virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
     42    virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed);
    4243    virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
    4344private:
     
    217218}
    218219
    219 }
    220 
     220int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed)
     221{
     222    int rc = VINF_SUCCESS;
     223    char szIfName[/*IFNAMSIZ*/ 16 + 36];
     224    long long unsigned int u64Rx, u64Tx, u64Speed;
     225
     226    RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/statistics/rx_bytes", name);
     227    FILE *f = fopen(szIfName, "r");
     228    if (f)
     229    {
     230        if (fscanf(f, "%llu", &u64Rx) == 1)
     231            *rx = u64Rx;
     232        else
     233            rc = VERR_FILE_IO_ERROR;
     234        fclose(f);
     235        RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/statistics/tx_bytes", name);
     236        f = fopen(szIfName, "r");
     237        if (f)
     238        {
     239            if (fscanf(f, "%llu", &u64Tx) == 1)
     240                *tx = u64Tx;
     241            else
     242                rc = VERR_FILE_IO_ERROR;
     243            fclose(f);
     244            RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/speed", name);
     245            f = fopen(szIfName, "r");
     246            if (f)
     247            {
     248                if (fscanf(f, "%llu", &u64Speed) == 1)
     249                    *speed = u64Speed * (1000000/8); /* Convert to bytes/sec */
     250                else
     251                    rc = VERR_FILE_IO_ERROR;
     252                fclose(f);
     253            }
     254            else
     255                rc = VERR_ACCESS_DENIED;
     256        }
     257        else
     258            rc = VERR_ACCESS_DENIED;
     259    }
     260    else
     261        rc = VERR_ACCESS_DENIED;
     262
     263    return rc;
     264}
     265
     266}
     267
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette