我們即將停用內部部署 API。請參閱我們的內部部署 API 停用文件以取得詳細資訊,並瞭解如何轉移到我們的新一代雲端 API。

DB Stats

/v1/stats/db

Use the /v1/stats/db endpoint to retrieve database stats.

Retrieving

Make a GET call to the /v1/stats/db endpoint to retrieve database stats in JSON or Prometheus format.

Checking the database stats can take a long time and affect app performance if your database is large. It is recommended polling this information only when needed.

Example

JSON Format

Request to retrieve database stats in JSON format:

GET /v1/stats/db
{
  Authorization: Bearer your-auth-token | Apikey your-api-key-token
}

If successful, your request returns 200 OK and a message body containing an db object.

You get the following response for single instance:

{
    "stats": {
        "db": {
            "db_contacts": {
                "data": [
                    {
                        "labels": {
                            "type": "non_whatsapp_user"
                        },
                        "value": 2
                    },
                    {
                        "labels": {
                            "type": "whatsapp_user"
                        },
                        "value": 5
                    }
                ],
                "help": "Current number of contacts in DB",
                "type": "gauge"
            },
            "db_message_receipts": {
                "data": [
                    {
                        "value": 6
                    }
                ],
                "help": "Current number of message receipts in DB",
                "type": "gauge"
            },
            "db_messages": {
                "data": [
                    {
                        "labels": {
                            "type": "undefined"
                        },
                        "value": 2
                    },
                    {
                        "labels": {
                            "type": "system"
                        },
                        "value": 1
                    }
                ],
                "help": "Current number of messages in DB",
                "type": "gauge"
            },
            "db_pending_callbacks": {
                "data": [
                    {
                        "value": 0
                    }
                ],
                "help": "Current number of pending callbacks in DB",
                "type": "gauge"
            },
            "db_pending_messages": {
                "data": [
                    {
                        "value": 0
                    }
                ],
                "help": "Current number of pending messages in DB",
                "type": "gauge"
            }
        }
    },
    "meta": {
        "api_status": "stable",
        "version": "2.18.13"
    }
} 
  

For high availability/multiconnect, only the primary Master returnd stats, others return {}:

{
    "stats": {
       "db": {
          "your-hostname1:your-container-id1": {},
          "your-primary-master:your-container-id2": {
             "db_contacts": {
               "data": [ {
                 "labels": {
                   "type": "whatsapp_user"
                 },
                 "value": 4
               } ],
               "help": "Current number of contacts in DB",
               "type": "gauge"
             },

             "db_message_receipts": { ... },

             "db_messages": { ... },
           
             "db_pending_callbacks": { ... },
           
             "db_pending_messages": { ... }
          },
         "your-hostname3:your-container-id3": {},
         ...
       }   
    }
}

Prometheus Format

Request to retrieve database stats in Prometheus format:

GET /v1/stats/db?format=prometheus
{
  Authorization: Bearer your-auth-token | Apikey your-api-key-token
}

You get the following response for single instance:

# HELP db_contacts Current number of contacts in DB
# TYPE db_contacts gauge
db_contacts{type="whatsapp_user"} 3
# HELP db_message_receipts Current number of message receipts in DB
# TYPE db_message_receipts gauge
db_message_receipts 0

You get the following response for high availability/multiconnect:

# HELP db_contacts Current number of contacts in DB
# TYPE db_contacts gauge
db_contacts{node="your-primary-master:your-container-id", type="whatsapp_user"} 3
# HELP db_message_receipts Current number of message receipts in DB
# TYPE db_message_receipts gauge
db_message_receipts{node="your-primary-master:your-container-id"} 0

Returned Fields

NameDescription

db_contacts

type: Object

Current number of contacts in the database.

db_message_receipts

type: Object

Current number of message receipts in the database.

db_messages

type: Object

Current number of messages in the database.

db_pending_callbacks

type: Object

Current number of pending callbacks in the database.

db_pending_messages

type: Object

Current number of pending messages in the database.