| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | /* container_docker.h -- a library for checking sysfs for Docker exposed metrics |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation, either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | |
| 17 | #ifndef _CONTAINER_DOCKER_H |
| 18 | #define _CONTAINER_DOCKER_H |
| 19 | |
| 20 | #include "system.h" |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" |
| 24 | { |
| 25 | #endif |
| 26 | |
| 27 | typedef struct chunk |
| 28 | { |
| 29 | char *memory; |
| 30 | size_t size; |
| 31 | } chunk_t; |
| 32 | |
| 33 | struct docker_memory_desc; |
| 34 | |
| 35 | /* Allocates space for a new docker_memory_desc object. |
| 36 | * Returns 0 if all went ok. Errors are returned as negative values. */ |
| 37 | int docker_memory_desc_new (struct docker_memory_desc **memdesc); |
| 38 | |
| 39 | /* Fill the docker_memory_desc structure pointed with the values found in the |
| 40 | * sysfs filesystem. */ |
| 41 | void docker_memory_desc_read (struct docker_memory_desc *__restrict |
| 42 | memdesc); |
| 43 | |
| 44 | /* Drop a reference of the docker_memory_desc library context. If the refcount |
| 45 | * of reaches zero, the resources of the context will be released. */ |
| 46 | struct docker_memory_desc |
| 47 | *docker_memory_desc_unref (struct docker_memory_desc *memdesc); |
| 48 | |
| 49 | /* Accessing the values from docker_memory_desc */ |
| 50 | |
| 51 | /* Return the number of bytes of page cache memory. */ |
| 52 | long long docker_memory_get_total_cache ( |
| 53 | struct docker_memory_desc *memdesc); |
| 54 | |
| 55 | /* Return the number of bytes of anonymous and swap cache memory |
| 56 | * (includes transparent hugepages). */ |
| 57 | long long docker_memory_get_total_rss ( |
| 58 | struct docker_memory_desc *memdesc); |
| 59 | |
| 60 | /* Return the number of bytes of swap usage. */ |
| 61 | long long docker_memory_get_total_swap ( |
| 62 | struct docker_memory_desc *memdesc); |
| 63 | |
| 64 | /* Return the number of bytes of bytes of memory that cannot be reclaimed |
| 65 | * (mlocked etc). */ |
| 66 | long long docker_memory_get_total_unevictable ( |
| 67 | struct docker_memory_desc *memdesc); |
| 68 | |
| 69 | /* Additional metrics that may be valuable in investigating performance or |
| 70 | * stability issues include page faults, which can represent either |
| 71 | * segmentation faults or fetching data from disk instead of memory |
| 72 | * (pgfault and pgmajfault, respectively). */ |
| 73 | long long docker_memory_get_total_pgfault ( |
| 74 | struct docker_memory_desc *memdesc); |
| 75 | long long docker_memory_get_total_pgmajfault ( |
| 76 | struct docker_memory_desc *memdesc); |
| 77 | |
| 78 | long long docker_memory_get_total_pgpgin ( |
| 79 | struct docker_memory_desc *memdesc); |
| 80 | long long docker_memory_get_total_pgpgout ( |
| 81 | struct docker_memory_desc *memdesc); |
| 82 | |
| 83 | int docker_running_containers (char *socket, unsigned int *count, |
| 84 | const char *image, char **perfdata, |
| 85 | bool verbose); |
| 86 | int docker_running_containers_memory (char *socket, |
| 87 | long long unsigned int *memory, |
| 88 | bool verbose); |
| 89 | |
| 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | #endif /* _CONTAINER_DOCKER_H */ |