pcp
[Top] [All Lists]

[PATCH 09/12] Fix Windows filesys metrics

To: Michael Newton <kimbrr@xxxxxxx>, Mark Goodwin <markgw@xxxxxxx>
Subject: [PATCH 09/12] Fix Windows filesys metrics
From: Nathan Scott <nscott@xxxxxxxxxx>
Date: Mon, 20 Nov 2006 16:11:05 +1100
Cc: pcp@xxxxxxxxxxx, kmcdonell@xxxxxxxxxx
Organization: Aconex
Reply-to: nscott@xxxxxxxxxx
Sender: pcp-bounce@xxxxxxxxxxx
This patch corrects the value reported for the existing filesys.full
metric on Windows, and adds in other filesystem fullness related metrics
(i.e. capacity/used/free).

-- 
Nathan

Index: devel-pcp-2.5.99/src/pmdas/windows/data.c
===================================================================
--- devel-pcp-2.5.99.orig/src/pmdas/windows/data.c 2006-11-20
12:01:59.741417000 +1100
+++ devel-pcp-2.5.99/src/pmdas/windows/data.c 2006-11-20
12:02:48.404458250 +1100
@@ -656,6 +656,32 @@ static struct {
       }, Q_KERNEL, M_NONE, ""
     },

+/* filesys.capacity */
+    { { PMDA_PMID(0,117), PM_TYPE_U64, LDISK_INDOM, PM_SEM_INSTANT,
+ PMDA_PMUNITS(1,0,0,PM_SPACE_KBYTE,0,0)
+      }, Q_LDISK, M_NONE, ""
+    },
+/* filesys.used */
+    { { PMDA_PMID(0,118), PM_TYPE_U64, LDISK_INDOM, PM_SEM_INSTANT,
+ PMDA_PMUNITS(1,0,0,PM_SPACE_KBYTE,0,0)
+      }, Q_LDISK, M_NONE, ""
+    },
+/* filesys.free */
+    { { PMDA_PMID(0,119), PM_TYPE_U64, LDISK_INDOM, PM_SEM_INSTANT,
+ PMDA_PMUNITS(1,0,0,PM_SPACE_KBYTE,0,0)
+      }, Q_LDISK, M_NONE, ""
+    },
+/* dummy - filesys.free_space */
+    { { PMDA_PMID(0,120), PM_TYPE_U32, LDISK_INDOM, PM_SEM_INSTANT,
+ PMDA_PMUNITS(1,0,0,PM_SPACE_MBYTE,0,0)
+      }, Q_LDISK, M_NONE, "\\LogicalDisk(*/*#*)\\Free Megabytes"
+    },
+/* dummy - filesys.free_percent */
+    { { PMDA_PMID(0,121), PM_TYPE_FLOAT, LDISK_INDOM, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0)
+      }, Q_LDISK, M_NONE, "\\LogicalDisk(*/*#*)\\% Free Space"
+    },
+
};

