VirtualBox

Changeset 43958 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Nov 26, 2012 10:37:06 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82302
Message:

Main/Metrics: Host disk size, linux only (#6345)

Location:
trunk/src/VBox/Main/src-server
Files:
3 edited

Legend:

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

    r43831 r43958  
    29362936    for (it = disks.begin(); it != disks.end(); ++it)
    29372937    {
    2938         Utf8StrFmt strName("Disk/%s/Load", it->c_str());
    2939         pm::SubMetric *fsLoadUtil   = new pm::SubMetric(strName + "/Util",
     2938        Utf8StrFmt strName("Disk/%s", it->c_str());
     2939        pm::SubMetric *fsLoadUtil   = new pm::SubMetric(strName + "/Load/Util",
    29402940            "Percentage of time disk was busy serving I/O requests.");
    2941         pm::BaseMetric *fsLoad = new pm::HostDiskLoadRaw(hal, this, strName,
     2941        pm::SubMetric *fsUsageTotal = new pm::SubMetric(strName + "/Usage/Total",
     2942            "Disk size.");
     2943        pm::BaseMetric *fsLoad  = new pm::HostDiskLoadRaw(hal, this, strName + "/Load",
    29422944                                                         *it, fsLoadUtil);
    29432945        aCollector->registerBaseMetric (fsLoad);
     2946        pm::BaseMetric *fsUsage = new pm::HostDiskUsage(hal, this, strName + "/Usage",
     2947                                                        *it, fsUsageTotal);
     2948        aCollector->registerBaseMetric (fsUsage);
    29442949
    29452950        aCollector->registerMetric(new pm::Metric(fsLoad, fsLoadUtil, 0));
     
    29492954                                                  new pm::AggregateMin()));
    29502955        aCollector->registerMetric(new pm::Metric(fsLoad, fsLoadUtil,
     2956                                                  new pm::AggregateMax()));
     2957
     2958        aCollector->registerMetric(new pm::Metric(fsUsage, fsUsageTotal, 0));
     2959        aCollector->registerMetric(new pm::Metric(fsUsage, fsUsageTotal,
     2960                                                  new pm::AggregateAvg()));
     2961        aCollector->registerMetric(new pm::Metric(fsUsage, fsUsageTotal,
     2962                                                  new pm::AggregateMin()));
     2963        aCollector->registerMetric(new pm::Metric(fsUsage, fsUsageTotal,
    29512964                                                  new pm::AggregateMax()));
    29522965    }
  • trunk/src/VBox/Main/src-server/Performance.cpp

    r43949 r43958  
    8282
    8383int CollectorHAL::getHostFilesystemUsage(const char * /* name */, ULONG * /* total */, ULONG * /* used */, ULONG * /* available */)
     84{
     85    return E_NOTIMPL;
     86}
     87
     88int CollectorHAL::getHostDiskSize(const char * /* name */, uint64_t * /* size */)
    8489{
    8590    return E_NOTIMPL;
     
    859864}
    860865
     866void HostDiskUsage::init(ULONG period, ULONG length)
     867{
     868    mPeriod = period;
     869    mLength = length;
     870    mTotal->init(mLength);
     871}
     872
     873void HostDiskUsage::preCollect(CollectorHints& /* hints */, uint64_t /* iTick */)
     874{
     875}
     876
     877void HostDiskUsage::collect()
     878{
     879    uint64_t total;
     880    int rc = mHAL->getHostDiskSize(mDiskName.c_str(), &total);
     881    if (RT_SUCCESS(rc))
     882        mTotal->put((ULONG)(total / (1024*1024)));
     883}
     884
    861885#ifndef VBOX_COLLECTOR_TEST_CASE
    862886void HostRamVmm::init(ULONG period, ULONG length)
  • trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp

    r43845 r43958  
    4949    virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
    5050    virtual int getHostFilesystemUsage(const char *name, ULONG *total, ULONG *used, ULONG *available);
     51    virtual int getHostDiskSize(const char *name, uint64_t *size);
    5152    virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
    5253
     
    242243}
    243244
     245int CollectorLinux::getHostDiskSize(const char *name, uint64_t *size)
     246{
     247    int rc = VINF_SUCCESS;
     248    char *pszName = NULL;
     249    long long unsigned int u64Size;
     250
     251    RTStrAPrintf(&pszName, "/sys/block/%s/size", name);
     252    Assert(pszName);
     253    FILE *f = fopen(pszName, "r");
     254    RTMemFree(pszName);
     255
     256    if (f)
     257    {
     258        if (fscanf(f, "%llu", &u64Size) == 1)
     259            *size = u64Size * 512;
     260        else
     261            rc = VERR_FILE_IO_ERROR;
     262        fclose(f);
     263    }
     264    else
     265        rc = VERR_ACCESS_DENIED;
     266
     267    return rc;
     268}
     269
    244270int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
    245271{
Note: See TracChangeset for help on using the changeset viewer.

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