typedef int BOOL;
#define IRIX 1
#include <stdio.h>
#include <sys/shm.h>
#include <pcp/pmapi.h>
#ifdef IRIX
#include <pcp/impl.h>
#endif
#include <pcp/pmda.h>
#include "domain.h"
#include "profile.h"
#include "metrics.h"
static pmdaInstid *counttime = NULL;
static pmdaInstid *bytes = NULL;
static pmdaIndom indomtab[] = {
{COUNT_TIME_INDOM,0,NULL},
{BYTE_INDOM,0,NULL}
};
static pmdaMetric metrictab[] = {
{ NULL, { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(0,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(1,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(1,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(1,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,3), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,4), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,5), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,6), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,7), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,8), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,9), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,10), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,11), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,12), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,13), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,14), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,15), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(2,16), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(3,0), PM_TYPE_U32, COUNT_TIME_INDOM, PM_SEM_COUNTER,
{ 0,0,1,0,0,PM_COUNT_ONE} }, },
{ NULL, { PMDA_PMID(4,0), PM_TYPE_U32, COUNT_TIME_INDOM, PM_SEM_COUNTER,
{ 0,1,0,0,PM_TIME_USEC,0} }, },
{ NULL, { PMDA_PMID(5,0), PM_TYPE_U32, BYTE_INDOM, PM_SEM_COUNTER,
{ 1,0,0,PM_SPACE_BYTE,0,0} }, }
};
extern int errno;
struct profile_stats *stats;
struct profile_header *shmheader;
int shmid = -1;
int
samba_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
{
__pmID_int *idp = (__pmID_int *)&(mdesc->m_desc.pmid);
if (inst != PM_IN_NULL && mdesc->m_desc.indom == PM_INDOM_NULL)
return PM_ERR_INST;
if (idp->cluster == 0) {
switch (idp->item) {
case 0:
atom->ul = stats->smb_count;
break;
case 1:
atom->ul = stats->uid_changes;
break;
default:
return PM_ERR_PMID;
}
}
else if (idp->cluster == 1) {
switch (idp->item) {
case 0:
atom->ul = stats->statcache_lookups;
break;
case 1:
atom->ul = stats->statcache_misses;
break;
case 2:
atom->ul = stats->statcache_hits;
break;
default:
return PM_ERR_PMID;
}
}
else if (idp->cluster == 2) {
switch (idp->item) {
case 0:
atom->ul = stats->writecache_num_write_caches;
break;
case 1:
atom->ul = stats->writecache_allocated_write_caches;
break;
case 2:
atom->ul = stats->writecache_read_hits;
break;
case 3:
atom->ul = stats->writecache_total_writes;
break;
case 4:
atom->ul = stats->writecache_init_writes;
break;
case 5:
atom->ul = stats->writecache_abutted_writes;
break;
case 6:
atom->ul = stats->writecache_num_perfect_writes;
break;
case 7:
atom->ul = stats->writecache_direct_writes;
break;
case 8:
atom->ul = stats->writecache_non_oplock_writes;
break;
case 9:
atom->ul = stats->writecache_flushed_writes[SEEK_FLUSH];
break;
case 10:
atom->ul = stats->writecache_flushed_writes[READ_FLUSH];
break;
case 11:
atom->ul = stats->writecache_flushed_writes[WRITE_FLUSH];
break;
case 12:
atom->ul = stats->writecache_flushed_writes[READRAW_FLUSH];
break;
case 13:
atom->ul = stats->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH];
break;
case 14:
atom->ul = stats->writecache_flushed_writes[CLOSE_FLUSH];
break;
case 15:
atom->ul = stats->writecache_flushed_writes[SYNC_FLUSH];
break;
case 16:
atom->ul = stats->writecache_flushed_writes[SIZECHANGE_FLUSH];
break;
default:
return PM_ERR_PMID;
}
}
else if (idp->cluster == 3) {
if (idp->item == 0) {
if (inst < indomtab[COUNT_TIME_INDOM].it_numinst) {
unsigned *p;
p = (unsigned *)((unsigned)stats + samba_counts[inst].offset);
atom->ul = *p;
}
else
return PM_ERR_INST;
}
else
return PM_ERR_PMID;
}
else if (idp->cluster == 4) {
if (idp->item == 0) {
if (inst < indomtab[COUNT_TIME_INDOM].it_numinst) {
unsigned *p;
p = (unsigned *)((unsigned)stats + samba_times[inst].offset);
atom->ul = *p;
}
else
return PM_ERR_INST;
}
else
return PM_ERR_PMID;
}
else if (idp->cluster == 5) {
if (idp->item == 0) {
if (inst < indomtab[BYTE_INDOM].it_numinst) {
unsigned *p;
p = (unsigned *)((unsigned)stats + samba_bytes[inst].offset);
atom->ul = *p;
}
else
return PM_ERR_INST;
}
else
return PM_ERR_PMID;
}
else
return PM_ERR_PMID;
return 0;
}
void
samba_init(pmdaInterface *dp)
{
int inst_count, i;
if (dp->status != 0)
return;
if ((shmid = shmget(PROF_SHMEM_KEY, 0, 0)) == -1) {
fprintf(stderr, "shmid: %s\n", strerror(errno));
fprintf(stderr, "samba not compiled with profile support or not running\n");
exit(1);
}
shmheader = (struct profile_header *)shmat(shmid, NULL, SHM_RDONLY);
if ((int)shmheader == -1) {
fprintf(stderr, "shmat: %s\n", strerror(errno));
exit(1);
}
inst_count = sizeof(samba_counts)/sizeof(samba_counts[0]);
counttime = (pmdaInstid *)malloc(inst_count * sizeof(pmdaInstid));
if (counttime == NULL) {
__pmNoMem("count&time",inst_count * sizeof(pmdaInstid),PM_FATAL_ERR);
}
for (i = 0; i < inst_count; i++) {
counttime[i].i_inst = i;
counttime[i].i_name = samba_counts[i].name;
}
indomtab[COUNT_TIME_INDOM].it_numinst = inst_count;
indomtab[COUNT_TIME_INDOM].it_set = counttime;
inst_count = sizeof(samba_bytes)/sizeof(samba_bytes[0]);
bytes = (pmdaInstid *)malloc(inst_count * sizeof(pmdaInstid));
if (bytes == NULL) {
__pmNoMem("bytes",inst_count * sizeof(pmdaInstid),PM_FATAL_ERR);
}
for (i = 0; i < inst_count; i++) {
bytes[i].i_inst = i;
bytes[i].i_name = samba_bytes[i].name;
}
indomtab[BYTE_INDOM].it_numinst = inst_count;
indomtab[BYTE_INDOM].it_set = bytes;
pmdaSetFetchCallBack(dp, samba_fetchCallBack);
pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]),
metrictab, sizeof(metrictab)/sizeof(metrictab[0]));
if (!shmheader)
fprintf(stderr, "samba_init: shmem not mapped\n");
else if (shmheader->prof_shm_magic != PROF_SHM_MAGIC)
fprintf(stderr, "samba_init: bad magic\n");
else if (shmheader->prof_shm_version != PROF_SHM_VERSION)
fprintf(stderr, "samba_init: bad version %X\n",
shmheader->prof_shm_version);
else {
stats = &shmheader->stats;
return;
}
exit(1);
}
int
main(int argc, char **argv)
{
int err = 0;
char *p;
pmdaInterface dispatch;
for (p = pmProgname = argv[0]; *p; p++)
if (*p == '/') pmProgname = p+1;
pmdaDaemon(&dispatch, PMDA_INTERFACE_2, pmProgname, SAMBA,
"samba.log", "/var/pcp/pmdas/samba/help");
if (pmdaGetOpt(argc, argv, "D:d:l:?", &dispatch, &err) != EOF) {
fprintf(stderr, "Usage: %s [options]\n\n\
Options:\n\
-d domain use domain (numeric) for metrics domain of PMDA\n\
-l logfile write log into logfile rather than using default log name\n",
pmProgname);
exit(1);
}
pmdaOpenLog(&dispatch);
samba_init(&dispatch);
pmdaConnect(&dispatch);
pmdaMain(&dispatch);
exit(0);
}