Loading...
Searching...
No Matches
aerospike_stats.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2024 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/aerospike.h>
20#include <aerospike/as_node.h>
21
22/**
23 * @defgroup cluster_stats Cluster Statistics
24 *
25 * Statistics for each Aerospike client instance.
26 */
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/******************************************************************************
33 * TYPES
34 *****************************************************************************/
35
36/**
37 * Connection statistics.
38 * @ingroup cluster_stats
39 */
40typedef struct as_conn_stats_s {
41 /**
42 * Connections residing in pool(s) on this node.
43 * There can be multiple pools per node. This value is a summary of those pools on this node.
44 */
45 uint32_t in_pool;
46
47 /**
48 * Connections actively being used in database transactions on this node.
49 * There can be multiple pools per node. This value is a summary of those pools on this node.
50 */
51 uint32_t in_use;
52
53 /**
54 * Total number of node connections opened since node creation.
55 */
56 uint32_t opened;
57
58 /**
59 * Total number of node connections closed since node creation.
60 */
61 uint32_t closed;
62
64
65/**
66 * Node statistics.
67 * @ingroup cluster_stats
68 */
69typedef struct as_node_stats_s {
70 /**
71 * Node.
72 */
74
75 /**
76 * Sync connection statistics on this node.
77 */
79
80 /**
81 * Async connection statistics on this node.
82 */
84
85 /**
86 * Async pipeline connection statistics on this node.
87 */
89
90 /**
91 * Transaction error count since node was initialized. If the error is retryable, multiple errors per
92 * transaction may occur.
93 */
94 uint64_t error_count;
95
96 /**
97 * Transaction timeout count since node was initialized. If the timeout is retryable (ie socket timeout),
98 * multiple timeouts per transaction may occur.
99 */
101
103
104/**
105 * Event loop statistics.
106 * @ingroup cluster_stats
107 */
108typedef struct as_event_loop_stats_s {
109 /**
110 * Approximate number of commands actively being processed on
111 * the event loop.
112 */
114
115 /**
116 * Approximate number of commands stored on this event loop's
117 * delay queue that have not been started yet.
118 */
119 uint32_t queue_size;
120
122
123/**
124 * Cluster statistics.
125 * @ingroup cluster_stats
126 */
127typedef struct as_cluster_stats_s {
128 /**
129 * Statistics for all nodes.
130 */
132
133 /**
134 * Statistics for all event loops.
135 */
137
138 /**
139 * Count of transaction retries since cluster was started.
140 */
141 uint64_t retry_count;
142
143 /**
144 * Node count.
145 */
146 uint32_t nodes_size;
147
148 /**
149 * Event loop count.
150 */
152
153 /**
154 * Count of sync batch/scan/query tasks awaiting execution. If the count is greater than zero,
155 * then all threads in the thread pool are active.
156 */
158
160
161struct as_cluster_s;
162
163/******************************************************************************
164 * FUNCTIONS
165 *****************************************************************************/
166
167/**
168 * Retrieve aerospike cluster statistics.
169 *
170 * @param cluster The aerospike cluster.
171 * @param stats The statistics summary for specified cluster.
172 *
173 * @ingroup cluster_stats
174 */
175AS_EXTERN void
176aerospike_cluster_stats(struct as_cluster_s* cluster, as_cluster_stats* stats);
177
178/**
179 * Retrieve aerospike client instance statistics.
180 *
181 * ~~~~~~~~~~{.c}
182 * as_cluster_stats stats;
183 * aerospike_stats(&as, &stats);
184 * aerospike_stats_destroy(&stats);
185 * ~~~~~~~~~~
186 *
187 * @param as The aerospike instance.
188 * @param stats The statistics summary for specified client instance.
189 *
190 * @ingroup cluster_stats
191 */
192static inline void
197
198/**
199 * Release node references and memory allocated in aerospike_stats().
200 *
201 * @param stats The cluster statistics summary.
202 *
203 * @ingroup cluster_stats
204 */
205AS_EXTERN void
207
208/**
209 * Retrieve aerospike node statistics.
210 *
211 * @param node The server node.
212 * @param stats The statistics summary for specified node.
213 *
214 * @ingroup cluster_stats
215 */
216AS_EXTERN void
218
219/**
220 * Release node reference allocated in aerospike_node_stats().
221 *
222 * @param stats The statistics summary for specified node.
223 *
224 * @ingroup cluster_stats
225 */
226static inline void
231
232/**
233 * Retrieve aerospike event loop statistics.
234 *
235 * @param event_loop The event loop.
236 * @param stats The statistics summary for specified event loop.
237 *
238 * @ingroup cluster_stats
239 */
240static inline void
242{
243 // Warning: cross-thread references without a lock.
244 stats->process_size = as_event_loop_get_process_size(event_loop);
245 stats->queue_size = as_event_loop_get_queue_size(event_loop);
246}
247
248/**
249 * Return string representation of cluster statistics.
250 * The string should be freed when it's no longer needed.
251 *
252 * @ingroup cluster_stats
253 */
254AS_EXTERN char*
256
257static inline void
259{
260 stats->in_pool = 0;
261 stats->in_use = 0;
262 stats->opened = 0;
263 stats->closed = 0;
264}
265
266void
268
269#ifdef __cplusplus
270} // end extern "C"
271#endif
static void as_conn_stats_init(as_conn_stats *stats)
void as_conn_stats_sum(as_conn_stats *stats, as_async_conn_pool *pool)
static void as_node_release(as_node *node)
Definition as_node.h:527
#define AS_EXTERN
Definition as_std.h:25
static uint32_t as_event_loop_get_queue_size(as_event_loop *event_loop)
Definition as_event.h:412
static int as_event_loop_get_process_size(as_event_loop *event_loop)
Definition as_event.h:398
AS_EXTERN void aerospike_node_stats(as_node *node, as_node_stats *stats)
static void aerospike_stats(aerospike *as, as_cluster_stats *stats)
AS_EXTERN char * aerospike_stats_to_string(as_cluster_stats *stats)
AS_EXTERN void aerospike_cluster_stats(struct as_cluster_s *cluster, as_cluster_stats *stats)
static void aerospike_event_loop_stats(as_event_loop *event_loop, as_event_loop_stats *stats)
static void aerospike_node_stats_destroy(as_node_stats *stats)
AS_EXTERN void aerospike_stats_destroy(as_cluster_stats *stats)
struct as_cluster_s * cluster
Definition aerospike.h:172
uint32_t thread_pool_queued_tasks
as_node_stats * nodes
as_event_loop_stats * event_loops
as_conn_stats async
uint64_t timeout_count
as_conn_stats sync
uint64_t error_count
as_conn_stats pipeline