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
Show file tree
Hide file tree
Changes from all commits
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
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 = ""
PACKAGE_INSTALL:append = " fluent-bit prometheus node-exporter process-exporter cloudwatch-agent"
83 changes: 83 additions & 0 deletions recipes-tools/cloudwatch-agent/cloudwatch-agent.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
SUMMARY = "AWS CloudWatch Agent"
DESCRIPTION = "The CloudWatch Agent enables you to collect metrics and logs from Amazon EC2 instances and on-premises servers."
HOMEPAGE = "https://github.com/aws/amazon-cloudwatch-agent"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://src/${GO_WORKDIR}/LICENSE;md5=4dde6168ca1ce801034ffe20cabf2b37"

DEPENDS = "go-native"
inherit go-mod useradd

PV = "1.300043.0"
SRCREV = "v1.300043.0"

SRC_URI = "git://github.com/aws/amazon-cloudwatch-agent.git;protocol=https;nobranch=1 \
file://cloudwatch-agent.init \
file://cloudwatch-agent.json"

S = "${WORKDIR}/git"

GO_LINKSHARED = ""
do_compile[network] = "1"

USERADD_PACKAGES = "${PN}"
GROUPADD_PARAM:${PN} = "-r cwagent"
USERADD_PARAM:${PN} = "-r -g cwagent -d /var/lib/cwagent -s /sbin/nologin -c 'CloudWatch Agent' cwagent"

# reproducible builds
INHIBIT_PACKAGE_DEBUG_SPLIT = '1'
INHIBIT_PACKAGE_STRIP = '1'

# Set Go import path
GO_IMPORT = "github.com/aws/amazon-cloudwatch-agent"

do_compile() {
bbwarn "Starting compile task"
cd ${S}
bbwarn "Current directory: $(pwd)"
bbwarn "Directory contents: $(ls -la)"

# Set GOPATH to include the source directory
export GOPATH="${B}/gopath"
mkdir -p ${GOPATH}/src/$(dirname ${GO_IMPORT})
ln -sf ${S} ${GOPATH}/src/${GO_IMPORT}
export GO111MODULE=on
cd ${GOPATH}/src/${GO_IMPORT}
bbwarn "Compiling in directory: $(pwd)"
bbwarn "Directory contents: $(ls -la)"
oe_runmake release
}

do_install() {
install -d ${D}${bindir}
install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/amazon-cloudwatch-agent ${D}${bindir}/amazon-cloudwatch-agent
install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/amazon-cloudwatch-agent-ctl ${D}${bindir}/amazon-cloudwatch-agent-ctl
install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/start-amazon-cloudwatch-agent ${D}${bindir}/start-amazon-cloudwatch-agent

install -d ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent
install -m 0644 ${WORKDIR}/cloudwatch-agent.json ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent/

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

# Create directory for CloudWatch Agent data
install -d ${D}/var/lib/cwagent
chown cwagent:cwagent ${D}/var/lib/cwagent

# Set correct ownership for config directory
chown -R cwagent:cwagent ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent
}

pkg_postinst_ontarget:${PN}() {
# Ensure the log file can be created by the cwagent user
touch /tmp/amazon-cloudwatch-agent.log
chown cwagent:cwagent /tmp/amazon-cloudwatch-agent.log
}

inherit update-rc.d

INITSCRIPT_NAME = "cloudwatch-agent"
INITSCRIPT_PARAMS = "defaults 95 15"

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

RDEPENDS:${PN} += "openssl"
57 changes: 57 additions & 0 deletions recipes-tools/cloudwatch-agent/files/cloudwatch-agent.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: cloudwatch-agent
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: AWS CloudWatch Agent
# Description: AWS CloudWatch Agent for collecting metrics and logs
### END INIT INFO

# Source function library.
source /etc/init.d/functions

DAEMON="/usr/bin/amazon-cloudwatch-agent"
NAME="cloudwatch-agent"
USER="cwagent"
GROUP="cwagent"
PIDFILE="/var/run/$NAME.pid"
CONFIG_FILE="/etc/amazon/amazon-cloudwatch-agent/cloudwatch-agent.json"
LOGFILE="/tmp/amazon-cloudwatch-agent.log"

do_start() {
echo -n "Starting $NAME: "
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER:$GROUP -- -config $CONFIG_FILE >> $LOGFILE 2>&1 &
echo $! > $PIDFILE
echo "done."
}

do_stop() {
echo -n "Stopping $NAME: "
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
echo "done."
}

case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
exit 1
;;
esac

exit 0
59 changes: 59 additions & 0 deletions recipes-tools/cloudwatch-agent/files/cloudwatch-agent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "cwagent"
},
"metrics": {
"namespace": "YoctoMetrics",
"metrics_collected": {
"cpu": {
"resources": [
"*"
],
"measurement": [
"usage_active",
"usage_idle",
"usage_system",
"usage_user"
],
"totalcpu": false
},
"mem": {
"measurement": [
"used_percent",
"used",
"total"
]
},
"disk": {
"resources": [
"/"
],
"measurement": [
"used_percent",
"used",
"total"
]
},
"diskio": {
"resources": [
"*"
],
"measurement": [
"reads",
"writes",
"read_bytes",
"write_bytes",
"io_time"
]
},
"netstat": {
"measurement": [
"tcp_established",
"tcp_time_wait"
]
}
}
}
}

51 changes: 51 additions & 0 deletions recipes-tools/fluent-bit/fluent-bit_3.1.6.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SUMMARY = "Fluent Bit: Fast and Lightweight Log Processor and Forwarder"
DESCRIPTION = "Fluent Bit is a fast Log Processor and Forwarder for Linux, BSD, OSX, and Windows."
HOMEPAGE = "https://fluentbit.io/"
BUGTRACKER = "https://github.com/fluent/fluent-bit/issues"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=2ee41112a44fe7014dce33e26468ba93"
SECTION = "net"

SRCREV = "v3.1.6"
SRC_URI = "git://github.com/fluent/fluent-bit.git;branch=master;protocol=https"

PV = "3.1.6"
S = "${WORKDIR}/git"
INSANE_SKIP_${PN}-dev += "dev-elf"

# Use CMake 'Unix Makefiles' generator
OECMAKE_GENERATOR ?= "Unix Makefiles"

DEPENDS = "cmake libyaml openssl zlib bison-native flex-native pkgconfig-native"

inherit cmake

EXTRA_OECMAKE = " \
-DGNU_HOST=${HOST_SYS} \
-DFLB_DEBUG=Off \
-DFLB_TRACE=Off \
-DFLB_JEMALLOC=Off \
-DFLB_TLS=On \
-DFLB_SHARED_LIB=Off \
-DFLB_EXAMPLES=Off \
-DFLB_SQLDB=Off \
-DFLB_HTTP_SERVER=On \
-DFLB_RECORD_ACCESSOR=On \
-DFLB_LUAJIT=Off \
-DFLB_FILTER_LUA=Off \
-DTEST_WRGSBASE_RESULT=0 \
"

EXTRA_OECMAKE += " --trace"


do_install() {
install -d ${D}${bindir}
install -m 0755 ${B}/bin/fluent-bit ${D}${bindir}/fluent-bit

install -d ${D}${sysconfdir}/fluent-bit/
cp -r ${S}/conf/* ${D}${sysconfdir}/fluent-bit/

install -d ${D}${docdir}/fluent-bit/
cp -r ${S}/docs/* ${D}${docdir}/fluent-bit/
}
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"
Loading