int metrictab_sz = sizeof(metricdesc) / sizeof(metricdesc[0]);
Index: devel-pcp-2.5.99/src/pmdas/windows/pmda.c
===================================================================
--- devel-pcp-2.5.99.orig/src/pmdas/windows/pmda.c 2006-11-20
12:03:43.891926000 +1100
+++ devel-pcp-2.5.99/src/pmdas/windows/pmda.c 2006-11-20
12:09:24.461210250 +1100
@@ -507,27 +507,45 @@ redo_indom(int idx)
static void
prefetch(int numpmid, pmID pmidlist[])
{
-    int delta;
-    int sts;
+    int delta, numextra = 0;
+    int sts, i;
     pmID *dst;
+    __pmID_int extra[2];
+    __pmID_int *pmidp;

#ifdef PCP_DEBUG
     if (pmDebug & DBG_TRACE_APPL2) {
- fprintf(stderr, "prefetch(numpid=%d, ...)\n", numpmid);
+ fprintf(stderr, "prefetch(numpmid=%d, ...)\n", numpmid);
     }
#endif

-    delta = numpmid * sizeof(pmID) - shm->segment[SEG_SCRATCH].elt_size
* shm->segment[SEG_SCRATCH].nelt;
+    /* we have derived filesys metrics, so may need to fetch more...
ugh */
+    for (i = 0; i < numpmid; i++) {
+ pmidp = (__pmID_int *)&pmidlist[i];
+ if ((pmidp->cluster == 0) &&
+     (pmidp->item >= 117 && pmidp->item <= 119)) {
+     extra[0] = extra[1] = *pmidp;
+     extra[0].item = 120;
+     extra[1].item = 121;
+     numextra = 2;
+     break;
+ }
+    }
+
+    delta = (numpmid + numextra) * sizeof(pmID) -
+     shm->segment[SEG_SCRATCH].elt_size *
shm->segment[SEG_SCRATCH].nelt;
     if (delta > 0) {
memcpy(new_hdr, shm, hdr_size);
- new_hdr->segment[SEG_SCRATCH].nelt = numpmid * sizeof(pmID);
+ new_hdr->segment[SEG_SCRATCH].nelt = (numpmid+numextra) *
sizeof(pmID);
new_hdr->size += delta;
shm_reshape(new_hdr);
     }
     dst = (pmID *)&((char *)shm)[shm->segment[SEG_SCRATCH].base];
+    if (numextra)
+ memcpy(dst + numpmid, extra, numextra * sizeof(pmID));
     memcpy(dst, pmidlist, numpmid * sizeof(pmID));
     numatoms = 0;
-    fprintf(send_f, "prefetch %d\n", numpmid);
+    fprintf(send_f, "prefetch %d\n", numpmid + numextra);
     fflush(send_f);
     if (fgets(response, sizeof(response), recv_f) == NULL) {
fprintf(stderr, "prefetch: recv EOF: %s\n", strerror(errno));
@@ -602,7 +620,7 @@ fetch(int numpmid, pmID pmidlist[], pmRe
static int
fetch_callback(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
{
-    int i;
+    int i, count;
     shm_result_t *rtab;
     pmAtomValue myatom;
     __pmID_int *pmidp;
@@ -693,10 +711,55 @@ fetch_callback(pmdaMetric *mdesc, unsign
     if (numatoms <= 0)
return numatoms;

+    rtab = (shm_result_t *)&((char
*)shm)[shm->segment[SEG_SCRATCH].base];
+
+    /*
+     * special case the filesystem metrics at this point -
+     * mapping the PDH services semantics for these to the
+     * saner metrics from other platforms is not pretty...
+     */
+    if ((pmidp->cluster == 0) &&
+ (pmidp->item == 67 || (pmidp->item >= 117 && pmidp->item <= 119))) {
+ float used_space, free_space, free_percent;
+ unsigned long long used, avail, capacity;
+ int item;
+
+ for (count = 0, i = 0; i < numatoms; i++) {
+     if (rtab[i].r_inst != inst)
+ continue;
+     if (pmidp->item == 67) { /* filesys.full, rtab holds %Free */
+ atom->f = (1.0 - rtab[i].r_atom.f) * 100.0;
+ return 1;
+     }
+     item = ((__pmID_int*)&rtab[i].r_pmid)->item;
+     if (item == 120) { /* dummy metric, rtab holds FreeMB */
+ free_space = ((float)rtab[i].r_atom.ul);
+ count++;
+     } else if (item == 121) { /* dummy metric, rtab holds %Free */
+ free_percent = rtab[i].r_atom.f;
+ count++;
+     }
+ }
+ if (count != 2) /* we need both "dummy" metric values below */
+     return 0;
+
+ used_space = free_space * (1.0 - free_percent);
+ used = 1024 * (unsigned long long)used_space; /* MB to KB */
+ avail = 1024 * (unsigned long long)free_space; /* MB to KB */
+ capacity = used + avail;
+
+ if (pmidp->item == 117) /* filesys.capacity */
+     atom->ull = capacity;
+ else if (pmidp->item == 118) /* filesys.used */
+     atom->ull = used;
+ else if (pmidp->item == 119) /* filesys.free */
+     atom->ull = avail;
+ return 1;
+    }
+
     /*
      * search in shm for pmAtomValues previously deposited by prefetch
      */
-    rtab = (shm_result_t *)&((char
*)shm)[shm->segment[SEG_SCRATCH].base];
     for (i = 0; i < numatoms; i++) {
if (rtab[i].r_pmid == mdesc->m_desc.pmid && rtab[i].r_inst == inst) {
    *atom = rtab[i].r_atom;
Index: devel-pcp-2.5.99/src/pmdas/windows/pmns.filesys
===================================================================
--- devel-pcp-2.5.99.orig/src/pmdas/windows/pmns.filesys 2006-11-20
12:10:17.488524250 +1100
+++ devel-pcp-2.5.99/src/pmdas/windows/pmns.filesys 2006-11-20
12:11:07.567654000 +1100
@@ -1,4 +1,7 @@
filesys {
     full WINDOWS:0:67
+    capacity WINDOWS:0:117
+    used WINDOWS:0:118
+    free WINDOWS:0:119
}




<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH 09/12] Fix Windows filesys metrics, Nathan Scott <=