Zabbix agent, read source code, debunk item key

Start capital:
Item key:
vm.memory.size[pused]
Hardware:
Solaris 10
OS:
SunOS 5.10
Where to look:
{"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE,  "free"},
vm.memory.size - Item key in Zabbix
CF_HAVEPARAMS - Does the item support arguments. this field will be replace with 0 if not arguments are supported
VM_MEMORY_SIZE - function name. this is most important argument to seek it next
"free" - what type of argument is used by default when you write zabbix_agentd -p to print supported item keys

Look for memory:
In memory.c we must search 'pused':
 if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
  ret = VM_MEMORY_TOTAL(result);
 else if (0 == strcmp(mode, "free"))
  ret = VM_MEMORY_FREE(result);
 else if (0 == strcmp(mode, "used"))
  ret = VM_MEMORY_USED(result);
 else if (0 == strcmp(mode, "pused"))
  ret = VM_MEMORY_PUSED(result);
 else if (0 == strcmp(mode, "available"))
  ret = VM_MEMORY_AVAILABLE(result);
 else if (0 == strcmp(mode, "pavailable"))
  ret = VM_MEMORY_PAVAILABLE(result);
The previous output says we must use function VM_MEMORY_PUSED so the final answer the percentage of user memory for Solaris 10 is:
static int VM_MEMORY_PUSED(AGENT_RESULT *result)
{
 zbx_uint64_t used, total;

 if (0 == (total = sysconf(_SC_PHYS_PAGES)))
 {
  SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
  return SYSINFO_RET_FAIL;
 }

 used = total - sysconf(_SC_AVPHYS_PAGES);

 SET_DBL_RESULT(result, used / (double)total * 100);

 return SYSINFO_RET_OK;
}

No comments: