Showing posts with label Container Monitoring. Show all posts
Showing posts with label Container Monitoring. Show all posts

Tuesday, August 8, 2023

How to run two different Grafana client agents on a single Linux host

Running two different Grafana client agents on a single Linux host with unique configuration files requires careful setup. Here's a step-by-step guide to achieving this, including creating two different users, one with sudo privileges and the other without.

Step 1: Create Two Users

First, create two users. One user will have sudo privileges, and the other will not.

For the user with sudo privileges:

sudo useradd grafana_sudo
sudo passwd grafana_sudo
sudo usermod -aG wheel grafana_sudo

For the user without sudo privileges:

sudo useradd grafana_nosudo
sudo passwd grafana_nosudo

Step 2: Install Grafana Agent

Download and install the Grafana Agent as per your system's architecture. You can follow the official Grafana Agent installation guide for detailed instructions.

Step 3: Create Unique Configuration Files

Create two different configuration files for the two Grafana Agents.

For the user with sudo privileges:

sudo mkdir /etc/grafana_sudo
sudo nano /etc/grafana_sudo/agent-config.yaml

For the user without sudo privileges:

sudo mkdir /etc/grafana_nosudo
sudo nano /etc/grafana_nosudo/agent-config.yaml

You can then add the specific configurations for each agent in these files.

Step 4: Create Systemd Service Files

Create two systemd service files to manage the Grafana Agents.

For the user with sudo privileges:

sudo nano /etc/systemd/system/grafana-agent-sudo.service

Add the following content:

[Unit]
Description=Grafana Agent (sudo)
After=network.target

[Service]
User=grafana_sudo
ExecStart=/usr/local/bin/agent-linux-amd64 -config.file /etc/grafana_sudo/agent-config.yaml

[Install]
WantedBy=multi-user.target

For the user without sudo privileges:

sudo nano /etc/systemd/system/grafana-agent-nosudo.service

Add the following content:

[Unit]
Description=Grafana Agent (no sudo)
After=network.target

[Service]
User=grafana_nosudo
ExecStart=/usr/local/bin/agent-linux-amd64 -config.file /etc/grafana_nosudo/agent-config.yaml

[Install]
WantedBy=multi-user.target

Step 5: Enable and Start the Services

Enable and start both services:

sudo systemctl enable grafana-agent-sudo
sudo systemctl start grafana-agent-sudo

sudo systemctl enable grafana-agent-nosudo
sudo systemctl start grafana-agent-nosudo

Now, you have two different Grafana client agents running on a single Linux host using unique configuration files, with one user having sudo privileges and the other not. You can monitor the status of both agents using:

sudo systemctl status grafana-agent-sudo
sudo systemctl status grafana-agent-nosudo

Make sure to replace the paths and filenames with the actual paths where the Grafana Agent binary and configuration files are located on your system.