Skip to content

Commit

Permalink
Merge branch 'main' of ../pcp
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcdonell committed Jul 23, 2024
2 parents d9ca6e2 + dd399a8 commit 09fe393
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions qa/003
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ do
-e "/disk\.xvm\..*: $unavailable/d" \
-e "/filesys\.readonly: $unknown/d" \
-e "/hinv\.cpu\..*: $unavailable/d" \
-e "/hinv\.disk\..*: $unavailable/d" \
-e "/hinv\.hugepagesize: $unavailable/d" \
-e "/hinv\.interconnect: $unavailable/d" \
-e "/hinv\.map\.cpu: $unavailable/d" \
Expand Down
7 changes: 7 additions & 0 deletions src/pmdas/linux/help
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ of traffic over different paths. See also multipathd(1), where the
same ID strings (WWID) are used to identify different paths to each
physical device.

@ hinv.disk.ctlr physical disk device controller
The disk controller is extracted from /sys/devices/pci0000:00/0000:<ctlr>.
Multiple disks may share the same controller.

@ hinv.disk.model physical disk device model
The disk model is extracted from /sys/devices/.../model.

@ disk.dev.avactive per-disk count of active time
Counts the number of milliseconds for which at least one I/O is in
progress for each device.
Expand Down
11 changes: 11 additions & 0 deletions src/pmdas/linux/pmda.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* for more details.
*
* pmDebugOption:
* appl1 disk-related metrics
* appl8 filesys metrics
* libpmda historic "everything else" diagnostics
*/
Expand Down Expand Up @@ -2597,6 +2598,16 @@ static pmdaMetric metrictab[] = {
{ PMDA_PMID(CLUSTER_STAT,104), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
PMDA_PMUNITS(0,0,0,0,0,0) }, },

/* hinv.disk.ctlr */
{ NULL,
{ PMDA_PMID(CLUSTER_STAT,105), PM_TYPE_STRING, DISK_INDOM, PM_SEM_DISCRETE,
PMDA_PMUNITS(0,0,0,0,0,0) }, },

/* hinv.disk.model */
{ NULL,
{ PMDA_PMID(CLUSTER_STAT,106), PM_TYPE_STRING, DISK_INDOM, PM_SEM_DISCRETE,
PMDA_PMUNITS(0,0,0,0,0,0) }, },

/*
* zram IO cluster
*/
Expand Down
154 changes: 154 additions & 0 deletions src/pmdas/linux/proc_partitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ static pmID disk_metric_table[] = {
/* disk.all.flush_rawactive */ PMDA_PMID(CLUSTER_STAT,102),
/* hinv.map.scsi_id */ PMDA_PMID(CLUSTER_STAT,103),
/* disk.all.inflight */ PMDA_PMID(CLUSTER_STAT,104),
/* hinv.disk.ctlr */ PMDA_PMID(CLUSTER_STAT,105),
/* hinv.disk.model */ PMDA_PMID(CLUSTER_STAT,106),

/* disk.partitions.read */ PMDA_PMID(CLUSTER_PARTITIONS,0),
/* disk.partitions.write */ PMDA_PMID(CLUSTER_PARTITIONS,1),
Expand Down Expand Up @@ -1066,6 +1068,138 @@ _pm_ioscheduler(const char *device)
return "unknown";
}

/*
* Get controller (name) for a specific disk
*/
char *
get_disk_ctlr(char *name)
{
ssize_t size;
int want;
char *part;
char path[MAXPATHLEN];
char link[MAXPATHLEN];
char *ctlr;

pmsprintf(path, sizeof(path), "%s/sys/block/%s", linux_statspath, name);
if ((size = readlink(path, link, sizeof(link)-1)) < 0) {
if (pmDebugOptions.appl1) {
fprintf(stderr, "get_disk_ctlr(%s,...): readlink(%s,...) failed: %" FMT_INT64, name, path, (int64_t)size);
if (size < 0)
fprintf(stderr, ": %s", pmErrStr(-oserror()));
fputc('\n', stderr);
}
return NULL;
}
link[size] = '\0';
/*
* .../pci0000:00/0000:00:10.0/.../sdd
* ^^^^^^^ controlller id as per lspci
* ^^^ disk name as per indom
*/
part = strtok(link, "/");
want = 0;
while (part != NULL) {
if (strcmp(part, "pci0000:00") == 0) {
/*
* this is the only PCI prefix we are sure about
* TODO - other possibilities here?
*/
want = 1;
}
else if (want == 1) {
if (strncmp(part, "0000:", 5) == 0) {
ctlr = strdup(&part[5]);
if (ctlr == NULL)
pmNoMem("get_disk_ctlr: ctlr", strlen(&part[5])+1, PM_RECOV_ERR);
return ctlr;
}
else {
/* TODO - prefixes other than 0000: here? */
if (pmDebugOptions.appl1) {
fprintf(stderr, "get_disk_ctlr(%s,...): expected 0000: got %5.5s from link %s\n", name, part, link);
}
return NULL;
}
}
part = strtok(NULL, "/");
}

if (pmDebugOptions.appl1)
fprintf(stderr, "get_disk_ctlr(%s,...): link=%s not expected\n", name, link);
return NULL;
}

