How to Integrate Linux Server for Grafana Cloud


In this article, we will learn how to seamlessly integrate Linux servers with Grafana Cloud. Grafana Cloud offers powerful monitoring and visualization capabilities for your infrastructure, enabling you to gain insights into the performance and health of your systems. Integrating Linux servers with Grafana Cloud allows you to collect metrics, logs, and traces from your servers and visualize them in customizable dashboards.

Prerequisites

  • AWS Account with Ubuntu 22.04 LTS EC2 Instance.
  • Basic knowledge of AWS services and Grafana.
  • Grafana Cloud account.

Create a Grafana Cloud Account by following the official documentation

Create Grafana Cloud Account

Step #1:Install Grafana Agent on Ubuntu

The Grafana Agent is a lightweight, open-source agent that collects metrics, logs, and traces from your Linux servers and sends them to Grafana Cloud.

So first create the directory for the apt keyrings

sudo mkdir -p /etc/apt/keyrings/
How to Integrate Linux Server for Grafana Cloud 1

Download and import the Grafana GPG key using following command.

wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
How to Integrate Linux Server for Grafana Cloud 2

Add Grafana package repository using following command.

echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
How to Integrate Linux Server for Grafana Cloud 3

Update the repositories

sudo apt-get update
How to Integrate Linux Server for Grafana Cloud 4

After updating the repository. Install the Grafana Agent

sudo apt-get install grafana-agent
How to Integrate Linux Server for Grafana Cloud 5

Start the grafana agent by running the following command

sudo systemctl start grafana-agent
How to Integrate Linux Server for Grafana Cloud 6

After this enable the grafana agent

sudo systemctl enable grafana-agent
How to Integrate Linux Server for Grafana Cloud 7

You can check if its running properly or not by running the following command.

sudo systemctl status grafana-agent
How to Integrate Linux Server for Grafana Cloud 8

Step #2:Install Linux Server Integration for Grafana Cloud

First Login to Grafana Cloud and launch the Grafana instance.

How to Integrate Linux Server for Grafana Cloud 9

then select the Connections > Add new connections from the home bar.

How to Integrate Linux Server for Grafana Cloud 10

Select the Linux Server

How to Integrate Linux Server for Grafana Cloud 11

Click on Grafana agent and choose the operating system on which your linux server is running. Then click on Create a new API token or you can use an existing on if you have, give the Access policy token name and click on create token.

This will generate API token which we will use to set up the grafana agent.

How to Integrate Linux Server for Grafana Cloud 12

Copy the code run it to install and run grafana agent as a grafana-agent.service systemd service.

Put the API token key generated before instead of “GCLOUD_RW_API_KEY

How to Integrate Linux Server for Grafana Cloud 13
How to Integrate Linux Server for Grafana Cloud 14

Step #3:Modify the Grafana agent yaml file

Now go back to the grafana cloud and scroll down.

In prepare your configuration file give the value for hostname. Here I’ve given monitoring-node

How to Integrate Linux Server for Grafana Cloud 15

go to the /etc/grafana-agent.yaml by using following command.

sudo nano /etc/grafana-agent.yaml
How to Integrate Linux Server for Grafana Cloud 16

Then copy the Integration and logs code lines from the grafana cloud and insert it in /etc/grafana-agent.yaml file according to your environment.

How to Integrate Linux Server for Grafana Cloud 17
How to Integrate Linux Server for Grafana Cloud 18
                                                                                                                                                                                   integrations:
  prometheus_remote_write:
  - basic_auth:
      password: glc_eyJvIjoiMTA5MTQwNCIsIm4iOiJzdGFjay04OTY4MzAtaW50ZWdyYXRpb24tcHJhc2FkLTQwIiwiayI6Ik8xMjUzcjd1SDdiZTY2QTZUSmlhbzZZaSIsIm0iOnsiciI6InByb2QtYXAtc291dGgtMSJ9fQ==
      username: 1507447
    url: https://prometheus-prod-43-prod-ap-south-1.grafana.net/api/prom/push
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  node_exporter:
    enabled: true
    # disable unused collectors
    disable_collectors:
      - ipvs #high cardinality on kubelet
      - btrfs
      - infiniband
      - xfs
      - zfs
    # exclude dynamic interfaces
    netclass_ignored_devices: "^(veth.*|cali.*|[a-f0-9]{15})$"
    netdev_device_exclude: "^(veth.*|cali.*|[a-f0-9]{15})$"
    # disable tmpfs
    filesystem_fs_types_exclude: "^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|tmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$"
    # drop extensive scrape statistics
    relabel_configs:
    - replacement: 'monitoring-node'
      target_label: instance
    metric_relabel_configs:
    - action: drop
      regex: node_scrape_collector_.+
      source_labels:
      - __name__
    - action: keep
      regex: node_arp_entries|node_boot_time_seconds|node_context_switches_total|node_cpu_seconds_total|node_disk_io_time_seconds_total|node_disk_io_time_weighted_seconds_total|node_disk_read_bytes_total|node_disk_read_time_seconds_total|node_disk_reads_completed_total|node_disk_write_time_seconds_total|node_disk_writes_completed_total|node_disk_written_bytes_total|node_filefd_allocated|node_filefd_maximum|node_filesystem_avail_bytes|node_filesystem_device_error|node_filesystem_files|node_filesystem_files_free|node_files>
      source_labels:
      - __name__

