Shrec:a Sre Behaviour Knowledge Graph Model for Shell Command Recommendations

Andrea Tonon, Bora Caglayan, Mingxue Wang, Peng Hu, Fei Shen, Puchao Zhang · DOI

Abstract

In IT system operations, shell commands are common command line tools used by site reliability engineers (SREs) for daily tasks, such as system configuration, package deployment, and performance optimization. The efficiency in their execution has a crucial business impact since shell commands very often aim to execute critical operations, such as the resolution of system faults. However, many shell commands involve long parameters that make them hard to remember and type. Additionally, the experience and knowledge of SREs using these commands are almost always not preserved. In this work, we propose SHREC, a SRE behaviour knowledge graph model for shell command recommendations. We model the SRE shell behaviour knowledge as a knowledge graph and propose a strategy to directly extract such a knowledge from SRE historical shell operations. The knowledge graph is then used to provide shell command recommendations in real-time to improve the SRE operation efficiency. Our empirical study based on real shell commands executed in our company demonstrates that Shrec can improve the SRE operation efficiency, allowing to share and re-utilize the SRE knowledge.

Introduction

Site Reliability Engineering (SRE) is a high-stakes field where speed and accuracy are paramount. When a system fails, SREs must execute shell commands to diagnose and fix the issue. However, these commands are often long, complex, and difficult to memorize. SHREC is a recommendation system designed to boost the efficiency of SREs by mining historical shell logs to build a "Behaviour Knowledge Graph." Unlike standard autocomplete, SHREC suggests complex, multi-parameter commands and entire operational sequences in real-time, significantly reducing the cognitive load and typing errors associated with critical system maintenance.

The authors identify three major pain points in current SRE workflows:

  1. Complexity: Shell commands frequently involve intricate parameters and long file paths that are prone to typos.
  2. Knowledge Loss: The "tribal knowledge" of experienced SREs—such as which sequence of commands is best for troubleshooting a specific service—is rarely preserved or shared systematically.
  3. Inefficiency: Erroneous commands often precede the correct one. As shown in Figure 1, a less experienced SRE might take over three minutes and twelve failed attempts just to execute a single correct command.
Figure 1: Example of inefficient shell command execution due to complexity and typos.

Methodology

The SHREC framework consists of a multi-stage pipeline designed to turn raw shell logs into actionable recommendations:

  1. Extraction & Parsing: Raw logs are cleaned to remove syntax errors and "non-crucial" commands (like repetitive cd calls). Relative paths are converted to absolute paths to reduce data sparsity.
  2. Sequential Pattern Mining (SPM): Using the SPAM algorithm, the system identifies frequent sequences of commands that represent useful operational workflows (e.g., checking a config, stopping a service, and restarting it).
  3. Behaviour Aggregation: Similar sequences are clustered using Jaccard distance, and "macros" are defined to summarize these operations.
  4. Intent Definition: Commands are classified into eight high-level intents (e.g., log_analysis, network_analysis) based on predefined rules.
  5. Knowledge Graph Modeling: Data is structured into a graph with eight vertex types: Scope, User, IP, Path, File, Command, Sequence, and Intent. This allows the system to understand the context—who is typing, on which server, and within which business service.
  6. Recommendation Engine: When an SRE starts typing, SHREC uses a scoring function to rank candidates. This function considers string similarity (using the Dice coefficient), user-specific history, and the frequency of the command within the current "scope" (business system).
Figure 5: The SHREC framework architecture for extracting and recommending shell commands.

Evaluation and Results

The researchers evaluated SHREC using real-world data from their own company, consisting of one month of historical shell commands. The dataset included 29,859 sessions involving 607 users across 58 different business scopes. The processed data yielded 18,524 unique commands and 3,997 frequent sequences ranging from 2 to 14 commands in length.

The empirical study demonstrated significant efficiency gains:

  • Reduced Typing: Users saw a 43% reduction in the number of command lines they needed to type manually.
  • Character Savings: For commands involving file paths, the number of characters to type dropped by 72.5%.
  • Workflow Acceleration: When executing multi-command sequences, the system provided a 57% reduction in manual input.
  • Performance: The system is fast enough for production use, with command recommendations appearing in <200ms and sequence suggestions in <300ms.

Discussion

A key insight of SHREC is that context is king. Recommendations are "scoped," ensuring suggestions are contextually appropriate for the specific business service. Furthermore, by focusing on sequences over singletons, SHREC acknowledges that most SRE tasks are workflows. This automated knowledge capture effectively "downloads" the expertise of senior engineers, making it available to the entire team.

However, the system faces a "cold start" problem; it relies on historical data and may struggle with entirely new services. Future work could involve using Natural Language Processing (NLP) to automatically infer intent or integrating real-time feedback loops to refine the Knowledge Graph based on user acceptance of recommendations.

Summary updated

BibTeX
@misc{tonon2024shrec,
  author = {Andrea Tonon and Bora Caglayan and Mingxue Wang and Peng Hu and Fei Shen and Puchao Zhang},
  title = {{Shrec:a Sre Behaviour Knowledge Graph Model for Shell Command Recommendations}},
  year = {2024},
  eprint = {2408.05592},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.05592},
}
Figure