Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log-vm: To centralize logs using grafana promtail & loki #594

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vunnyso
Copy link
Contributor

@vunnyso vunnyso commented May 8, 2024

Description of changes

Checklist for things done

  • Summary of the proposed changes in the PR description
  • More detailed description in the commit message(s)
  • Commits are squashed into relevant entities - avoid a lot of minimal dev time commits in the PR
  • Contribution guidelines followed
  • Ghaf documentation updated with the commit - https://tiiuae.github.io/ghaf/
  • PR linked to architecture documentation and requirement(s) (ticket id)
  • Test procedure described (or includes tests). Select one or more:
    • Tested on Lenovo X1 x86_64
    • Tested on Jetson Orin NX or AGX aarch64
    • Tested on Polarfire riscv64
  • Author has run nix flake check --accept-flake-config and it passes
  • All automatic Github Action checks pass - see actions
  • Author has added reviewers and removed PR draft status

Testing

To view logs in locally on ghaf target machine

ssh into log-vm and use logcli to view systemd journal logs

[ghaf@ghaf-host:~]$ ssh 192.168.101.66

[ghaf@log-vm:~]$ logcli query '{job="systemd-journal"}'

[ghaf@log-vm:~]$ logcli query '{hostname="ghaf-host"}'

To view logs in grafana GUI on remote server/ dev machine.

  1. Move to dev machine / machine where you want to install grafana
    To install grafana on NixOS you can follow mentioned guide here

Example:

services.grafana = {
  enable   = true;
  settings = {
    server = {
      http_addr = "<your_local_network_grafana_instance_ip_address_here>";
      domain = "localdomain";
      http_port = 3000;
      protocol = "http";
    };
  };

  dataDir  = "/var/lib/grafana";
};
  1. Make sure you have connected to WIFI using nm-launcher on ghaf target machine.

  2. Run the below command to add loki data source, replace with netvm-wifi-ip-address with yours IP.
    [ghaf@log-vm:~]$ curl 'http://admin:admin@<grafana_ip_in_your_local_network>:3000/api/datasources'
    -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"loki","type":"loki","url":"http://<net-vm_wifi_ip_address>:3100","access":"proxy","isDefault":true,"database":"tsdb"}'

  3. Go to browser where you want to view the logs and type following address http://<grafana_ip_in_your_local_network>:3000/explore
    Follow below steps in order to view logs/download logs.

image

Also there is way to filter out logs based on hostName as in example below:
image

Next Steps

  1. Build Grafana alloy nix package
  2. Change from promtail agent to alloy

vilvo and others added 3 commits May 10, 2024 12:32
* Design https://ssrc.atlassian.net/wiki/x/GYA4Pw
* log-vm scaffolding based on copy of net-vm
  - sets up systemd-journal-remote on default port 19532

Signed-off-by: Ville Ilvonen <ville.ilvonen@unikie.com>
Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
This patch will add promtail-agent service in `ghaf-host`
and `gui-vm`. Also add loki service in log-vm.

Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
@vunnyso vunnyso temporarily deployed to internal-build-workflow May 13, 2024 13:39 — with GitHub Actions Inactive
@vilvo
Copy link
Contributor

vilvo commented May 14, 2024

Better link testing instructions for grafana installation to https://nixos.wiki/wiki/Grafana instead of https://community.grafana.com/t/installing-on-nixos/6712
The latter link is from 2018 and many nixos grafana settings have been changed - for example

trace: warning: The option `services.grafana.domain' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.domain'.
trace: warning: The option `services.grafana.port' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.http_port'.
trace: warning: The option `services.grafana.protocol' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.protocol'.

I got grafana running with:

networking.firewall.allowedTCPPorts = [ 3000 ];
services.grafana = {
  enable   = true;
  settings = {
    server = {
      http_addr = "<your_local_network_grafana_instance_ip_address_here>";
      domain = "localdomain";
      http_port = 3000;
      protocol = "http";
    };
  };

  dataDir  = "/var/lib/grafana";
};

@vunnyso vunnyso temporarily deployed to internal-build-workflow May 14, 2024 09:24 — with GitHub Actions Inactive
This patch adds hostName as parameter in promtail agent
so that we can distinguish from which machine or vm logs
are coming.

Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
@vunnyso
Copy link
Contributor Author

vunnyso commented May 14, 2024

Better link testing instructions for grafana installation to https://nixos.wiki/wiki/Grafana instead of https://community.grafana.com/t/installing-on-nixos/6712 The latter link is from 2018 and many nixos grafana settings have been changed - for example

trace: warning: The option `services.grafana.domain' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.domain'.
trace: warning: The option `services.grafana.port' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.http_port'.
trace: warning: The option `services.grafana.protocol' defined in `/nix/store/mzgmjayar7pm38x46yxhf27q4jv11zmp-source/hosts/nixos/carrie/configuration.nix' has been renamed to `services.grafana.settings.server.protocol'.

I got grafana running with:

networking.firewall.allowedTCPPorts = [ 3000 ];
services.grafana = {
  enable   = true;
  settings = {
    server = {
      http_addr = "<your_local_network_grafana_instance_ip_address_here>";
      domain = "localdomain";
      http_port = 3000;
      protocol = "http";
    };
  };

  dataDir  = "/var/lib/grafana";
};

Thanks @vilvo for details, I have updated Testing section accordingly.

@vilvo
Copy link
Contributor

vilvo commented May 14, 2024

Also, please change step 3. in Testing section instructions to:

[ghaf@log-vm:~]$ curl 'http://admin:admin@<grafana_ip_in_your_local_network>:3000/api/datasources'
-X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"loki","type":"loki","url":"http://<net-vm_wifi_ip_address>:3100","access":"proxy","isDefault":true,"database":"tsdb"}'

As of now, it's unclear where the tester is expected to run the command. Also, it's better use grafana instance ip address instead of localhost. Tested it to work that way. Also, the ghaf logs filtering based on the ghaf hostname works fine 👍🏻

@vunnyso vunnyso changed the title log-vm: To centralize logs using grafana log-vm: To centralize logs using grafana promtail & loki May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants