-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAT-14495] Set up the node_exporter for ynp
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
Showing
6 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
7 changes: 7 additions & 0 deletions
7
managed/node-agent/resources/ynp/modules/provision/node_exporter/node_exporter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
10 changes: 10 additions & 0 deletions
10
...e-agent/resources/ynp/modules/provision/node_exporter/templates/node_exporter_precheck.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
62 changes: 62 additions & 0 deletions
62
...d/node-agent/resources/ynp/modules/provision/node_exporter/templates/node_exporter_run.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |