type: metadb

status:
  class: receiver
  stability:
    development: [metrics]

resource_attributes:
  project_id:
    description: The name of the elasticsearch cluster.
    type: string
    enabled: true
  project_name:
    description: The name of the elasticsearch node.
    type: string
    enabled: true
  cluster_id:
    description: The version of the elasticsearch node.
    type: string
    enabled: true
  cluster_name:
    description: The name of the elasticsearch index.
    type: string
    enabled: true
  service_plan:
    description: The service plan of the TiDB cluster (e.g. Dedicated, Premium, Essential, Starter).
    type: string
    enabled: true

attributes:
  sql_type:
    type: string
    description: The command types of sql statements, such as select, create, etc.
  cluster_name:
    type: string
    description: Cluster name.
  cluster_id:
    type: string
    description: Cluster ID.
  instance:
    type: string
    description: Instance name.
  component:
    type: string
    description: Components of a TiDB cluster.
    enum: [tidb, tikv, pd, tiflash]
  # error_type:
  #   type: string
  #   description: Error types of query errors, such as planner:xxx, executor:2345, etc.
  type:
    type: string
    description: Types of query or type of query errors
  result:
    type: string
    description: Result of disconnection.
  txn_mode:
    type: string
    description: Transaction mode.
  project_name:
    type: string
    description: Project name.
  changefeed_id:
    type: string
    description: Changefeed id.
  resource_group:
    type: string
    description: Resource group.
  job_id:
    type: string
    description: dm job id.
  task:
    type: string
    description: dm task.
  device:
    type: string
    description: device for disk latency

