Update grafana stack install script.

This commit is contained in:
Oliver Gwyther 2025-02-28 20:07:58 +00:00
parent b94b7b0c64
commit 059a09992a

View File

@ -47,11 +47,8 @@ function install_prometheus() {
echo "Copying Prometheus binary to $PROMETHEUS_DIR..."
cp prometheus-$PROMETHEUS_VERSION.linux-amd64/prometheus $PROMETHEUS_DIR
echo "Copying promtool to /usr/local/bin..."
cp prometheus-$PROMETHEUS_VERSION.linux-amd64/promtool /usr/local/bin/
echo "Creating necessary directories for Prometheus data and config..."
mkdir -p $CONFIG_DIR $DATA_DIR
echo "Copying promtool binary to /usr/local/bin"
sudo cp prometheus-$PROMETHEUS_VERSION.linux-amd64/promtool /usr/local/bin
echo "Creating Prometheus configuration file in $CONFIG_DIR..."
cat <<EOF > $CONFIG_DIR/prometheus.yml
@ -69,16 +66,16 @@ scrape_configs:
EOF
echo "Creating $PROMETHEUS_USER user and group..."
groupadd --system $PROMETHEUS_GROUP
useradd -s /sbin/nologin --system -g $PROMETHEUS_GROUP $PROMETHEUS_USER
sudo groupadd --system $PROMETHEUS_GROUP
sudo useradd -s /sbin/nologin --system -g $PROMETHEUS_GROUP $PROMETHEUS_USER
echo "Setting ownership of directories and files..."
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP $CONFIG_DIR $DATA_DIR
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/prometheus
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/node_exporter
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP $CONFIG_DIR $DATA_DIR
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/prometheus
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/node_exporter
echo "Creating systemd service for Prometheus..."
cat <<EOF > /etc/systemd/system/prometheus.service
cat <<EOF | sudo tee /etc/systemd/system/prometheus.service > /dev/null
[Unit]
Description=Prometheus Time Series Database
Wants=network-online.target
@ -98,11 +95,11 @@ WantedBy=default.target
EOF
echo "Reloading systemd daemon..."
systemctl daemon-reload
sudo systemctl daemon-reload
echo "Enabling Prometheus service..."
systemctl enable prometheus.service
sudo systemctl enable prometheus.service
echo "Starting Prometheus service..."
systemctl start prometheus.service
sudo systemctl start prometheus.service
echo "Checking status of Prometheus service..."
systemctl status prometheus.service
}
@ -129,10 +126,10 @@ function install_node_exporter() {
tar xvfz node_exporter-$NODE_EXPORTER_VERSION.linux-amd64.tar.gz
echo "Copying Node Exporter binary to $BINARY_DIR..."
cp node_exporter-$NODE_EXPORTER_VERSION.linux-amd64/node_exporter $BINARY_DIR
sudo cp node_exporter-$NODE_EXPORTER_VERSION.linux-amd64/node_exporter $BINARY_DIR
echo "Creating systemd service for Node Exporter..."
cat <<EOF > /etc/systemd/system/node_exporter.service
cat <<EOF | sudo tee /etc/systemd/system/node_exporter.service > /dev/null
[Unit]
Description=Node Exporter
Wants=network-online.target
@ -150,11 +147,11 @@ WantedBy=default.target
EOF
echo "Reloading systemd daemon..."
systemctl daemon-reload
sudo systemctl daemon-reload
echo "Enabling Node Exporter service..."
systemctl enable node_exporter.service
sudo systemctl enable node_exporter.service
echo "Starting Node Exporter service..."
systemctl start node_exporter.service
sudo systemctl start node_exporter.service
echo "Checking status of Node Exporter service..."
systemctl status node_exporter.service
}
@ -180,9 +177,12 @@ function install_grafana() {
echo "Starting Grafana service..."
sudo systemctl start grafana-server
echo "Checking status of Grafana service..."
sudo systemctl status grafana-server
systemctl status grafana-server
}
# Prompt for sudo password and validate it
sudo -v
# Main script execution
show_menu