Frontend pages for utu-agent exp_analysis
This section is designed for viewing log data generated by the evaluation module. To use this feature, you must first run the evaluation code. Otherwise, no specific information will be displayed on the page. To run the evaluation, see Preconditions section.
For instructions on what is the evaluation, please refer to the following link: Youtu-agent_Evaluation.
Before running the evaluation section, you need to configure the environment variables and ensure that the value of the UTU_DB_URL when running evaluation is the same as when running exp_analysis. For how to configure and check env, please refer to the Set env of log sql server section.
After configuring the environment variables, you can refer to the Run evaluations section to run the evaluations example. You can follow this example to run your own data later.
At this point, you can continue running the code in the exp_analysis.
This step is mainly to obtain the database configuration, because the code needs to access the database service.
First, ensure that a .env file exists in the youtu-agent root directory. If not, refer to the Sync Dependencies section in the source-code-deployment section to configure the .env file.
Then you can run the following command to verify that the environment variables have been set successfully:
echo ${UTU_DB_URL}Note: If the output is empty or contains an incorrect value, check that the UTU_DB_URL variable exists in the .env file and that .env has been sourced. Run the following code to source the environment:
source .env
The following describes two common methods for installing and using the database.
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured SQL database engine. It is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.
Key Characteristics:
- Serverless: No separate server process to install or configure.
- Self-Contained: Requires minimal external support from the operating system or libraries.
- Zero-Configuration: No setup or administration needed.
- Transactional: Fully ACID-compliant, even in the event of system crashes or power failures.
- Single File Database: An entire database is stored in a single cross-platform disk file.
To interact with SQLite databases via the command line, you need the sqlite3 CLI tool.
-
Windows:
- Download the precompiled binaries for Windows from the SQLite Download Page.
- Download
sqlite-tools-win32-*.zip. - Extract the ZIP file. You will get an
sqlite3.exefile. You can run it directly from the extracted folder.
-
macOS: SQLite is pre-installed on macOS. Open a terminal and simply run:
sqlite3- Linux (Ubuntu/Debian): Install it using the package manager:
sudo apt update && sudo apt install sqlite3Basic CLI Commands:
# Open a database file (creates it if it doesn't exist)
sqlite3 my_database.db
# Inside the SQLite prompt, you can run SQL commands
sqlite> .tables -- List all tables
sqlite> .schema -- Show the schema of all tables
sqlite> .schema table_name -- Show the schema of a specific table
sqlite> .mode column -- Set output mode for better readability
sqlite> .headers on -- Turn on column headers
sqlite> .help -- Show all available commands
sqlite> .exit -- Exit the CLIThen you can configure it in env file like this:
UTU_DB_URL=sqlite:///your_db_filePostgreSQL, often simply called "Postgres", is a powerful, open-source object-relational database system with over 35 years of active development. It has earned a strong reputation for its proven architecture, reliability, data integrity, robust feature set, and performance.
Key Characteristics:
- Client-Server Model: Requires a running server process (
postmaster) that manages database files and accepts connections from client applications. - Highly Extensible: Supports custom functions, data types, operators, and more.
- Standards-Compliant: Highly compliant with SQL standards.
- Advanced Features: Supports complex queries, foreign keys, triggers, updatable views, transactional integrity, and multi-version concurrency control (MVCC).
- macOS (Using Homebrew):
brew install postgresql
brew services start postgresql # To start the server and set it to run at login- Linux (Ubuntu/Debian):
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql.service # Start the service- Windows:
Download the installer from the PostgreSQL Official Download Page. The installer includes the server, pgAdmin (a graphical tool), and the command-line tools.
psql is the interactive terminal for working with PostgreSQL.
-
Switch to the default
postgresuser (on Linux/macOS) and connect to the database:sudo -u postgres psql
On Windows,
psqlis available in the installed directory and you can connect directly. -
Basic
psqlCommands:# -- List all databases l # -- Connect to a specific database c database_name # -- List all tables in the current database dt # -- Describe a table's structure d table_name # -- List all users/roles du # -- Quit psql q
After installing PostgreSQL, a default superuser named postgres is created. To set up proper authentication, you'll typically need to create dedicated users with passwords.
# Create a new user
sudo -u postgres createuser --superuser your_username
# Set password for the user
sudo -u postgres psql -c "ALTER USER your_username WITH PASSWORD 'your_secure_password';"Security Note: Always use strong, complex passwords for production environments. Avoid simple or default passwords.
PostgreSQL runs on port 5432 by default. You may need to change this if the port is already in use or for security reasons.
Steps to Change the Default Port
-
Locate the Configuration File
The main configuration file ispostgresql.conf. Find it using:sudo find / -name postgresql.conf
Common locations include:
- Ubuntu/Debian:
/etc/postgresql/<version>/main/postgresql.conf - CentOS/RHEL:
/var/lib/pgsql/<version>/data/postgresql.conf
- Ubuntu/Debian:
-
Modify the Port Setting
Open the file with a text editor and find the line:# port = 5432Remove the
#to uncomment and change the port number:port = 6432 # or your preferred port -
Restart PostgreSQL Service
Apply the changes by restarting the service.sudo systemctl restart postgresql
-
Connect Using the New Port When connecting, specify the port explicitly:
psql -U your_username -d your_database -h 127.0.0.1 -p 6432
Then you can configure it in env file like this:
UTU_DB_URL=postgresql://your_username:your_password@127.0.0.1:6432/your_databasenpm install next --legacy-peer-depsnpm install --legacy-peer-depsThe reason for using the --legacy-peer-deps option is that the latest version of the react-json-view installation package is 1.21.3. When installed with react version 19.0.0, a warning will be generated. The actual test can be installed and used normally.
npm run buildnpm run startOnce you start your project, the server will be accessible via a browser using your server's IP address and the default port 3000. If you want to change the default port, you can modify the port in the start command in the script section of package.json.
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 3000",
"lint": "next lint",
"db:migrate": "tsx src/lib/db/migrate.ts",
"test:db": "tsx scripts/test-db-connection.ts"
}
}npm run test:dbYou can call the above command to test whether your database service can be accessed normally. Assuming that the database service has been configured, you can get the first data query in the database by the following command.