1 | /* |
2 | * thr_info.h |
3 | * |
4 | * Copyright (C) 2008-2014 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include <stdbool.h> |
26 | #include <stddef.h> |
27 | #include <stdint.h> |
28 | |
29 | #include "dynbuf.h" |
30 | |
31 | #include "base/proto.h" |
32 | #include "base/security.h" |
33 | #include "base/transaction.h" |
34 | |
35 | #define MAX_INFO_THREADS 256 |
36 | |
37 | typedef int (*as_info_get_tree_fn) (char *name, char *subtree, cf_dyn_buf *db); |
38 | typedef int (*as_info_get_value_fn) (char *name, cf_dyn_buf *db); |
39 | typedef int (*as_info_command_fn) (char *name, char *parameters, cf_dyn_buf *db); |
40 | |
41 | // Sets a static value - set to 0 to remove a previous value. |
42 | extern int as_info_set_buf(const char *name, const uint8_t *value, size_t value_sz, bool def); |
43 | extern int as_info_set(const char *name, const char *value, bool def); |
44 | |
45 | // For dynamic items - you will get called when the name is requested. The |
46 | // dynbuf will be fully set up for you - just add the information you want to |
47 | // return. |
48 | extern int as_info_set_dynamic(const char *name, as_info_get_value_fn gv_fn, bool def); |
49 | |
50 | // For tree items - you will get called when the name is requested, and it will |
51 | // have the name you registered (name) and the subtree portion (value). The |
52 | // dynbuf will be fully set up for you - just add the information you want to |
53 | // return |
54 | extern int as_info_set_tree(char *name, as_info_get_tree_fn gv_fn); |
55 | |
56 | // For commands - you will be called with the parameters. |
57 | extern int as_info_set_command(const char *name, as_info_command_fn command_fn, as_sec_perm required_perm); |
58 | |
59 | int as_info_parameter_get(char *param_str, char *param, char *value, int *value_len); |
60 | |
61 | typedef struct as_info_transaction_s { |
62 | as_file_handle *fd_h; |
63 | as_proto *proto; |
64 | uint64_t start_time; |
65 | } as_info_transaction; |
66 | |
67 | // Processes an info request that comes in from the network, sends the response. |
68 | extern void as_info(as_info_transaction *it); |
69 | |
70 | // Processes a pure puffer request without any info header stuff. |
71 | extern int as_info_buffer(uint8_t *req_buf, size_t req_buf_len, cf_dyn_buf *rsp); |
72 | |
73 | // The info unit uses the fabric to communicate with the other members of the |
74 | // cluster so it needs to register for different messages and create listener |
75 | // threads, etc. |
76 | extern int as_info_init(); |
77 | |
78 | // Needed by heartbeat: |
79 | |
80 | char *as_info_bind_to_string(const cf_serv_cfg *cfg, cf_sock_owner owner); |
81 | |
82 | // Needed by ticker: |
83 | |
84 | int as_info_queue_get_size(); |
85 | void info_log_with_datestamp(void (*log_fn)(void)); |
86 | uint32_t process_cpu(void); |
87 | void sys_cpu_info(uint32_t* user_pct, uint32_t* kernel_pct); |
88 | void sys_mem_info(uint64_t *free_mem, uint32_t *free_pct); |
89 | |
90 | extern bool g_mstats_enabled; |
91 | |
92 | // Needed by main(): |
93 | extern uint64_t g_start_sec; |
94 | |