From c4605e48341a8b704d47917dbf2472524e87e1d2 Mon Sep 17 00:00:00 2001 From: Andy Lake Date: Tue, 24 Oct 2023 12:08:36 -0400 Subject: [PATCH] adding host-metrics RPM --- perfsonar-host-metrics/Makefile | 3 + perfsonar-host-metrics/exporter_opts.sh | 11 --- .../perfsonar-host-metrics/LICENSE | 0 .../perfsonar-host-metrics/Makefile | 18 ++++ .../apache-node_exporter.conf | 0 .../perfsonar-host-metrics/exporter_opts.sh | 12 +++ .../rpm/perfsonar-host-metrics.spec | 85 +++++++++++++++++++ unibuild-order | 3 +- 8 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 perfsonar-host-metrics/Makefile delete mode 100644 perfsonar-host-metrics/exporter_opts.sh create mode 100644 perfsonar-host-metrics/perfsonar-host-metrics/LICENSE create mode 100644 perfsonar-host-metrics/perfsonar-host-metrics/Makefile rename perfsonar-host-metrics/{ => perfsonar-host-metrics}/apache-node_exporter.conf (100%) create mode 100644 perfsonar-host-metrics/perfsonar-host-metrics/exporter_opts.sh create mode 100644 perfsonar-host-metrics/perfsonar-host-metrics/unibuild-packaging/rpm/perfsonar-host-metrics.spec diff --git a/perfsonar-host-metrics/Makefile b/perfsonar-host-metrics/Makefile new file mode 100644 index 0000000..274876c --- /dev/null +++ b/perfsonar-host-metrics/Makefile @@ -0,0 +1,3 @@ +AUTO_TARBALL := 1 + +include unibuild/unibuild.make \ No newline at end of file diff --git a/perfsonar-host-metrics/exporter_opts.sh b/perfsonar-host-metrics/exporter_opts.sh deleted file mode 100644 index 0335732..0000000 --- a/perfsonar-host-metrics/exporter_opts.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -TARGET_FILE="/etc/default/node_exporter" -NODE_EXPORTER_OPTS='PS_NODE_EXPORTER_OPTS="--collector.systemd --collector.systemd.unit-include=^(elmond|grafana-server|httpd|logstash|node_exporter|opensearch-dashboards|opensearch|owamp|(perfsonar-.+)|postgresql|(pscheduler-.+)|(psconfig-.+))\.service"' -grep -q PS_NODE_EXPORTER_OPTS ${TARGET_FILE} -if [ $? -eq 1 ]; then - TEMPFILE=$(mktemp) - echo ${NODE_EXPORTER_OPTS} | cat - ${TARGET_FILE} > ${TEMPFILE} - sed -E 's/^NODE_EXPORTER_OPTS="(.*)"/NODE_EXPORTER_OPTS="\1 \$PS_NODE_EXPORTER_OPTS"/' -i ${TEMPFILE} - mv ${TEMPFILE} ${TARGET_FILE} -fi diff --git a/perfsonar-host-metrics/perfsonar-host-metrics/LICENSE b/perfsonar-host-metrics/perfsonar-host-metrics/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/perfsonar-host-metrics/perfsonar-host-metrics/Makefile b/perfsonar-host-metrics/perfsonar-host-metrics/Makefile new file mode 100644 index 0000000..8475a5d --- /dev/null +++ b/perfsonar-host-metrics/perfsonar-host-metrics/Makefile @@ -0,0 +1,18 @@ +# Makefile for perfSONAR Host Metrics +# +default: + @true + +install: +ifndef PERFSONAR-ROOTPATH + @echo No PERFSONAR-ROOTPATH specified for installation + @false +endif +ifndef HTTPD-CONFIGPATH + @echo No HTTPD-CONFIGPATH specified for installation + @false +endif + mkdir -p ${PERFSONAR-ROOTPATH} + mkdir -p ${HTTPD-CONFIGPATH} + install -m 755 exporter_opts.sh ${PERFSONAR-ROOTPATH}/ + install -m 644 apache-node_exporter.conf ${HTTPD-CONFIGPATH}/ \ No newline at end of file diff --git a/perfsonar-host-metrics/apache-node_exporter.conf b/perfsonar-host-metrics/perfsonar-host-metrics/apache-node_exporter.conf similarity index 100% rename from perfsonar-host-metrics/apache-node_exporter.conf rename to perfsonar-host-metrics/perfsonar-host-metrics/apache-node_exporter.conf diff --git a/perfsonar-host-metrics/perfsonar-host-metrics/exporter_opts.sh b/perfsonar-host-metrics/perfsonar-host-metrics/exporter_opts.sh new file mode 100644 index 0000000..570de1a --- /dev/null +++ b/perfsonar-host-metrics/perfsonar-host-metrics/exporter_opts.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +TARGET_FILE="/etc/default/node_exporter" +EDIT_MARKER='#Edited by PS_HOST_METRICS' +NODE_EXPORTER_OPTS='PS_NODE_EXPORTER_OPTS=""' +grep -q PS_HOST_METRICS ${TARGET_FILE} +if [ $? -eq 1 ]; then + TEMPFILE=$(mktemp) + echo ${EDIT_MARKER} | cat - ${TARGET_FILE} > ${TEMPFILE} + sed -E 's/^NODE_EXPORTER_OPTS="(.*)"/NODE_EXPORTER_OPTS="\1 --collector.systemd --collector.systemd.unit-include=^(elmond|grafana-server|httpd|logstash|node_exporter|opensearch-dashboards|opensearch|owamp|(perfsonar-.+)|postgresql|(pscheduler-.+)|(psconfig-.+))\.service"/' -i ${TEMPFILE} + mv ${TEMPFILE} ${TARGET_FILE} +fi diff --git a/perfsonar-host-metrics/perfsonar-host-metrics/unibuild-packaging/rpm/perfsonar-host-metrics.spec b/perfsonar-host-metrics/perfsonar-host-metrics/unibuild-packaging/rpm/perfsonar-host-metrics.spec new file mode 100644 index 0000000..a763bf3 --- /dev/null +++ b/perfsonar-host-metrics/perfsonar-host-metrics/unibuild-packaging/rpm/perfsonar-host-metrics.spec @@ -0,0 +1,85 @@ +%define install_base /usr/lib/perfsonar +%define pkg_install_base %{install_base}/host_metrics +%define httpd_config_base /etc/httpd/conf.d + +#Version variables set by automated scripts +%define perfsonar_auto_version 5.0.5 +%define perfsonar_auto_relnum 1 + +# defining macros needed by SELinux +# SELinux policy type - Targeted policy is the default SELinux policy used in Red Hat Enterprise Linux. +%global selinuxtype targeted +# default boolean value needs to be changed to enable http proxy +%global selinuxbooleans httpd_can_network_connect=1 + +Name: perfsonar-host-metrics +Version: %{perfsonar_auto_version} +Release: %{perfsonar_auto_relnum}%{?dist} +Summary: perfSONAR Host Metrics +License: ASL 2.0 +Group: Development/Libraries +URL: http://www.perfsonar.net +Source0: perfsonar-host-metrics-%{version}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildArch: noarch +Requires: perfsonar-common +Requires: openssl +Requires: prometheus-node-exporter +Requires: httpd +Requires: mod_ssl +Requires: selinux-policy-%{selinuxtype} +Requires(post): selinux-policy-%{selinuxtype} +BuildRequires: selinux-policy-devel +%{?selinux_requires} + +%description +A package that installs sets-up Prometheus node_exporter for a perfSONAR install + +%prep +%setup -q -n perfsonar-host-metrics-%{version} + +%build + +%install +make PERFSONAR-ROOTPATH=%{buildroot}/%{pkg_install_base} HTTPD-CONFIGPATH=%{buildroot}/%{httpd_config_base} install + +%clean +rm -rf %{buildroot} + +%post +#Restart/enable opensearch and logstash +%systemd_post node_exporter.service +if [ "$1" = "1" ]; then + #set SELinux booleans to allow httpd proxy to work + %selinux_set_booleans -s %{selinuxtype} %{selinuxbooleans} + #update node_exporter to monitor pS processes + %{pkg_install_base}/exporter_opts.sh + + ###### + #if new install, then enable + systemctl daemon-reload + systemctl enable node_exporter.service + systemctl restart node_exporter.service + #Enable and restart apache for reverse proxy + systemctl enable httpd + systemctl restart httpd +fi + +%preun +%systemd_preun node_exporter.service + +%postun +%systemd_postun_with_restart node_exporter.service +if [ $1 -eq 0 ]; then + %selinux_unset_booleans -s %{selinuxtype} %{selinuxbooleans} +fi + +%files +%defattr(0644,perfsonar,perfsonar,0755) +%license LICENSE +%attr(0755, perfsonar, perfsonar) %{pkg_install_base}/exporter_opts.sh +%attr(0644, perfsonar, perfsonar) %{httpd_config_base}/apache-node_exporter.conf + +%changelog +* Tue Oct 24 2023 andy@es.net 5.0.5-0.0.a1 +- Initial package \ No newline at end of file diff --git a/unibuild-order b/unibuild-order index 73c538a..d3d0170 100644 --- a/unibuild-order +++ b/unibuild-order @@ -7,4 +7,5 @@ changecom()dnl # See the documentation at https://github.com/perfsonar/unibuild for # more information. # -prometheus-node-exporter \ No newline at end of file +prometheus-node-exporter +perfsonar-host-metrics \ No newline at end of file