Configuring the Grafana agent
This page explains how to configure the Grafana agent to push your logs and metrics and visualize them in Grafana.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console
- You have activated your Cockpit
- You have installed docker and docker compose
Configuring and running the Grafana agent
It is not currently possible to collect logs if you are using OSX.
-
Create a token and select the push permission for metrics and logs.
-
Create a folder where you will keep your configuration files.
-
Create a configuration file inside your folder and name it
config.yaml
. This file will contain the Grafana agent configuration. -
Copy the following yaml template.
Important:- Make sure you replace the
remote_write
URL withhttps://metrics.cockpit.fr-par.scw.cloud/api/v1/push
and theclients
URL withhttps://logs.cockpit.fr-par.scw.cloud/loki/api/v1/push
- Make sure you add the token you created in step 2
metrics:wal_directory: /tmp/agentglobal:scrape_interval: 60sremote_write:- url: <your metrics push url>headers:"X-Token": <your push token>logs:positions_directory: /tmp/positions/configs:- name: scwclients:- url: <your logs push url>tenant_id: <your push token>scrape_configs:- job_name: varlogsstatic_configs:- targets: [localhost]labels:job: varlogs__path__: /host/root/var/log/*.logintegrations:node_exporter:enabled: truerootfs_path: /host/rootsysfs_path: /host/sysprocfs_path: /host/procYour configuration file should look like the following:
metrics:wal_directory: /tmp/agentglobal:scrape_interval: 60sremote_write:- url: https://metrics.cockpit.fr-par.scw.cloud/api/v1/pushheaders:"X-Token": 4zz-3cGLS5tzuDRb6LkEdpem7eOqj8EFecfWcJmTvrakS15gu07iEvtC5RfYDzi8logs:positions_directory: /tmp/positions/configs:- name: scwclients:- url: https://logs.cockpit.fr-par.scw.cloud/loki/api/v1/pushtenant_id: 4zz-3cGLS5tzuDRb6LkEdpem7eOqj8EFecfWcJmTvrakS15gu07iEvtC5RfYDzi8scrape_configs:- job_name: varlogsstatic_configs:- targets: [localhost]labels:job: varlogs__path__: /host/root/var/log/*.logintegrations:node_exporter:enabled: truerootfs_path: /host/rootsysfs_path: /host/sysprocfs_path: /host/proc - Make sure you replace the
-
In the same folder, create another file and name it
docker-compose.yaml
. -
Copy the following template and paste it into your file:
version: "3"services:agent:image: grafana/agent:latestrestart: alwaysvolumes:- "./config.yaml:/etc/agent-config/agent.yaml:ro"- "/:/host/root:ro"- "/sys:/host/sys:ro"- "/proc:/host/proc:ro"- "/tmp/agent:/etc/agent"entrypoint:- /bin/grafana-agent- -config.file=/etc/agent-config/agent.yaml- -metrics.wal-directory=/tmp/agent/walnetwork_mode: "host"pid: "host" -
Run the following command to open your folder containing your configuration files:
cd <your folder> -
Run the following command to bring the Grafana Agent container up:
docker compose upImportant:Run
sudo docker compose up
if you are using Linux and your user is not in the docker group.
Visualizing metrics on Grafana
- Log into Grafana using your Grafana credentials.
- Click the Dashboards icon, then click Browse.
- Click New on the top right corner of your screen then click Import to import your Grafana dashboard.
- Enter
1860
, which is the ID of the Node Exporter Full dashboard, in the ID field and click Load. - Select the Scaleway Metrics Prometheus instance as the data source and click Import. Your dashboard displays with your metrics.
Visualizing logs on Grafana
- Log into Grafana using your Grafana credentials.
- Click the Compass icon.
- Click Explore.
- Select the Scaleway Logs data source on the top left corner of your screen.
- Click Log browser.
- Select your labels and their values using the instructions on your screen.
- Click Show logs. A new screen display with your logs.
- Optionally, click the Live button on the top right corner of your screen to see your logs arriving in real time.