On Wed, Oct 18, 2023 at 11:54:06AM +0200, Martijn van Duren wrote:
> This diff adds the two entries from the hrSWRunPerfTable:
> hrSWRunPerfCPU, and hrSWRunPerfMem. This allows snmptop from the
> net-snmp package to work. Math stolen^Wcopied from top/machine.c.
>
> OK?
ok
>
> martijn@
>
> Index: mib.c
> ===================================================================
> RCS file: /cvs/src/libexec/snmpd/snmpd_metrics/mib.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 mib.c
> --- mib.c 4 Jul 2023 11:34:19 -0000 1.4
> +++ mib.c 18 Oct 2023 09:52:07 -0000
> @@ -69,6 +69,10 @@ struct event connev;
> const char *agentxsocket = NULL;
> int agentxfd = -1;
>
> +int pageshift;
> +#define pagetok(size) ((size) << pageshift)
> +
> +void pageshift_init(void);
> void snmp_connect(struct agentx *, void *, int);
> void snmp_tryconnect(int, short, void *);
> void snmp_read(int, short, void *);
> @@ -89,6 +93,7 @@ struct agentx_object *hrProcessorLoad;
> struct agentx_index *hrSWRunIdx;
> struct agentx_object *hrSWRunIndex, *hrSWRunName, *hrSWRunID, *hrSWRunPath;
> struct agentx_object *hrSWRunParameters, *hrSWRunType, *hrSWRunStatus;
> +struct agentx_object *hrSWRunPerfCPU, *hrSWRunPerfMem;
>
> void mib_hrsystemuptime(struct agentx_varbind *);
> void mib_hrsystemdate(struct agentx_varbind *);
> @@ -634,6 +639,7 @@ mib_hrswrun(struct agentx_varbind *vb)
> struct agentx_object *obj;
> enum agentx_request_type req;
> int32_t idx;
> + int32_t time;
> struct kinfo_proc *kinfo;
> char *s;
>
> @@ -711,6 +717,13 @@ mib_hrswrun(struct agentx_varbind *vb)
> agentx_varbind_integer(vb, 4);
> break;
> }
> + } else if (obj == hrSWRunPerfCPU) {
> + time = kinfo->p_rtime_sec * 100;
> + time += (kinfo->p_rtime_usec + 5000) / 10000;
> + agentx_varbind_integer(vb, time);
> + } else if (obj == hrSWRunPerfMem) {
> + agentx_varbind_integer(vb, pagetok(kinfo->p_vm_tsize +
> + kinfo->p_vm_dsize + kinfo->p_vm_ssize));
> } else
> fatal("%s: Unexpected object", __func__);
> }
> @@ -3278,6 +3291,7 @@ main(int argc, char *argv[])
> kr_init();
> pf_init();
> timer_init();
> + pageshift_init();
>
> if (agentxsocket != NULL) {
> if (strlcpy(agentxsocketdir, agentxsocket,
> @@ -3375,6 +3389,10 @@ main(int argc, char *argv[])
> (hrSWRunType = agentx_object(host, AGENTX_OID(HRSWRUNTYPE),
> &hrSWRunIdx, 1, 0, mib_hrswrun)) == NULL ||
> (hrSWRunStatus = agentx_object(host, AGENTX_OID(HRSWRUNSTATUS),
> + &hrSWRunIdx, 1, 0, mib_hrswrun)) == NULL ||
> + (hrSWRunPerfCPU = agentx_object(host, AGENTX_OID(HRSWRUNPERFCPU),
> + &hrSWRunIdx, 1, 0, mib_hrswrun)) == NULL ||
> + (hrSWRunPerfMem = agentx_object(host, AGENTX_OID(HRSWRUNPERFMEM),
> &hrSWRunIdx, 1, 0, mib_hrswrun)) == NULL)
> fatal("agentx_object");
>
> @@ -4318,6 +4336,22 @@ main(int argc, char *argv[])
> log_setverbose(verbose);
>
> event_dispatch();
> +}
> +
> +#define LOG1024 10
> +void
> +pageshift_init(void)
> +{
> + long pagesize;
> +
> + if ((pagesize = sysconf(_SC_PAGESIZE)) == -1)
> + fatal("sysconf(_SC_PAGESIZE)");
> + while (pagesize > 1) {
> + pageshift++;
> + pagesize >>= 1;
> + }
> + /* we only need the amount of log(2)1024 for our conversion */
> + pageshift -= LOG1024;
> }
>
> void
>