Skip to content

Commit

Permalink
New item docker.port.discovery (#88)
Browse files Browse the repository at this point in the history
* docker.port.discovery
* v0.6.9
  • Loading branch information
jangaraj authored Jan 14, 2018
1 parent 32ece16 commit dba2fb7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Changes 0.6.9
- new item key docker.port.discovery

# Changes 0.6.8
- fixed docker.discovery for newer kernels 4.X ([#80](https://github.com/monitoringartist/zabbix-docker-monitoring/pull/80))

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ Note: cid - container ID, two options are available:

| Key | Description |
| --- | ----------- |
| **docker.discovery[\<par1\>,\<par2\>,\<par3\>]** | **LLD discovering:**<br>Only running containers are discovered.<br>[Additional Docker permissions](#additional-docker-permissions) are needed when you want to see container name (human name) in metrics/graphs instead of short container ID. Optional parameters are used for definition of HCONTAINERID - docker.inspect function will be used in this case.<br>For example:<br>*docker.discovery[Config,Env,MESOS_TASK_ID=]* is recommended for Mesos/Chronos/Marathon container monitoring<br>Note 1: *docker.discovery* is faster version of *docker.discovery[Name]*<br>Note 2: Available macros:<br>*{#FCONTAINERID}* - full container ID (64 character string)<br>*{#SCONTAINERID}* - short container ID (12 character string)<br>*{#HCONTAINERID}* - human name of container<br>*{#SYSTEM.HOSTNAME}* - system hostname |
| **docker.discovery[\<par1\>,\<par2\>,\<par3\>]** | **LLD container discovering:**<br>Only running containers are discovered.<br>[Additional Docker permissions](#additional-docker-permissions) are needed when you want to see container name (human name) in metrics/graphs instead of short container ID. Optional parameters are used for definition of HCONTAINERID - docker.inspect function will be used in this case.<br>For example:<br>*docker.discovery[Config,Env,MESOS_TASK_ID=]* is recommended for Mesos/Chronos/Marathon container monitoring<br>Note 1: *docker.discovery* is faster version of *docker.discovery[Name]*<br>Note 2: Available macros:<br>*{#FCONTAINERID}* - full container ID (64 character string)<br>*{#SCONTAINERID}* - short container ID (12 character string)<br>*{#HCONTAINERID}* - human name of container<br>*{#SYSTEM.HOSTNAME}* - system hostname |
| **docker.port.discovery[cid,\<protocol\>]** | **LLD published container port dicovering:**<br>**protocol** - port protocol, which should be discovered, default value *all*, available protocols: *tcp,udp* |
| **docker.mem[cid,mmetric]** | **Memory metrics:**<br>**mmetric** - any available memory metric in the pseudo-file memory.stat, e.g.: *cache, rss, mapped_file, pgpgin, pgpgout, swap, pgfault, pgmajfault, inactive_anon, active_anon, inactive_file, active_file, unevictable, hierarchical_memory_limit, hierarchical_memsw_limit, total_cache, total_rss, total_mapped_file, total_pgpgin, total_pgpgout, total_swap, total_pgfault, total_pgmajfault, total_inactive_anon, total_active_anon, total_inactive_file, total_active_file, total_unevictable*, Note: if you have a problem with memory metrics, be sure that memory cgroup subsystem is enabled - kernel parameter: *cgroup_enable=memory* |
| **docker.cpu[cid,cmetric]** | **CPU metrics:**<br>**cmetric** - any available CPU metric in the pseudo-file cpuacct.stat/cpu.stat, e.g.: *system, user, total (current sum of system/user* or container [throttling metrics](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-cpu.html): *nr_throttled, throttled_time*<br>Note: CPU user/system/total metrics must be recalculated to % utilization value by Zabbix - *Delta (speed per second)*. |
| **docker.dev[cid,bfile,bmetric]** | **Blk IO metrics:**<br>**bfile** - container blkio pseudo-file, e.g.: *blkio.io_merged, blkio.io_queued, blkio.io_service_bytes, blkio.io_serviced, blkio.io_service_time, blkio.io_wait_time, blkio.sectors, blkio.time, blkio.avg_queue_size, blkio.idle_time, blkio.dequeue, ...*<br>**bmetric** - any available blkio metric in selected pseudo-file, e.g.: *Total*. Option for selected block device only is also available e.g. *'8:0 Sync'* (quotes must be used in key parameter in this case)<br>Note: Some pseudo blkio files are available only if kernel config *CONFIG_DEBUG_BLK_CGROUP=y*, see recommended docs. |
Expand Down
104 changes: 103 additions & 1 deletion src/modules/zabbix_module_docker/zabbix_module_docker.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ struct inspect_result
};
struct timeval stimeout;

char *m_version = "v0.6.8";
char *m_version = "v0.6.9";
char *stat_dir = NULL, *driver, *c_prefix = NULL, *c_suffix = NULL, *cpu_cgroup = NULL, *hostname = 0;
static int item_timeout = 1, buffer_size = 1024, cid_length = 66, socket_api;
int zbx_module_docker_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_module_docker_port_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_module_docker_inspect(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_module_docker_cstatus(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_module_docker_istatus(AGENT_REQUEST *request, AGENT_RESULT *result);
Expand All @@ -69,6 +70,7 @@ static ZBX_METRIC keys[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
{"docker.discovery", CF_HAVEPARAMS, zbx_module_docker_discovery, "<parameter 1>, <parameter 2>, <parameter 3>"},
{"docker.port.discovery", CF_HAVEPARAMS, zbx_module_docker_port_discovery, "full container id, <protocol>"},
{"docker.inspect", CF_HAVEPARAMS, zbx_module_docker_inspect, "full container id, parameter 1, <parameter 2>"},
{"docker.cstatus", CF_HAVEPARAMS, zbx_module_docker_cstatus, "status"},
{"docker.istatus", CF_HAVEPARAMS, zbx_module_docker_istatus, "status"},
Expand Down Expand Up @@ -524,6 +526,106 @@ struct inspect_result zbx_module_docker_inspect_exec(AGENT_REQUEST *request)
return iresult;
}

/******************************************************************************
* *
* Function: zbx_module_docker_port_discovery *
* *
* Purpose: published container port discovery *
* *
* Return value: SYSINFO_RET_FAIL - function failed, item will be marked *
* as not supported by zabbix *
* SYSINFO_RET_OK - success *
* *
******************************************************************************/
int zbx_module_docker_port_discovery(AGENT_REQUEST * request, AGENT_RESULT * result) {
zabbix_log(LOG_LEVEL_DEBUG, "In zbx_module_docker_discover_ports()");

if (2 < request->nparam || 0 == request->nparam) {
zabbix_log(LOG_LEVEL_ERR, "Invalid number of parameters: %d", request->nparam);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters"));
return SYSINFO_RET_FAIL;
}

char * container;
container = get_rparam(request, 0);

AGENT_REQUEST request2;
init_request(&request2);
add_request_param(&request2, zbx_strdup(NULL, container));
add_request_param(&request2, zbx_strdup(NULL, "HostConfig"));
add_request_param(&request2, zbx_strdup(NULL, "PortBindings"));
struct inspect_result iresult;
iresult = zbx_module_docker_inspect_exec(&request2);
free_request(&request2);
if (iresult.return_code == SYSINFO_RET_FAIL) {
zabbix_log(LOG_LEVEL_DEBUG, "zbx_module_docker_inspect_exec FAIL: %s", iresult.value);
return SYSINFO_RET_FAIL;
}

// now parse the value we get back from zbx_module_docker_inspect_exec()
struct zbx_json_parse jp_data = {
iresult.value,
&iresult.value[strlen(iresult.value)]
};

char buf[10], host_port[6], container_port[6];
int port_len;
const char *p = NULL,
*p2 = NULL,
*proto = NULL,
*request_proto = NULL;
struct zbx_json_parse jp_obj;

struct zbx_json j;
zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);

if (1 < request->nparam) {
request_proto = get_rparam(request, 1);
}
while (NULL != (p = zbx_json_pair_next(&jp_data, p, buf, sizeof(buf)))) {
// Split "12345/tcp" specifier
proto = strstr(buf, "/") + 1;
port_len = proto - buf;
zbx_strlcpy(container_port, buf, port_len);

if (NULL != request_proto && '\0' != *request_proto && 0 != strcmp(request_proto, proto)) {
continue;
}

// Open list of HostIP/HostPort dicts
if (FAIL == zbx_json_brackets_open(p, &jp_obj)) {
zabbix_log(LOG_LEVEL_DEBUG, "zbx_json_brackets_open FAIL: %s", zbx_json_strerror());
continue;
}

// Open dict of HostIP, HostPort values
p2 = zbx_json_next(&jp_obj, NULL);
if (FAIL == zbx_json_brackets_open(p2, &jp_obj)) {
zabbix_log(LOG_LEVEL_DEBUG, "zbx_json_brackets_open FAIL: %s", zbx_json_strerror());
continue;
}

// Lookup HostPort value
if (FAIL == zbx_json_value_by_name(&jp_obj, "HostPort", host_port, sizeof(host_port))) {
zabbix_log(LOG_LEVEL_DEBUG, "zbx_json_value_by_name FAIL: %s", zbx_json_strerror());
continue;
}

zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, "{#HOSTPORT}", host_port, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#CONTAINERPORT}", container_port, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "{#PROTO}", proto, ZBX_JSON_TYPE_STRING);
zbx_json_close(&j);

}
zbx_json_close(&j);
SET_STR_RESULT(result, zbx_strdup(NULL, j.buffer));
zbx_json_free(&j);

return SYSINFO_RET_OK;
}

/******************************************************************************
* *
* Function: zbx_module_docker_get_fci *
Expand Down

0 comments on commit dba2fb7

Please sign in to comment.