Skip to main content
Glama

system_logs

Read system logs from journalctl or log files to monitor infrastructure services and troubleshoot issues in Kubernetes, Docker, and other systems.

Instructions

Read system logs from journalctl or a log file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
unitNoSystemd unit name (e.g., 'nginx', 'docker')
linesNoNumber of lines to show (default: 50)
pathNoPath to a log file (alternative to journalctl)

Implementation Reference

  • The handler implementation for the 'system_logs' tool. It either reads a local file or queries journalctl.
    export async function systemLogs(args: Record<string, unknown>): Promise<string> {
      const unit = args.unit as string | undefined;
      const lines = (args.lines as number) || 50;
      const path = args.path as string | undefined;
    
      // If a file path is given, read from file
      if (path) {
        try {
          const content = await readFile(path, "utf-8");
          const allLines = content.trim().split("\n");
          const lastN = allLines.slice(-lines);
          return `Logs from '${path}' (last ${lastN.length} lines):\n\n${lastN.join("\n")}`;
        } catch (error: any) {
          throw new Error(`Failed to read log file: ${error.message}`);
        }
      }
    
      // Otherwise use journalctl
      try {
        const jArgs = ["--no-pager", `-n${lines}`];
        if (unit) jArgs.push("-u", unit);
    
        const { stdout } = await execFileAsync("journalctl", jArgs, { timeout: 15000 });
        return `System logs${unit ? ` (${unit})` : ""} (last ${lines} lines):\n\n${stdout.trim()}`;
      } catch (error: any) {
        throw new Error(`Failed to read system logs: ${error.message}`);
      }
    }
  • Schema definition for 'system_logs' tool.
      name: "system_logs",
      description: "Read system logs from journalctl or a log file",
      inputSchema: {
        type: "object" as const,
        properties: {
          unit: { type: "string", description: "Systemd unit name (e.g., 'nginx', 'docker')" },
          lines: { type: "number", description: "Number of lines to show (default: 50)" },
          path: { type: "string", description: "Path to a log file (alternative to journalctl)" },
        },
      },
    },
  • Routing of the 'system_logs' tool in handleSystemTool.
    case "system_logs": return systemLogs(a);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batu-sonmez/infraclaude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server