-/* $OpenBSD: mib.c,v 1.4 2023/07/04 11:34:19 sashan Exp $ */
+/* $OpenBSD: mib.c,v 1.5 2023/10/24 18:16:05 martijn Exp $ */
/*
* Copyright (c) 2022 Martijn van Duren <martijn@openbsd.org>
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 *);
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 *);
struct agentx_object *obj;
enum agentx_request_type req;
int32_t idx;
+ int32_t time;
struct kinfo_proc *kinfo;
char *s;
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__);
}
kr_init();
pf_init();
timer_init();
+ pageshift_init();
if (agentxsocket != NULL) {
if (strlcpy(agentxsocketdir, agentxsocket,
(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");
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
snmp_connect(struct agentx *sa, void *cookie, int close)
{