logs:
  configs:
  - clients:
    - basic_auth:
        password: glc_eyJvIjoiMTA5MTQwNCIsIm4iOiJzdGFjay04OTY4MzAtaW50ZWdyYXRpb24tcHJhc2FkLTQwIiwiayI6Ik8xMjUzcjd1SDdiZTY2QTZUSmlhbzZZaSIsIm0iOnsiciI6InByb2QtYXAtc291dGgtMSJ9fQ==
        username: 854611
      url: https://logs-prod-028.grafana.net/loki/api/v1/push
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/node_exporter_journal_scrape
      journal:
        max_age: 24h
        labels:
          instance: 'monitoring-node'
          job: integrations/node_exporter
      relabel_configs:
      - source_labels: ['__journal__systemd_unit']
        target_label: 'unit'
      - source_labels: ['__journal__boot_id']
        target_label: 'boot_id'
      - source_labels: ['__journal__transport']
        target_label: 'transport'
      - source_labels: ['__journal_priority_keyword']
        target_label: 'level'
    - job_name: integrations/node_exporter_direct_scrape
      static_configs:
      - targets:
        - localhost
        labels:
          instance: 'monitoring-node'
          __path__: /var/log/{syslog,messages,*.log}
          job: integrations/node_exporter

metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: glc_eyJvIjoiMTA5MTQwNCIsIm4iOiJzdGFjay04OTY4MzAtaW50ZWdyYXRpb24tcHJhc2FkLTQwIiwiayI6Ik8xMjUzcjd1SDdiZTY2QTZUSmlhbzZZaSIsIm0iOnsiciI6InByb2QtYXAtc291dGgtMSJ9fQ==
        username: 1507447
      url: https://prometheus-prod-43-prod-ap-south-1.grafana.net/api/prom/push
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

save the file and restart the grafana agent service

systemctl restart grafana-agent.service

Give the password to authenticate.

How to Integrate Linux Server for Grafana Cloud 19

If you don’t know the password you can change it using following commanad.

sudo passwd ubuntu

scroll down and click on Test connections to test that the agent is collecting data and sending it to Grafana Cloud.

You will get the message “The agent is now collecting data from your machine.

How to Integrate Linux Server for Grafana Cloud 20

Step #4:Install Dashboards and alerts on Grafana Cloud

Next click on Install to install the pre-configured dashboards and alerts.

How to Integrate Linux Server for Grafana Cloud 21

Now click on View Dashboards.

How to Integrate Linux Server for Grafana Cloud 22

You will see the many pre-build dashboards installed. For now we will select

Linux node/overviewDashboard.

How to Integrate Linux Server for Grafana Cloud 23

The dashboard displays various graphs and metrics which are related to server performance.

Like CPU usage, memory usage, network traffice and many more.

How to Integrate Linux Server for Grafana Cloud 24

Conclusion:

Integrating Linux servers with Grafana Cloud provides valuable insights into the performance and health of your infrastructure. You can seamlessly integrate Linux server with Grafana Cloud. By following the steps outlined in this guide, you can easily set up monitoring and visualization for your Linux servers and gain visibility into their operation. Whether you’re managing a single server or a large-scale deployment, Grafana Cloud offers the tools you need to monitor and optimize your infrastructure effectively.

Related Articles:

How to Create Account in Grafana Cloud

Reference:

Grafana Cloud official page

Prasad Hole

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap