Skip to main content

UniAgent Deployment (Linux Only)

When there are applications in multiple languages on a Linux server, it is recommended to use UniAgent for installation.

The installation path is fixed at /opt/tingyun-oneagent. For installation steps, please refer to UniAgent Deployment Guide.

The UniAgent package integrates Agents for Java/PHP/.NET Core/Node.js/Python. After installation, you do not need to manually modify the application's configuration files. All Agent embedding actions are automatically completed by UniAgent, and it can automatically monitor applications inside Docker containers.

After UniAgent installation is complete, if you need to monitor Node.js applications, you need to manually enable the Node.js monitoring switch in /opt/tingyun-oneagent/conf/interceptor.conf by setting nodejs_enabled=true.

sudo sed -i -e "s/nodejs_enabled.*/nodejs_enabled=true/" /opt/tingyun-oneagent/conf/interceptor.conf

Then restart the Node.js application.

Standard Agent Deployment

  1. Go to the application root directory and install the package.

    cd <app root dir>
    npm install tingyun
  2. Run the configuration command and fill in the application name and license key.

    node node_modules/tingyun/setup.js 

    After completion, the Agent configuration file tingyun.json will be generated in the application directory.

  3. Modify the application's main file and add require('tingyun') to the first line.

    If your package.json does not have a main parameter and there is no index.js file in the application root directory, you need to manually add require('tingyun') to the first line of the main file.

    If you are on Windows, the setup.js script may fail to add require('tingyun') to the first line, so you need to manually add it to the main file.

Using pkg to Package as Executable

  1. Go to the application root directory and install the package.

    cd <app root dir>
    npm install tingyun
  2. Add require('tingyun') to the first line of the application's main file.

  3. Because the Agent introduces dynamically required JS, you need to modify package.js and add scripts references.

    Example:

    {
    "name": "demo",
    "version": "1.0.0",
    "description": "this is a demo",
    "main": "index.js",
    "bin": "index.js",
    "pkg": {
    "scripts": ["node_modules/tingyun/parsers/wrappers/**/*.js"],
    "targets": [ "node18-win-x64" ],
    "outputPath": "."
    },
    "dependencies": {
    "express": "^4.18.2",
    "mysql": "^2.18.1",
    "tingyun": "^3.0.4"
    }
    }
    • bin specifies the project entry file, set according to the pkg documentation
    • pkg.scripts specifies the JS files to be forcibly included, supports glob format paths, node_modules/tingyun/parsers/wrappers/**/*.js is the dynamic import module path for the Agent
    • Other configurations should be set according to the actual project needs
  4. Repackage

    pkg package.json

    Warnings may appear during packaging, which is normal:

    Warning Cannot resolve 'path' node_modules\tingyun\util\shimmer.js
    Dynamic require may fail at run time, because the requested file
    is unknown at compilation time and not included into executable.
    Use a string literal as an argument for 'require', or leave it
    as is and specify the resolved file name in 'scripts' option.
  5. When deploying, you need to place the Agent configuration file tingyun.json in the same folder as the executable file.

    Example template for the Agent configuration file tingyun.json:

    {
    "agent_log_level": "info",
    "app_name": "demo",
    "license_key": "9OgQXob4VGGFFYcm",
    "collectors": "127.0.0.1:7665",
    "ssl": false,
    "agent_log_file_name": "tingyun_agent.log",
    "audit_mode": false
    }

    The app_name, license_key, and collectors fields need to be dynamically modified according to the project needs.

    The log file path does not need to be changed; logs are output to the current directory of the executable file.