Hi,
Turns out adding derived metrics support to zbxpcp is trivial.
Based on comments from Ken yesterday I think we can ignore errors from
pmLoadDerivedMetrics, if the configuration file is malformed then
messages will be logged into the zabbix-agent log file.
Update the man page accordingly. The file name is quite a name monster,
please feel free to adjust if you can come up with something better.
A small CodingStyle fixlet included as a bonus as well.
---
src/zabbix-agent/src/zbxpcp.3 | 10 +++++++++-
src/zabbix-agent/src/zbxpcp.c | 15 ++++++++++-----
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/zabbix-agent/src/zbxpcp.3 b/src/zabbix-agent/src/zbxpcp.3
index 3a03d19..557ac4a 100644
--- a/src/zabbix-agent/src/zbxpcp.3
+++ b/src/zabbix-agent/src/zbxpcp.3
@@ -117,6 +117,13 @@ the system.
.BI /etc/zabbix/zabbix_agentd.conf
Typical Zabbix agent configuration file location.
.TP 10
+.BI /etc/zabbix/zbxpcp-derived-metrics.conf
+Optional PCP derived metrics configuration file for
+.BR zbxpcp .
+See
+.BR pmLoadDerivedConfig (3)
+for more info on derived metrics.
+.TP 10
.BI $(PCP_LIB_DIR)/zabbix/agent/zbxpcp.so
Zabbix agent loadable PCP module.
.PD
@@ -124,6 +131,7 @@ Zabbix agent loadable PCP module.
.BR PCPIntro (1),
.BR pminfo (1),
.BR pmrep (1),
-.BR zabbix_get (1)
+.BR zabbix_get (1),
+.BR pmLoadDerivedConfig (3)
and
.BR zabbix_agentd (8).
diff --git a/src/zabbix-agent/src/zbxpcp.c b/src/zabbix-agent/src/zbxpcp.c
index fef75f3..5e20d4f 100644
--- a/src/zabbix-agent/src/zbxpcp.c
+++ b/src/zabbix-agent/src/zbxpcp.c
@@ -19,7 +19,6 @@
/*
* TODO
- * - derived metrics support
* - config file support
* - conn type
* - conn target
@@ -36,6 +35,10 @@
#define ZBX_PCP_METRIC_PREFIX "pcp."
#endif
+#ifndef ZBX_PCP_DERIVED_CONFIG
+#define ZBX_PCP_DERIVED_CONFIG "/etc/zabbix/zbxpcp-derived-metrics.conf"
+#endif
+
/* PCP includes. */
#include "pmapi.h"
#include "impl.h"
@@ -50,6 +53,10 @@ static int ctx = -1;
int zbx_module_pcp_connect()
{
+ /* Load possible derived metric definitions. */
+ if (access(ZBX_PCP_DERIVED_CONFIG, F_OK ) != -1)
+ pmLoadDerivedConfig(ZBX_PCP_DERIVED_CONFIG);
+
ctx = pmNewContext(PM_CONTEXT_HOST, "localhost");
return ctx;
}
@@ -228,11 +235,9 @@ int zbx_module_pcp_fetch_metric(AGENT_REQUEST *request,
AGENT_RESULT *result)
}
/* Locate the correct instance. */
- for (i = 0; desc[0].indom != PM_INDOM_NULL && i < rp->vset[0]->numval;
i++) {
- if (rp->vset[0]->vlist[i].inst == iid) {
+ for (i = 0; desc[0].indom != PM_INDOM_NULL && i < rp->vset[0]->numval; i++)
+ if (rp->vset[0]->vlist[i].inst == iid)
break;
- }
- }
if (i == rp->vset[0]->numval) {
pmFreeResult(rp);
return SYSINFO_RET_FAIL;
Thanks,
--
Marko Myllynen
|