/*
* Get model for a specific disk
*/
char *
get_disk_model(char *name)
{
ssize_t size;
int fd;
char *part;
char path[MAXPATHLEN];
char link[MAXPATHLEN];
char duplink[MAXPATHLEN];
char *model;

pmsprintf(path, sizeof(path), "%s/sys/block/%s", linux_statspath, name);
if ((size = readlink(path, link, sizeof(link)-1)) < 0) {
if (pmDebugOptions.appl1) {
fprintf(stderr, "get_disk_model(%s,...): readlink(%s,...) failed: %" FMT_INT64, name, path, (int64_t)size);
if (size < 0)
fprintf(stderr, ": %s", pmErrStr(-oserror()));
fputc('\n', stderr);
}
return NULL;
}
link[size] = '\0';
strcpy(duplink, link);
model = NULL;
part = strtok(link, "/");
while (part != NULL) {
if (strcmp(part, "block") == 0) {
/*
* .../pci0000:00/.../a:b:c:d/block/sdd
* becomes
* .../pci0000:00/.../a:b:c:d/model
*/
int offset;
offset = part - link - 1;
duplink[offset] = '\0';
pmsprintf(path, sizeof(path), "%s/sys/block/%s/model", linux_statspath, duplink);
if ((fd = open(path, O_RDONLY)) >= 0) {
char buf[1024];
size = read(fd, buf, sizeof(buf)-1);
if (size > 0) {
buf[size-1] = '\0';
model = strdup(buf);
// TODO pmMem
return model;
}
else {
if (pmDebugOptions.appl1) {
fprintf(stderr, "get_disk_model(%s,...): read(%s): %" FMT_INT64 "\n", name, path, (int64_t)size);
}
return NULL;
}
}
else {
if (pmDebugOptions.appl1) {
fprintf(stderr, "get_disk_model(%s,...): open(%s,...) failed: %s\n", name, path, pmErrStr(-oserror()));
}
return NULL;
}
}
part = strtok(NULL, "/");
}

if (pmDebugOptions.appl1)
fprintf(stderr, "get_disk_model(%s,...): link=%s not expected\n", name, link);
return NULL;
}

int
proc_partitions_fetch(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
{
Expand Down Expand Up @@ -1225,6 +1359,26 @@ proc_partitions_fetch(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
return PM_ERR_INST;
atom->cp = _pm_scsi_id(p->namebuf);
break;
case 105: /* hinv.disk.ctlr */
if (p == NULL)
return PM_ERR_INST;
if (p->ctlr == NULL) {
p->ctlr = get_disk_ctlr(p->namebuf);
if (p->ctlr == NULL)
return 0;
}
atom->cp = p->ctlr;
break;
case 106: /* hinv.disk.model */
if (p == NULL)
return PM_ERR_INST;
if (p->model == NULL) {
p->model = get_disk_model(p->namebuf);
if (p->model == NULL)
return 0;
}
atom->cp = p->model;
break;
default:
/* disk.all.* is a singular instance domain */
atom->ull = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/pmdas/linux/proc_partitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ typedef struct {
char *dmname; /* symlink from /dev/mapper, else NULL */
char *mdname; /* symlink from /dev/md, else NULL */
char *wwidname; /* wwid of sd path, else NULL */
char *ctlr; /* from /sys/block symlink, else NULL */
char *model; /* from /sys/devices/..., else NULL */
zram_stat_t *zram;
unsigned long long rd_ios;
unsigned long long rd_merges;
Expand Down
6 changes: 6 additions & 0 deletions src/pmdas/linux/root_linux
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ hinv {
hugepagesize 60:1:59
ntape 60:71:16
nfchost 60:91:16
disk
}

hinv.map {
Expand Down Expand Up @@ -107,6 +108,11 @@ hinv.cpu.frequency_scaling {
min 60:55:9
}

hinv.disk {
ctlr 60:0:105
model 60:0:106
}

kernel {
all
percpu
Expand Down

0 comments on commit 09fe393

Please sign in to comment.