Skip to content

Commit

Permalink
log-vm: Adding grafana services and storing logs in log-vm
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vunnyso committed May 10, 2024
1 parent 7d3b28a commit 1308dc7
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
39 changes: 39 additions & 0 deletions modules/common/log/promtail-agent.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{pkgs, ...}: let
server-ip-port = "192.168.101.66:3100";
in {
environment.etc."promtail-local-config.yaml".text = ''
server:
http_listen_port: 9101
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
client:
url: http://${server-ip-port}/loki/api/v1/push
scrape_configs:
- job_name: journal
journal:
path: /var/log/journal
labels:
job: systemd-journal
relabel_configs:
- source_labels: ['__journal__systemd_unit']
target_label: 'unit'
'';

systemd.services.promtail = {
description = "Service to upload journal logs";
enable = true;
after = ["network-online.target"];
serviceConfig = {
ExecStart = "${pkgs.grafana-loki}/bin/promtail -config.file=/etc/promtail-local-config.yaml";
Restart = "on-failure";
RestartSec = "1";
};
wantedBy = ["multi-user.target"];
};
}
1 change: 1 addition & 0 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
pkgs.waypipe
pkgs.networkmanagerapplet
pkgs.nm-launcher
pkgs.grafana-loki
]
++ (lib.optional (configHost.ghaf.profiles.debug.enable && configHost.ghaf.virtualization.microvm.idsvm.mitmproxy.enable) pkgs.mitmweb-ui);
};
Expand Down
27 changes: 26 additions & 1 deletion modules/microvm/virtualization/microvm/logvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
nixpkgs.buildPlatform.system = configHost.nixpkgs.buildPlatform.system;
nixpkgs.hostPlatform.system = configHost.nixpkgs.hostPlatform.system;

environment.systemPackages = lib.mkIf config.ghaf.profiles.debug.enable [];
networking = {
firewall.allowedTCPPorts = [3100];
};

environment.systemPackages = [pkgs.grafana-loki];

systemd.network = {
enable = true;
Expand All @@ -54,6 +58,20 @@
};
};

environment.etc."loki.yaml".source = ./loki-local-config.yaml;

systemd.services.loki = {
enable = true;
description = "Loki Service";
after = ["network-online.target"];
serviceConfig = {
ExecStart = "${pkgs.grafana-loki}/bin/loki -config.file=/etc/loki.yaml";
Restart = "on-failure";
RestartSec = "1";
};
wantedBy = ["multi-user.target"];
};

microvm = {
optimize.enable = true;
hypervisor = "cloud-hypervisor";
Expand All @@ -64,6 +82,13 @@
mountPoint = "/nix/.ro-store";
proto = "virtiofs";
}
{
# Creating a persistent log-store which is mapped on ghaf-host
tag = "log-store";
source = "/tmp/loki";
mountPoint = "/tmp/loki";
proto = "virtiofs";
}
];
writableStoreOverlay = lib.mkIf config.ghaf.development.debug.tools.enable "/nix/.rw-store";
};
Expand Down
39 changes: 39 additions & 0 deletions modules/microvm/virtualization/microvm/loki-local-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h

ruler:
alertmanager_url: http://localhost:9093
5 changes: 5 additions & 0 deletions targets/lenovo-x1/everything.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
self.nixosModules.disko-lenovo-x1-basic-v1
self.nixosModules.hw-lenovo-x1

# Import promtail agent for remote upload of journal logs
../../modules/common/log/promtail-agent.nix

({
pkgs,
config,
Expand All @@ -57,6 +60,8 @@

disko.devices.disk = config.ghaf.hardware.definition.disks;

environment.systemPackages = [pkgs.grafana-loki];

ghaf = {
# Hardware definitions
hardware.x86_64.common.enable = true;
Expand Down
2 changes: 2 additions & 0 deletions targets/lenovo-x1/guivmExtraModules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,7 @@ in
guivmPCIPassthroughModule
guivmVirtioInputHostEvdevModule
guivmExtraConfigurations
# Import promtail agent for remote upload of journal logs
../../modules/common/log/promtail-agent.nix
]
++ lib.optionals configH.ghaf.hardware.fprint.enable [configH.ghaf.hardware.fprint.extraConfigurations]

0 comments on commit 1308dc7

Please sign in to comment.