Tianji Documentation

repository·master·Indexed 25 days ago

https://github.com/msgbyte/tianji

An all-in-one insight hub integrating website analytics, uptime monitoring, and server status tracking. The ecosystem includes a CLI for managing Tianji Workers, an MCP Server for AI assistant integration, and tools for tracking events and bridging App Store reviews into surveys.

Tokens
75.8K
Snippets
168
Records
476
Agent score
83%

What's inside Tianji

  1. Overview of Tianji capabilities

    master

    Tianji is an all-in-one lightweight monitoring application designed to consolidate multiple specialized tools into a single service. It provides three core functionalities:

    1. Website Analytics: Tracking metrics like PV (Page Views), UV (Unique Visitors), and page visit counts (similar to GA or Umami).
    2. Uptime Monitor: Checking network quality and server connectivity.
    3. Server Status: Monitoring server health and status (similar to Prometheus).

    It is intended for users who need comprehensive monitoring without the overhead of managing multiple separate services.

  2. Overview of Tianji MCP Server features

    master

    The Tianji MCP Server acts as a bridge between AI assistants and the Tianji platform. It exposes survey-related functionality through the Model Context Protocol (MCP), allowing AI assistants to:

    • Query survey results
    • Get detailed survey information
    • Get a list of all surveys in a workspace
  3. Overview of AI Router

    master

    AI Router provides a single stable AI endpoint for a group of AI Gateways. It manages request routing, traffic splitting via weights, and automatic fallback to subsequent tiers when retryable failures occur.

    Key Use Cases:

    • Using one endpoint instead of hard-coding specific AI providers.
    • Splitting traffic across multiple gateways using weights.
    • Implementing fallback logic (e.g., moving from a primary provider to a backup during outages).
    • Gradually migrating traffic between providers by adjusting weights.
  4. Identify typical Tianji Feed use cases

    master

    Tianji Feed is designed for aggregating and communicating various operational signals. Common use cases include:

    • Incident Management: Creating product and infrastructure incident streams across multiple services.
    • Deployment Tracking: Managing CI/CD deployment and release notices.
    • Business Intelligence: Monitoring billing and subscription signals.
    • Operational Alerts: Centralizing security, monitoring, and error alerts.
  5. Understand Tianji Feed concepts

    master

    Tianji Feed is a lightweight event stream used to aggregate important events from different systems into channels for collaboration and stakeholder notification. Key concepts include:

    • Channel: A logical stream used to collect and organize events. Channels can be connected to one or more notification targets and can optionally require a webhook signature.
    • Event: A single record containing a name, content, tags, source, sender identity, importance, and an optional payload. Events support archiving and unarchiving.
    • State: A specialized ongoing event that can be repeatedly upserted (created or updated) using a stable eventId and is considered resolved once finished.
    • Integration: Built-in webhook adapters that transform 3rd-party payloads (such as GitHub, Stripe, Sentry, or Tencent Cloud Alarm) into Feed events.
    • Notification: The mechanism by which channels fan-out events to configured notifiers. Delivery frequency is configurable via channel settings.
  6. Understand User Label Resolution in Usage Analytics

    master

    In Tianji AI Gateway Usage Analytics, user charts (Request Count, Cost, and Token Usage) resolve raw userIds into human-readable labels using the following priority order:

    1. The member's non-empty nickname.
    2. The member's username.
    3. The original userId (fallback if the member cannot be resolved).

    Resolved users are displayed in the format: name (userId). If a user is removed or cannot be resolved, the system falls back to the raw userId without additional punctuation to ensure historical data remains readable.

  7. Use the Tianji unified monitoring dashboard

    master

    Tianji's unified dashboard consolidates server metrics, endpoint response times, and user experience data into a single view. This allows engineers to correlate disparate data sources without context switching.

    Key features include:

    • Correlation Capability: View server metrics and user experience data simultaneously to reduce Mean Time to Resolution (MTTR).
    • Timeline View: Synchronizes events across different monitoring types (e.g., traffic spikes vs. server resource constraints) to identify cause-and-effect relationships.
  8. Understand the Monitor Redis Broadcast Hardening Design

    master

    The Monitor Redis Broadcast Hardening design ensures that optional Redis Monitor lifecycle synchronization is safe under concurrent events, startup races, Redis disconnects, and database failures.

    Key principles:

    • PostgreSQL is authoritative: Redis is used for broadcasting, but the final state of any Monitor is always determined by the PostgreSQL database. This prevents delayed or out-of-order Redis messages from overriding the true state in the database.
    • Redis is optional: If REDIS_URL is not provided, the system operates without Redis clients and without startup delays.
    • Per-Monitor Serialization: Operations for a specific monitorId (updates, state changes, deletions, remote events, and reconciliations) are serialized through an internal queue to prevent race conditions. Different Monitor IDs can still process operations concurrently.
  9. Use Tianji for cost-efficient observability

    master

    Tianji provides several features to implement cost-aware observability patterns:

  10. Default Docker Monitoring Behavior in Tianji

    master
    When installed via Docker or Docker Compose, Tianji enables built-in server monitoring by default. It automatically monitors its own container's system resource usage (CPU, memory, disk, network, etc.) and reports this data to the default workspace. The container is identified as tianji-container in the monitoring dashboard.
  11. Tianji Real-Time Monitoring Capabilities

    master

    Tianji provides a multi-dimensional observability view through three core monitoring capabilities:

    Website Analytics

    Tracks real-time visitor metrics including:

    • Visitor count and geographic distribution
    • Page load performance (LCP, FID, CLS)
    • User behavior flow tracking
    • API response time statistics

    Uptime Monitor

    Provides continuous availability checking via:

    • Second-level heartbeat detection
    • Multi-region global probing
    • Support for DNS, TCP, and HTTP protocols
    • Automatic failover verification

    Server Status

    Streams infrastructure metrics including:

    • CPU, memory, and disk I/O monitoring
    • Network traffic and connection status
    • Process-level resource consumption
    • Container and virtualization metrics