Package Request: collectd Write Prometheus plugin

Right now, it looks like the most common ways for people to get metrics from OpenWrt into Prometheus are to use the prometheus-node-exporter-* packages or by using collectd-mod-* and using collect-mod-network to send metrics to a collectd_exporter instance, and having Prometheus scrape the collectd_exporter instance.

A collectd Write Prometheus plugin exists which serves its own metrics page for Prometheus to scape, so collectd_exporter would not be required.

Could this plugin be created as a package for OpenWrt?

I can try enabling the plugin and see if it builds ok in OpenWrt context.

(Based on the plugin page, it depends on protobuf-c and libmicrohttpd, which both we do have. So there should be no blockers.)

3 Likes

Looks a bit more difficult.
The collectd configure.ac does not find the protoc-c compiler, athough the basic libprotobuf packages are found...

libprotobuf . . . . . yes
libprotobuf-c . . . . yes
...
protobuf-c  . . . . . no (protoc-c compiler not found)

I did not succeed in defining the plugin. It apparently fails in finding a protobuf-c compiler ("protoc-c" compiler?)

I am not sure if that protoc-c is even installed with our protobuf-c package.

The change I tried:

perus@ub2304:/Openwrt/e8450/feeds/packages$ git diff
diff --git a/utils/collectd/Makefile b/utils/collectd/Makefile
index 308a4dc22..70c7b0789 100644
--- a/utils/collectd/Makefile
+++ b/utils/collectd/Makefile
@@ -122,7 +122,6 @@ COLLECTD_PLUGINS_DISABLED:= \
        write_kafka \
        write_log \
        write_mongodb \
-       write_prometheus \
        write_redis \
        write_riemann \
        write_sensu \
@@ -209,7 +208,8 @@ COLLECTD_PLUGINS_SELECTED:= \
        vmem \
        wireless \
        write_graphite \
-       write_http
+       write_http \
+       write_prometheus
 
 PKG_CONFIG_DEPENDS:= \
        $(patsubst %,CONFIG_PACKAGE_collectd-mod-%,$(subst _,-,$(COLLECTD_PLUGINS_SELECTED))) \
@@ -365,6 +365,10 @@ else
   CONFIGURE_ARGS+= --without-libudev
 endif
 
+ifneq ($(CONFIG_PACKAGE_collectd-mod-write-prometheus),)
+  CONFIGURE_ARGS+= --with-protoc_c="$(STAGING_DIR)/usr/bin/protoc"
+endif
+
 define Package/collectd/conffiles
 /etc/collectd.conf
 /etc/config/collectd
@@ -548,6 +552,7 @@ $(eval $(call BuildPlugin,vmem,virtual memory usage input,vmem,))
 $(eval $(call BuildPlugin,wireless,wireless status input,wireless,))
 $(eval $(call BuildPlugin,write-graphite,Carbon/Graphite output,write_graphite,+PACKAGE_collectd-mod-write-graphite:libpthread))
 $(eval $(call BuildPlugin,write-http,HTTP POST output,write_http,+PACKAGE_collectd-mod-write-http:libcurl))
+$(eval $(call BuildPlugin,write-prometheus,Prometheus output,write_prometheus,+PACKAGE_collectd-mod-write-prometheus:libmicrohttpd +PACKAGE_collectd-mod-write-prometheus:libprotobuf-c))
 
 $(eval $(call BuildScriptPlugin,sqm,SQM/qdisc collection,sqm_collectd,+PACKAGE_collectd-mod-sqm:collectd-mod-exec))
 $(eval $(call BuildScriptLuaPlugin,ltq-dsl,Lantiq DSL collection,dsl,@ltq-dsl-app +PACKAGE_collectd-mod-ltq-dsl:collectd-mod-lua +libubus-lua))

If you want the plugin, please test compiling it yourself, and get the protoc-c compiler defined/built/included/found.

I was able to compile the plugin by adding a dependency on the host variant of protobuf-c, basing on the provided patch (tested on release 23.05.2 and rpi4b).

The protoc binary needs to run on host during the build process, I also changed the flag so it points to the protobuf-c library now instead of the compiler (automake didn't seem to recognize the --with-protoc_c anyway.

The only thing I am not happy with is that the dependency on protobuf-c/host is added for the package "globally", I didn't find an easy way to add it only for the scenarios where "write_prometheus" plugin is built. Simply adding the line in the same condition clause as the CONFIGURE_ARGS seems to have no effect (the dependency is not added at all).

diff --git a/utils/collectd/Makefile b/utils/collectd/Makefile
index 0119c88aa..7c60fead2 100644
--- a/utils/collectd/Makefile
+++ b/utils/collectd/Makefile
@@ -29,6 +29,8 @@ PKG_CONFIG_DEPENDS:= \
 	PACKAGE_COLLECTD_ENCRYPTED_NETWORK \
 	PACKAGE_COLLECTD_DEBUG_OUTPUT_ENABLE
 
+PKG_BUILD_DEPENDS+=protobuf-c/host
+
 COLLECTD_PLUGINS_DISABLED:= \
 	amqp \
 	amqp1 \
@@ -120,7 +122,6 @@ COLLECTD_PLUGINS_DISABLED:= \
 	write_kafka \
 	write_log \
 	write_mongodb \
-	write_prometheus \
 	write_redis \
 	write_riemann \
 	write_sensu \
@@ -207,7 +208,8 @@ COLLECTD_PLUGINS_SELECTED:= \
 	vmem \
 	wireless \
 	write_graphite \
-	write_http
+	write_http \
+	write_prometheus
 
 PKG_CONFIG_DEPENDS:= \
 	$(patsubst %,CONFIG_PACKAGE_collectd-mod-%,$(subst _,-,$(COLLECTD_PLUGINS_SELECTED))) \
@@ -349,6 +351,12 @@ ifneq ($(CONFIG_PACKAGE_collectd-mod-disk),)
 	--with-libudev="$(STAGING_DIR)/usr"
 endif
 
+# exception: write-prometheus needs protobuf-c
+ifneq ($(CONFIG_PACKAGE_collectd-mod-write-prometheus),)
+  CONFIGURE_ARGS+= \
+	--with-libprotobuf_c="$(STAGING_DIR)/usr"
+endif
+
 define Package/collectd/conffiles
 /etc/collectd.conf
 /etc/config/collectd
@@ -530,6 +538,7 @@ $(eval $(call BuildPlugin,vmem,virtual memory usage input,vmem,))
 $(eval $(call BuildPlugin,wireless,wireless status input,wireless,))
 $(eval $(call BuildPlugin,write-graphite,Carbon/Graphite output,write_graphite,+PACKAGE_collectd-mod-write-graphite:libpthread))
 $(eval $(call BuildPlugin,write-http,HTTP POST output,write_http,+PACKAGE_collectd-mod-write-http:libcurl))
+$(eval $(call BuildPlugin,write-prometheus,Prometheus output,write_prometheus,+PACKAGE_collectd-mod-write-prometheus:libmicrohttpd +PACKAGE_collectd-mod-write-prometheus:libprotobuf-c))
 
 $(eval $(call BuildScriptPlugin,sqm,SQM/qdisc collection,sqm_collectd,+PACKAGE_collectd-mod-sqm:collectd-mod-exec))
 $(eval $(call BuildScriptLuaPlugin,ltq-dsl,Lantiq DSL collection,dsl,@ltq-dsl-app +PACKAGE_collectd-mod-ltq-dsl:collectd-mod-lua +libubus-lua))

1 Like