Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudwatch agent yocto recipe #5

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Add node-exporter recipe
  • Loading branch information
MoeMahhouk committed Aug 28, 2024
commit a51c68834ed9cd85ea3ad773a9b7d8e38fa47b9b
2 changes: 1 addition & 1 deletion recipes-core/images/cvm-initramfs.bbappend
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PACKAGE_INSTALL:append = " fluent-bit prometheus"
PACKAGE_INSTALL:append = " fluent-bit prometheus node-exporter"
17 changes: 17 additions & 0 deletions recipes-tools/node-exporter/files/node_exporter.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Default settings for node_exporter

# Options to pass to node_exporter
ARGS=""

# User and group to run node_exporter as
USER="node_exporter"
GROUP="node_exporter"

# Path to the node_exporter binary
DAEMON="/usr/bin/node_exporter"

# Path to the PID file
PIDFILE="/var/run/node_exporter.pid"

# Path to the log file
LOGFILE="/tmp/node_exporter.log"
70 changes: 70 additions & 0 deletions recipes-tools/node-exporter/files/node_exporter.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: node_exporter
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Prometheus Node Exporter
### END INIT INFO

# Set default values
DAEMON="/usr/bin/node_exporter"
USER="node_exporter"
GROUP="node_exporter"
PIDFILE="/var/run/node_exporter.pid"
LOGFILE="/tmp/node_exporter.log"
ARGS=""

# Read configuration variable file if it is present
[ -r /etc/default/node_exporter ] && . /etc/default/node_exporter

start() {
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
start-stop-daemon --start --quiet --background \
--make-pidfile --pidfile $PIDFILE \
--chuid $USER:$GROUP \
--exec $DAEMON -- $ARGS >> $LOGFILE 2>&1
echo 'Service started' >&2
}

stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE") 2>/dev/null; then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
start-stop-daemon --stop --quiet --pidfile $PIDFILE --name node_exporter
rm -f $PIDFILE
echo 'Service stopped' >&2
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then
echo "Service is running"
else
echo "Service is stopped"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0
49 changes: 49 additions & 0 deletions recipes-tools/node-exporter/node-exporter.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SUMMARY = "Prometheus exporter for hardware and OS metrics"
DESCRIPTION = "Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written in Go with pluggable metric collectors."
HOMEPAGE = "https://github.com/prometheus/node_exporter"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327"

inherit update-rc.d useradd

PV = "1.8.2"

SRC_URI = "https://github.com/prometheus/node_exporter/releases/download/v${PV}/node_exporter-${PV}.linux-amd64.tar.gz \
file://node_exporter.init \
file://node_exporter.default"

SRC_URI[sha256sum] = "6809dd0b3ec45fd6e992c19071d6b5253aed3ead7bf0686885a51d85c6643c66"

S = "${WORKDIR}/node_exporter-${PV}.linux-amd64"

USERADD_PACKAGES = "${PN}"
GROUPADD_PARAM:${PN} = "-r node_exporter"
USERADD_PARAM:${PN} = "-r -g node_exporter -d /var/lib/node_exporter -s /sbin/nologin -c 'Node Exporter' node_exporter"

do_install() {
install -d ${D}${bindir}
install -m 0755 ${S}/node_exporter ${D}${bindir}

install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/node_exporter.init ${D}${sysconfdir}/init.d/node_exporter

install -d ${D}${sysconfdir}/default
install -m 0644 ${WORKDIR}/node_exporter.default ${D}${sysconfdir}/default/node_exporter

# Create directory for Node Exporter data
install -d ${D}/var/lib/node_exporter

# Set correct ownership
chown -R node_exporter:node_exporter ${D}/var/lib/node_exporter
}

pkg_postinst_ontarget:${PN}() {
# Ensure the log file can be created by the node_exporter user
touch /tmp/node_exporter.log
chown node_exporter:node_exporter /tmp/node_exporter.log
}

INITSCRIPT_NAME = "node_exporter"
INITSCRIPT_PARAMS = "defaults 95 15"

FILES:${PN} += "${sysconfdir} /var/lib/node_exporter"