Skip to content

Commit

Permalink
[PLAT-14495] Set up the node_exporter for ynp
Browse files Browse the repository at this point in the history
Summary: Configure node_exporter module for ynp

Test Plan:
Manually tried provisioing node via YNP. Verified node_exporter is running post the
script execution.

Reviewers: anijhawan, nbhatia

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36115
  • Loading branch information
Vars-07 committed Jun 26, 2024
1 parent c2e13ef commit 34632ba
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions managed/node-agent/resources/ynp/configs/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ locks = unlimited
[InstallNodeAgent]
{{ render_section(yba) -}}
yb_user = {{ ynp.yb_user }}

[ConfigureNodeExporter]
prometheus_user = prometheus
yb_home_dir = {{ ynp.yb_home_dir }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ airgap_flag=""
{% endif %}

installer_dir="{{ ynp_dir }}/../../bin"
sudo su - {{ yb_user }} -c "\"$installer_dir/node-agent-installer.sh\" -c install -u {{ url }} -t {{ api_key }} --provider_id {{ provider_id }} --instance_type {{ instance_type_name }} --zone_name {{ provider_region_zone_name }} --node_name {{ node_name }} --node_ip {{ node_ip }} --silent --skip_verify_cert $airgap_flag"
su - {{ yb_user }} -c "\"$installer_dir/node-agent-installer.sh\" -c install -u {{ url }} -t {{ api_key }} --provider_id {{ provider_id }} --instance_type {{ instance_type_name }} --zone_name {{ provider_region_zone_name }} --node_name {{ node_name }} --node_ip {{ node_ip }} --silent --skip_verify_cert $airgap_flag"

# install node_agent service
"$installer_dir/node-agent-installer.sh" -c install_service --user yugabyte
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ...base_module import BaseYnpModule


class ConfigureNodeExporter(BaseYnpModule):

run_template = "node_exporter_run.j2"
precheck_template = "node_exporter_precheck.j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
service_name="node_exporter.service"

# Get the status of node_exporter Service
status=$(systemctl show -p ActiveState "$service_name" | grep ActiveState | awk -F= '{print $2}')
if [ "$status" = "active" ]; then
echo "\"$service_name\" is active"
else
echo "\"$service_name\" is not active"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
thirdparty_dir="{{ ynp_dir }}/../../thirdparty"

# Setup the directories & permissions for prometheus user
mkdir -p /opt/prometheus
mkdir -p /etc/prometheus
mkdir -p /var/log/prometheus
mkdir -p /var/run/prometheus
mkdir -p /tmp/yugabyte/metrics

if [ -f "$thirdparty_dir/node_exporter-1.7.0.linux-amd64.tar.gz" ]; then
mv "$thirdparty_dir/node_exporter-1.7.0.linux-amd64.tar.gz" /opt/prometheus
fi

# Check if the user "prometheus" already exists
if ! id -u prometheus >/dev/null 2>&1; then
adduser --shell /bin/bash prometheus
fi

# Set ownership and permissions
chown -R prometheus:prometheus /opt/prometheus
chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /var/log/prometheus
chown -R prometheus:prometheus /var/run/prometheus
chown -R yugabyte:yugabyte /tmp/yugabyte/metrics
chmod -R 755 /tmp/yugabyte/metrics

if [ -f /opt/prometheus/node_exporter-1.7.0.linux-amd64.tar.gz ]; then
chmod +r /opt/prometheus/node_exporter-1.7.0.linux-amd64.tar.gz

# Extract the node_exporter tarball
su - {{ prometheus_user }} -c "cd /opt/prometheus && tar zxf node_exporter-1.7.0.linux-amd64.tar.gz"
fi

# Configure Systemd Unit
file_path="/etc/systemd/system/node_exporter.service"

# Create the file and write the content
cat <<EOL > $file_path
[Unit]
Description=node_exporter - Exporter for machine metrics.
Documentation=https://github.com/William-Yeh/ansible-prometheus
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
Restart=on-failure

User=prometheus
Group=prometheus

ExecStart=/opt/prometheus/node_exporter-1.7.0.linux-amd64/node_exporter --web.listen-address=:9300 --collector.textfile.directory={{ yb_home_dir }}/metrics
EOL

# Enable and start the node_exporter service
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter

echo "Node exporter setup is complete."

0 comments on commit 34632ba

Please sign in to comment.