1#include <Common/CurrentMetrics.h>
2
3
4/// Available metrics. Add something here as you wish.
5#define APPLY_FOR_METRICS(M) \
6 M(Query, "Number of executing queries") \
7 M(Merge, "Number of executing background merges") \
8 M(PartMutation, "Number of mutations (ALTER DELETE/UPDATE)") \
9 M(ReplicatedFetch, "Number of data parts being fetched from replica") \
10 M(ReplicatedSend, "Number of data parts being sent to replicas") \
11 M(ReplicatedChecks, "Number of data parts checking for consistency") \
12 M(BackgroundPoolTask, "Number of active tasks in BackgroundProcessingPool (merges, mutations, fetches, or replication queue bookkeeping)") \
13 M(BackgroundMovePoolTask, "Number of active tasks in BackgroundProcessingPool for moves") \
14 M(BackgroundSchedulePoolTask, "Number of active tasks in BackgroundSchedulePool. This pool is used for periodic ReplicatedMergeTree tasks, like cleaning old data parts, altering data parts, replica re-initialization, etc.") \
15 M(DiskSpaceReservedForMerge, "Disk space reserved for currently running background merges. It is slightly more than the total size of currently merging parts.") \
16 M(DistributedSend, "Number of connections to remote servers sending data that was INSERTed into Distributed tables. Both synchronous and asynchronous mode.") \
17 M(QueryPreempted, "Number of queries that are stopped and waiting due to 'priority' setting.") \
18 M(TCPConnection, "Number of connections to TCP server (clients with native interface)") \
19 M(HTTPConnection, "Number of connections to HTTP server") \
20 M(InterserverConnection, "Number of connections from other replicas to fetch parts") \
21 M(OpenFileForRead, "Number of files open for reading") \
22 M(OpenFileForWrite, "Number of files open for writing") \
23 M(Read, "Number of read (read, pread, io_getevents, etc.) syscalls in fly") \
24 M(Write, "Number of write (write, pwrite, io_getevents, etc.) syscalls in fly") \
25 M(SendScalars, "Number of connections that are sending data for scalars to remote servers.") \
26 M(SendExternalTables, "Number of connections that are sending data for external tables to remote servers. External tables are used to implement GLOBAL IN and GLOBAL JOIN operators with distributed subqueries.") \
27 M(QueryThread, "Number of query processing threads") \
28 M(ReadonlyReplica, "Number of Replicated tables that are currently in readonly state due to re-initialization after ZooKeeper session loss or due to startup without ZooKeeper configured.") \
29 M(LeaderReplica, "Number of Replicated tables that are leaders. Leader replica is responsible for assigning merges, cleaning old blocks for deduplications and a few more bookkeeping tasks. There may be no more than one leader across all replicas at one moment of time. If there is no leader it will be elected soon or it indicate an issue.") \
30 M(MemoryTracking, "Total amount of memory (bytes) allocated in currently executing queries. Note that some memory allocations may not be accounted.") \
31 M(MemoryTrackingInBackgroundProcessingPool, "Total amount of memory (bytes) allocated in background processing pool (that is dedicated for backround merges, mutations and fetches). Note that this value may include a drift when the memory was allocated in a context of background processing pool and freed in other context or vice-versa. This happens naturally due to caches for tables indexes and doesn't indicate memory leaks.") \
32 M(MemoryTrackingInBackgroundMoveProcessingPool, "Total amount of memory (bytes) allocated in background processing pool (that is dedicated for backround moves). Note that this value may include a drift when the memory was allocated in a context of background processing pool and freed in other context or vice-versa. This happens naturally due to caches for tables indexes and doesn't indicate memory leaks.") \
33 M(MemoryTrackingInBackgroundSchedulePool, "Total amount of memory (bytes) allocated in background schedule pool (that is dedicated for bookkeeping tasks of Replicated tables).") \
34 M(MemoryTrackingForMerges, "Total amount of memory (bytes) allocated for background merges. Included in MemoryTrackingInBackgroundProcessingPool. Note that this value may include a drift when the memory was allocated in a context of background processing pool and freed in other context or vice-versa. This happens naturally due to caches for tables indexes and doesn't indicate memory leaks.") \
35 M(LeaderElection, "Number of Replicas participating in leader election. Equals to total number of replicas in usual cases.") \
36 M(EphemeralNode, "Number of ephemeral nodes hold in ZooKeeper.") \
37 M(ZooKeeperSession, "Number of sessions (connections) to ZooKeeper. Should be no more than one, because using more than one connection to ZooKeeper may lead to bugs due to lack of linearizability (stale reads) that ZooKeeper consistency model allows.") \
38 M(ZooKeeperWatch, "Number of watches (event subscriptions) in ZooKeeper.") \
39 M(ZooKeeperRequest, "Number of requests to ZooKeeper in fly.") \
40 M(DelayedInserts, "Number of INSERT queries that are throttled due to high number of active data parts for partition in a MergeTree table.") \
41 M(ContextLockWait, "Number of threads waiting for lock in Context. This is global lock.") \
42 M(StorageBufferRows, "Number of rows in buffers of Buffer tables") \
43 M(StorageBufferBytes, "Number of bytes in buffers of Buffer tables") \
44 M(DictCacheRequests, "Number of requests in fly to data sources of dictionaries of cache type.") \
45 M(Revision, "Revision of the server. It is a number incremented for every release or release candidate except patch releases.") \
46 M(VersionInteger, "Version of the server in a single integer number in base-1000. For example, version 11.22.33 is translated to 11022033.") \
47 M(RWLockWaitingReaders, "Number of threads waiting for read on a table RWLock.") \
48 M(RWLockWaitingWriters, "Number of threads waiting for write on a table RWLock.") \
49 M(RWLockActiveReaders, "Number of threads holding read lock in a table RWLock.") \
50 M(RWLockActiveWriters, "Number of threads holding write lock in a table RWLock.") \
51 M(GlobalThread, "Number of threads in global thread pool.") \
52 M(GlobalThreadActive, "Number of threads in global thread pool running a task.") \
53 M(LocalThread, "Number of threads in local thread pools. Should be similar to GlobalThreadActive.") \
54 M(LocalThreadActive, "Number of threads in local thread pools running a task.") \
55 M(DistributedFilesToInsert, "Number of pending files to process for asynchronous insertion into Distributed tables. Number of files for every shard is summed.") \
56
57
58namespace CurrentMetrics
59{
60 #define M(NAME, DOCUMENTATION) extern const Metric NAME = __COUNTER__;
61 APPLY_FOR_METRICS(M)
62 #undef M
63 constexpr Metric END = __COUNTER__;
64
65 std::atomic<Value> values[END] {}; /// Global variable, initialized by zeros.
66
67 const char * getName(Metric event)
68 {
69 static const char * strings[] =
70 {
71 #define M(NAME, DOCUMENTATION) #NAME,
72 APPLY_FOR_METRICS(M)
73 #undef M
74 };
75
76 return strings[event];
77 }
78
79 const char * getDocumentation(Metric event)
80 {
81 static const char * strings[] =
82 {
83 #define M(NAME, DOCUMENTATION) DOCUMENTATION,
84 APPLY_FOR_METRICS(M)
85 #undef M
86 };
87
88 return strings[event];
89 }
90
91 Metric end() { return END; }
92}
93
94#undef APPLY_FOR_METRICS
95