| 1 |
/** |
| 2 |
* collectd - utils_cache.h |
| 3 |
* Copyright (C) 2007 Florian octo Forster |
| 4 |
* Copyright (C) 2016 Sebastian tokkee Harl |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 7 |
* copy of this software and associated documentation files (the "Software"), |
| 8 |
* to deal in the Software without restriction, including without limitation |
| 9 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 11 |
* Software is furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
* |
| 24 |
* Authors: |
| 25 |
* Florian octo Forster <octo at collectd.org> |
| 26 |
* Sebastian tokkee Harl <sh at tokkee.org> |
| 27 |
**/ |
| 28 |
|
| 29 |
#ifndef UTILS_CACHE_H |
| 30 |
#define UTILS_CACHE_H 1 |
| 31 |
|
| 32 |
#include "plugin.h" |
| 33 |
|
| 34 |
#define STATE_UNKNOWN 0 |
| 35 |
#define STATE_OKAY 1 |
| 36 |
#define STATE_WARNING 2 |
| 37 |
#define STATE_ERROR 3 |
| 38 |
#define STATE_MISSING 15 |
| 39 |
|
| 40 |
int uc_init(void); |
| 41 |
int uc_check_timeout(void); |
| 42 |
int uc_update(const data_set_t *ds, const value_list_t *vl); |
| 43 |
int uc_get_rate_by_name(const char *name, gauge_t **ret_values, |
| 44 |
size_t *ret_values_num); |
| 45 |
gauge_t *uc_get_rate(const data_set_t *ds, const value_list_t *vl); |
| 46 |
int uc_get_value_by_name(const char *name, value_t **ret_values, |
| 47 |
size_t *ret_values_num); |
| 48 |
value_t *uc_get_value(const data_set_t *ds, const value_list_t *vl); |
| 49 |
|
| 50 |
size_t uc_get_size(void); |
| 51 |
int uc_get_names(char ***ret_names, cdtime_t **ret_times, size_t *ret_number); |
| 52 |
|
| 53 |
int uc_get_state(const data_set_t *ds, const value_list_t *vl); |
| 54 |
int uc_set_state(const data_set_t *ds, const value_list_t *vl, int state); |
| 55 |
int uc_get_hits(const data_set_t *ds, const value_list_t *vl); |
| 56 |
int uc_set_hits(const data_set_t *ds, const value_list_t *vl, int hits); |
| 57 |
int uc_inc_hits(const data_set_t *ds, const value_list_t *vl, int step); |
| 58 |
|
| 59 |
int uc_set_callbacks_mask(const char *name, unsigned long callbacks_mask); |
| 60 |
|
| 61 |
int uc_get_history(const data_set_t *ds, const value_list_t *vl, |
| 62 |
gauge_t *ret_history, size_t num_steps, size_t num_ds); |
| 63 |
int uc_get_history_by_name(const char *name, gauge_t *ret_history, |
| 64 |
size_t num_steps, size_t num_ds); |
| 65 |
|
| 66 |
/* |
| 67 |
* Iterator interface |
| 68 |
*/ |
| 69 |
struct uc_iter_s; |
| 70 |
typedef struct uc_iter_s uc_iter_t; |
| 71 |
|
| 72 |
/* |
| 73 |
* NAME |
| 74 |
* uc_get_iterator |
| 75 |
* |
| 76 |
* DESCRIPTION |
| 77 |
* Create an iterator for the cache. It will hold the cache lock until it's |
| 78 |
* destroyed. |
| 79 |
* |
| 80 |
* RETURN VALUE |
| 81 |
* An iterator object on success or NULL else. |
| 82 |
*/ |
| 83 |
uc_iter_t *uc_get_iterator(void); |
| 84 |
|
| 85 |
/* |
| 86 |
* NAME |
| 87 |
* uc_iterator_next |
| 88 |
* |
| 89 |
* DESCRIPTION |
| 90 |
* Advance the iterator to the next positiion and (optionally) returns the |
| 91 |
* name of the entry. |
| 92 |
* |
| 93 |
* PARAMETERS |
| 94 |
* `iter' The iterator object to advance. |
| 95 |
* `ret_name' Optional pointer to a string where to store the name. If not |
| 96 |
* NULL, the returned value is a copy of the value and has to be |
| 97 |
* freed by the caller. |
| 98 |
* |
| 99 |
* RETURN VALUE |
| 100 |
* Zero upon success or non-zero if the iterator ie NULL or no further |
| 101 |
* values are available. |
| 102 |
*/ |
| 103 |
int uc_iterator_next(uc_iter_t *iter, char **ret_name); |
| 104 |
void uc_iterator_destroy(uc_iter_t *iter); |
| 105 |
|
| 106 |
/* Return the timestamp of the value at the current position. */ |
| 107 |
int uc_iterator_get_time(uc_iter_t *iter, cdtime_t *ret_time); |
| 108 |
/* Return the (raw) value at the current position. */ |
| 109 |
int uc_iterator_get_values(uc_iter_t *iter, value_t **ret_values, |
| 110 |
size_t *ret_num); |
| 111 |
/* Return the interval of the value at the current position. */ |
| 112 |
int uc_iterator_get_interval(uc_iter_t *iter, cdtime_t *ret_interval); |
| 113 |
/* Return the metadata for the value at the current position. */ |
| 114 |
int uc_iterator_get_meta(uc_iter_t *iter, meta_data_t **ret_meta); |
| 115 |
|
| 116 |
/* |
| 117 |
* Meta data interface |
| 118 |
*/ |
| 119 |
int uc_meta_data_exists(const value_list_t *vl, const char *key); |
| 120 |
int uc_meta_data_delete(const value_list_t *vl, const char *key); |
| 121 |
/* Same API as meta_data_toc. */ |
| 122 |
int uc_meta_data_toc(const value_list_t *vl, char ***toc); |
| 123 |
|
| 124 |
int uc_meta_data_add_string(const value_list_t *vl, const char *key, |
| 125 |
const char *value); |
| 126 |
int uc_meta_data_add_signed_int(const value_list_t *vl, const char *key, |
| 127 |
int64_t value); |
| 128 |
int uc_meta_data_add_unsigned_int(const value_list_t *vl, const char *key, |
| 129 |
uint64_t value); |
| 130 |
int uc_meta_data_add_double(const value_list_t *vl, const char *key, |
| 131 |
double value); |
| 132 |
int uc_meta_data_add_boolean(const value_list_t *vl, const char *key, |
| 133 |
bool value); |
| 134 |
|
| 135 |
int uc_meta_data_get_string(const value_list_t *vl, const char *key, |
| 136 |
char **value); |
| 137 |
int uc_meta_data_get_signed_int(const value_list_t *vl, const char *key, |
| 138 |
int64_t *value); |
| 139 |
int uc_meta_data_get_unsigned_int(const value_list_t *vl, const char *key, |
| 140 |
uint64_t *value); |
| 141 |
int uc_meta_data_get_double(const value_list_t *vl, const char *key, |
| 142 |
double *value); |
| 143 |
int uc_meta_data_get_boolean(const value_list_t *vl, const char *key, |
| 144 |
bool *value); |
| 145 |
|
| 146 |
#endif /* !UTILS_CACHE_H */ |