metrics:
  tidb_cloud.db_queries_total:
    enabled: true
    description: The total number of queries.
    unit: "1"
    sum:
      value_type: double
      monotonic: true
      aggregation: cumulative
    attributes: [sql_type, cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.db_failed_queries_total:
    enabled: true
    description: The total number of execution errors.
    unit: "1"
    sum:
      value_type: int
      monotonic: true
      aggregation: cumulative
    attributes: [type, cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.db_connections:
    enabled: true
    description: Current number of connections in TiDB server.
    unit: "1"
    gauge:
      value_type: int
    attributes: [cluster_name, instance, cluster_id, component, project_name]
  # tidb_cloud.db_query_duration_seconds:
  #   enabled: true
  #   description: Query duration distribution of seconds.
  #   unit: s
  #   histogram:
  #     aggregation: cumulative
  #     value_type: int
  #   attributes: [sql_type, cluster_name, cluster_id, instance, component, project_name]

  tidb_cloud.db_query_duration_seconds.count:
    enabled: true
    description: Total number of handled queries in server
    unit: "1"
    sum:
      value_type: int
      monotonic: true
      aggregation: cumulative
    attributes: [sql_type, cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.db_query_duration_seconds.sum:
    enabled: true
    description: Total number of handled queries in server
    unit: s
    sum:
      value_type: int
      monotonic: true
      aggregation: cumulative
    attributes: [sql_type, cluster_name, cluster_id, instance, component, project_name]

  tidb_cloud.db_total_connection:
    enabled: true
    description: The number of current connection
    unit: "1"
    gauge:
      value_type: double
    attributes: [cluster_name, instance, component, project_name]
  tidb_cloud.db_active_connections:
    enabled: true
    description: The number of active connection.
    unit: "1"
    gauge:
      value_type: double
    attributes: [cluster_name, instance, component, project_name]
  tidb_cloud.db_disconnections:
    enabled: true
    description: The number of clients disconnected.
    unit: "1"
    gauge:
      value_type: double
    attributes: [result, cluster_name, instance, component, project_name]
  tidb_cloud.db_database_time:
    enabled: true
    description: A time model statistic that is the sum of all process' CPU consumption plus the sum of non-idle wait time.
    unit: s
    gauge:
      value_type: double
    attributes: [sql_type, cluster_name, instance, component, project_name]
  tidb_cloud.db_query_per_second:
    enabled: true
    description: The number of SQL statements executed per second on all TiDB instances, which is counted according to SELECT, INSERT, UPDATE, and other types of statements.
    unit: "1"
    gauge:
      value_type: double
    attributes: [type, cluster_name, instance, component, project_name]
  tidb_cloud.db_failed_queries:
    enabled: true
    description: The statistics of error types (such as syntax errors and primary key conflicts) according to the errors occurred when executing SQL statements per second on each TiDB instance.
    unit: "1"
    gauge:
      value_type: double
    attributes: [type, cluster_name, instance, component, project_name]
  tidb_cloud.db_command_per_second:
    enabled: true
    description: The number of commands processed by TiDB per second, which is classified according to the success or failure of command execution results.
    unit: "1"
    gauge:
      value_type: double
    attributes: [type, cluster_name, instance, component, project_name]
  tidb_cloud.db_queries_using_plan_cache_ops:
    enabled: true
    description:
      "The statistics of queries using Plan Cache per second. The execution plan cache only supports the prepared statement command. If the value is 0, the execution plan cache has not been hit."
    unit: "1"
    gauge:
      value_type: double
    attributes: [type, cluster_name, instance, component, project_name]
  tidb_cloud.db_average_query_duration:
    enabled: true
    description:
      "The duration between the time that the client's network request is sent to TiDB and the time that the request is returned to the client after TiDB has executed it. In general, client requests are sent in the form of SQL statements, but can also include the execution time of commands such as COM_PING, COM_SLEEP, COM_STMT_FETCH, and COM_SEND_LONG_DATA. Because TiDB supports Multi-Query, it supports sending multiple SQL statements at one time, such as select 1; select 1; select 1;. In this case, the total execution time of this query includes the execution time of all SQL statements."
    unit: s
    gauge:
      value_type: double
    attributes: [sql_type, cluster_name, instance, component, project_name]
  tidb_cloud.db_transaction_per_second:
    enabled: true
    description: The number of transactions executed per second.
    unit: "1"
    gauge:
      value_type: double
    attributes: [txn_mode, type, cluster_name, instance, component, project_name]



  tidb_cloud.node_storage_used_bytes:
    enabled: true
    description: The disk usage bytes of TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: int
    attributes: [cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.node_storage_capacity_bytes:
    enabled: true
    description: The disk capacity bytes of TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: int
    attributes: [cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.node_storage_available_bytes:
    enabled: true
    description: The disk available bytes of TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: int
    attributes: [cluster_name, cluster_id, instance, component, project_name]



  tidb_cloud.node_cpu_seconds_total:
    enabled: true
    description: The CPU usage of TiDB/TiKV/TiFlash nodes.
    unit: s
    sum:
      value_type: int
      monotonic: true
      aggregation: cumulative
    attributes: [cluster_name, cluster_id, instance, component, project_name]

  tidb_cloud.node_cpu_seconds_total_rate:
    enabled: true
    description: The CPU usage rate of TiDB/TiKV/TiFlash nodes.
    unit: s
    sum:
      value_type: double
      monotonic: true
      aggregation: cumulative
    attributes: [cluster_name, cluster_id, instance, component, project_name]

  tidb_cloud.node_cpu_capacity_cores:
    enabled: true
    description: The capacity cores of TiDB/TiKV/TiFlash nodes.
    unit: "1"
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, instance, component, project_name]



  tidb_cloud.node_memory_used_bytes:
    enabled: true
    description: The used memory bytes of TiDB/TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.node_memory_capacity_bytes:
    enabled: true
    description: The memory capacity bytes of TiDB/TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, instance, component, project_name]
  tidb_cloud.node_memory_available_bytes:
    enabled: true
    description: The memory capacity bytes of TiDB/TiKV/TiFlash nodes.
    unit: By
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, instance, component, project_name]

# newly added metrics
  tidb_cloud.db_component_uptime:
    enabled: true
    description: The uptime of tidb components
    unit: s
    gauge:
      value_type: double
    attributes: [cluster_name, instance, component, project_name]
  tidb_cloud.cdc_changefeed_resolved_ts_lag:
    enabled: true
    description: The resolved ts lag of a changefeed's owner.
    unit: s
    gauge:
      value_type: double
    attributes: [changefeed_id, cluster_name, instance, project_name]
  tidb_cloud.cdc_changefeed_latency:
    enabled: true
    description: The checkpoint ts lag of a changefeed's owner.
    unit: s
    gauge:
      value_type: double
    attributes: [changefeed_id, cluster_name, instance, project_name]
  tidb_cloud.cdc_checkpoint_ts:
    enabled: true
    description: The checkpoint timestamp of a changefeed.
    unit: "1"
    gauge:
      value_type: double
    attributes: [changefeed_id, cluster_name, instance, project_name]
  tidb_cloud.cdc_changefeed_status:
    enabled: true
    description: The status of a changefeed.
    unit: s
    gauge:
      value_type: int
    attributes: [changefeed_id, cluster_name, instance, project_name]
  tidb_cloud.cdc_changefeed_replica_rows:
    enabled: true
    description: The number of replica rows that ChangeFeed writes to the downstream per second.
    unit: "1"
    gauge:
      value_type: double
    attributes: [changefeed_id, cluster_name, instance, project_name]
  tidb_cloud.resource_manager_resource_unit_read_request_unit:
    enabled: true
    description: The resource manager read request.
    unit: "1"
    gauge:
      value_type: double
    attributes: [resource_group, cluster_name, instance, project_name]
  tidb_cloud.resource_manager_resource_unit_write_request_unit:
    enabled: true
    description: The resource manager write request.
    unit: "1"
    gauge:
      value_type: double
    attributes: [resource_group, cluster_name, instance, project_name]
  tidb_cloud.resource_manager_resource_request_unit_total:
    enabled: true
    description: The resource manager request unit total.
    unit: "1"
    gauge:
      value_type: double
    attributes: [resource_group, cluster_name, instance, project_name]
  tidb_cloud.dm_task_state:
    enabled: true
    description: Task State
    unit: "1"
    gauge:
      value_type: int
    attributes: [task, job_id, cluster_name, instance, project_name]
  tidb_cloud.dm_syncer_replication_lag_bucket:
    enabled: true
    description: Task State
    unit: "1"
    gauge:
      value_type: double
    attributes: [task, job_id, cluster_name, instance, project_name ]
  tidb_cloud.dm_syncer_replication_lag_gauge:
    enabled: true
    description: Task State
    unit: "1"
    gauge:
      value_type: double
    attributes: [task, job_id, cluster_name, instance, project_name ]
  tidb_cloud.dm_relay_read_error_count:
    enabled: true
    description: Task State
    unit: "1"
    gauge:
      value_type: double
    attributes: [task, job_id, cluster_name, instance, project_name ]
  tidb_cloud.db_kv_request_duration:
    enabled: true
    description:
      "TiDB KV Request Duration"
    unit: s
    gauge:
      value_type: double
    attributes: [type, cluster_name, instance, component, project_name]
  tidb_cloud.node_disk_read_latency:
    enabled: true
    description:
      "Node disk read latency"
    unit: s
    gauge:
      value_type: double
    attributes: [cluster_name, instance, component, project_name, device]
  tidb_cloud.node_disk_write_latency:
    enabled: true
    description:
      "Node disk write latency"
    unit: s
    gauge:
      value_type: double
    attributes: [cluster_name, instance, component, project_name, device]

  tidb_cloud.db_row_storage_used_bytes:
    enabled: true
    description: The row-based (TiKV) storage usage for a TiDB X cluster.
    unit: By
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, project_name]
  tidb_cloud.db_columnar_storage_used_bytes:
    enabled: true
    description: The columnar (TiFlash) storage usage for a TiDB X cluster.
    unit: By
    gauge:
      value_type: double
    attributes: [cluster_name, cluster_id, project_name]
