All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aerospike_stats.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2021 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
29 extern "C" {
30 #endif
31 
32 /******************************************************************************
33  * TYPES
34  *****************************************************************************/
35 
36 /**
37  * Connection statistics.
38  * @ingroup cluster_stats
39  */
40 typedef 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  */
69 typedef 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  * Node error count within current window.
92  */
93  uint32_t error_count;
94 
96 
97 /**
98  * Event loop statistics.
99  * @ingroup cluster_stats
100  */
101 typedef struct as_event_loop_stats_s {
102  /**
103  * Approximate number of commands actively being processed on
104  * the event loop.
105  */
107 
108  /**
109  * Approximate number of commands stored on this event loop's
110  * delay queue that have not been started yet.
111  */
112  uint32_t queue_size;
113 
115 
116 /**
117  * Cluster statistics.
118  * @ingroup cluster_stats
119  */
120 typedef struct as_cluster_stats_s {
121  /**
122  * Statistics for all nodes.
123  */
125 
126  /**
127  * Statistics for all event loops.
128  */
130 
131  /**
132  * Node count.
133  */
134  uint32_t nodes_size;
135 
136  /**
137  * Event loop count.
138  */
140 
141  /**
142  * Count of sync batch/scan/query tasks awaiting execution. If the count is greater than zero,
143  * then all threads in the thread pool are active.
144  */
146 
148 
149 struct as_cluster_s;
150 
151 /******************************************************************************
152  * FUNCTIONS
153  *****************************************************************************/
154 
155 /**
156  * Retrieve aerospike cluster statistics.
157  *
158  * @param cluster The aerospike cluster.
159  * @param stats The statistics summary for specified cluster.
160  *
161  * @ingroup cluster_stats
162  */
163 AS_EXTERN void
164 aerospike_cluster_stats(struct as_cluster_s* cluster, as_cluster_stats* stats);
165 
166 /**
167  * Retrieve aerospike client instance statistics.
168  *
169  * ~~~~~~~~~~{.c}
170  * as_cluster_stats stats;
171  * aerospike_stats(&as, &stats);
172  * aerospike_stats_destroy(&stats);
173  * ~~~~~~~~~~
174  *
175  * @param as The aerospike instance.
176  * @param stats The statistics summary for specified client instance.
177  *
178  * @ingroup cluster_stats
179  */
180 static inline void
182 {
183  aerospike_cluster_stats(as->cluster, stats);
184 }
185 
186 /**
187  * Release node references and memory allocated in aerospike_stats().
188  *
189  * @param stats The cluster statistics summary.
190  *
191  * @ingroup cluster_stats
192  */
193 AS_EXTERN void
195 
196 /**
197  * Retrieve aerospike node statistics.
198  *
199  * @param node The server node.
200  * @param stats The statistics summary for specified node.
201  *
202  * @ingroup cluster_stats
203  */
204 AS_EXTERN void
206 
207 /**
208  * Release node reference allocated in aerospike_node_stats().
209  *
210  * @param stats The statistics summary for specified node.
211  *
212  * @ingroup cluster_stats
213  */
214 static inline void
216 {
217  as_node_release(stats->node);
218 }
219 
220 /**
221  * Retrieve aerospike event loop statistics.
222  *
223  * @param event_loop The event loop.
224  * @param stats The statistics summary for specified event loop.
225  *
226  * @ingroup cluster_stats
227  */
228 static inline void
230 {
231  // Warning: cross-thread references without a lock.
232  stats->process_size = as_event_loop_get_process_size(event_loop);
233  stats->queue_size = as_event_loop_get_queue_size(event_loop);
234 }
235 
236 /**
237  * Return string representation of cluster statistics.
238  * The string should be freed when it's no longer needed.
239  *
240  * @ingroup cluster_stats
241  */
242 AS_EXTERN char*
244 
245 #ifdef __cplusplus
246 } // end extern "C"
247 #endif
uint32_t in_pool
static uint32_t as_event_loop_get_queue_size(as_event_loop *event_loop)
Definition: as_event.h:412
as_node_stats * nodes
struct as_cluster_s * cluster
Definition: aerospike.h:172
AS_EXTERN void aerospike_node_stats(as_node *node, as_node_stats *stats)
as_conn_stats pipeline
as_conn_stats sync
#define AS_EXTERN
Definition: as_std.h:25
as_conn_stats async
AS_EXTERN char * aerospike_stats_to_string(as_cluster_stats *stats)
static void aerospike_event_loop_stats(as_event_loop *event_loop, as_event_loop_stats *stats)
static int as_event_loop_get_process_size(as_event_loop *event_loop)
Definition: as_event.h:398
static void aerospike_stats(aerospike *as, as_cluster_stats *stats)
as_node * node
uint32_t event_loops_size
as_event_loop_stats * event_loops
uint32_t thread_pool_queued_tasks
static void as_node_release(as_node *node)
Definition: as_node.h:495
AS_EXTERN void aerospike_cluster_stats(struct as_cluster_s *cluster, as_cluster_stats *stats)
AS_EXTERN void aerospike_stats_destroy(as_cluster_stats *stats)
uint32_t error_count
static void aerospike_node_stats_destroy(as_node_stats *stats)