> ## Documentation Index
> Fetch the complete documentation index at: https://wukong.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Get System Variables

> Get system variables and performance metrics

## Overview

Get WuKongIM system runtime variables and performance metrics for system monitoring and performance analysis.

## Query Parameters

<ParamField query="sort" type="string" default="in_msgs">
  Sort field

  * `in_msgs` - Sort by received message count
  * `out_msgs` - Sort by sent message count
  * `in_bytes` - Sort by received bytes
  * `out_bytes` - Sort by sent bytes
</ParamField>

<ParamField query="conn_limit" type="integer" default={20}>
  Connection information limit count
</ParamField>

<ParamField query="node_id" type="integer">
  Specify node ID (cluster environment)
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:5001/varz?sort=in_msgs&conn_limit=50');
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  params = {
      'sort': 'in_msgs',
      'conn_limit': 50
  }

  response = requests.get('http://localhost:5001/varz', params=params)
  data = response.json()
  print(data)
  ```

  ```go Go theme={null}
  package main

  import (
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      resp, err := http.Get("http://localhost:5001/varz?sort=in_msgs&conn_limit=50")
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()
      
      var result map[string]interface{}
      json.NewDecoder(resp.Body).Decode(&result)
      fmt.Printf("%+v\n", result)
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "server_id": "wukongim-node-1",
    "version": "2.0.0",
    "git_commit": "abc123def",
    "go_version": "go1.21.0",
    "start": "2024-01-15T08:00:00Z",
    "now": "2024-01-15T10:30:00Z",
    "uptime": "2h30m0s",
    "connections": 1250,
    "total_connections": 15000,
    "in_msgs": 125000,
    "out_msgs": 130000,
    "in_bytes": 12500000,
    "out_bytes": 13000000,
    "slow_consumers": 5,
    "subscriptions": 8500,
    "http_req_stats": {
      "uri_stats": [
        {
          "uri": "/message/send",
          "count": 5000,
          "avg_time": "15ms"
        },
        {
          "uri": "/channel/create",
          "count": 200,
          "avg_time": "25ms"
        }
      ]
    },
    "cpu": 15.5,
    "mem": 536870912,
    "config": {
      "max_connections": 10000,
      "max_subscriptions_per_conn": 100,
      "max_payload": 1048576
    }
  }
  ```
</ResponseExample>

## Response Fields

### Server Information

<ResponseField name="server_id" type="string" required>
  Server identifier
</ResponseField>

<ResponseField name="version" type="string" required>
  WuKongIM version number
</ResponseField>

<ResponseField name="git_commit" type="string" required>
  Git commit hash
</ResponseField>

<ResponseField name="go_version" type="string" required>
  Go language version
</ResponseField>

### Runtime Information

<ResponseField name="start" type="string" required>
  Server start time (ISO 8601 format)
</ResponseField>

<ResponseField name="now" type="string" required>
  Current time (ISO 8601 format)
</ResponseField>

<ResponseField name="uptime" type="string" required>
  Runtime duration
</ResponseField>

### Connection Statistics

<ResponseField name="connections" type="integer" required>
  Current connection count
</ResponseField>

<ResponseField name="total_connections" type="integer" required>
  Total connections (historical cumulative)
</ResponseField>

<ResponseField name="slow_consumers" type="integer" required>
  Number of slow consumers
</ResponseField>

<ResponseField name="subscriptions" type="integer" required>
  Total subscriptions
</ResponseField>

### Message Statistics

<ResponseField name="in_msgs" type="integer" required>
  Total received messages
</ResponseField>

<ResponseField name="out_msgs" type="integer" required>
  Total sent messages
</ResponseField>

<ResponseField name="in_bytes" type="integer" required>
  Total received bytes
</ResponseField>

<ResponseField name="out_bytes" type="integer" required>
  Total sent bytes
</ResponseField>

### HTTP Request Statistics

<ResponseField name="http_req_stats" type="object" required>
  HTTP request statistics

  <Expandable title="http_req_stats fields">
    <ResponseField name="http_req_stats.uri_stats" type="array">
      URI statistics list

      <ResponseField name="http_req_stats.uri_stats[].uri" type="string">
        Request URI
      </ResponseField>

      <ResponseField name="http_req_stats.uri_stats[].count" type="integer">
        Request count
      </ResponseField>

      <ResponseField name="http_req_stats.uri_stats[].avg_time" type="string">
        Average response time
      </ResponseField>
    </ResponseField>
  </Expandable>
</ResponseField>

### System Resources

<ResponseField name="cpu" type="number" required>
  CPU usage (percentage)
</ResponseField>

<ResponseField name="mem" type="integer" required>
  Memory usage (bytes)
</ResponseField>

### Configuration Information

<ResponseField name="config" type="object" required>
  System configuration information

  <Expandable title="config fields">
    <ResponseField name="config.max_connections" type="integer">
      Maximum connection limit
    </ResponseField>

    <ResponseField name="config.max_subscriptions_per_conn" type="integer">
      Maximum subscriptions per connection
    </ResponseField>

    <ResponseField name="config.max_payload" type="integer">
      Maximum message payload size (bytes)
    </ResponseField>
  </Expandable>
</ResponseField>

## Status Codes

| Status Code | Description                             |
| ----------- | --------------------------------------- |
| 200         | Successfully retrieved system variables |
| 500         | Internal server error                   |

## Monitoring Metrics Description

### Performance Metrics

| Metric         | Description                           | Normal Range    | Alert Threshold |
| -------------- | ------------------------------------- | --------------- | --------------- |
| CPU Usage      | Server CPU utilization percentage     | \< 70%          | > 80%           |
| Memory Usage   | Server memory consumption             | \< 80%          | > 90%           |
| Connections    | Current active connections            | Based on config | Near maximum    |
| Slow Consumers | Number of slow processing connections | \< 5%           | > 10%           |

### Throughput Metrics

| Metric               | Description                          | Monitoring Focus                     |
| -------------------- | ------------------------------------ | ------------------------------------ |
| Message Receive Rate | Messages received per second         | Sudden increases or decreases        |
| Message Send Rate    | Messages sent per second             | Ratio to receive rate                |
| Byte Transfer Rate   | Network transfer speed               | Bandwidth usage                      |
| HTTP Request Stats   | API call frequency and response time | Hot APIs and performance bottlenecks |

## Best Practices

1. **Regular Monitoring**: Recommended to get system variables every 30-60 seconds
2. **Alert Setup**: Set reasonable alert thresholds for key metrics
3. **Trend Analysis**: Record historical data to analyze system performance trends
4. **Capacity Planning**: Perform capacity planning based on monitoring data
5. **Performance Optimization**: Identify performance bottlenecks and optimize
6. **Cluster Monitoring**: Monitor all node status in cluster environments
