1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 Kern Sibbald 5 6 The original author of Bacula is Kern Sibbald, with contributions 7 from many others, a complete list can be found in the file AUTHORS. 8 9 You may use this file and others of this release according to the 10 license defined in the LICENSE file, which includes the Affero General 11 Public License, v3.0 ("AGPLv3") and some additional permissions and 12 terms pursuant to its AGPLv3 Section 7. 13 14 This notice must be preserved when any source code is 15 conveyed and/or propagated. 16 17 Bacula(R) is a registered trademark of Kern Sibbald. 18 */ 19 /* 20 * Radosław Korzeniewski, MMXVIII 21 * radoslaw@korzeniewski.net, radekk@inteos.pl 22 * Inteos Sp. z o.o. http://www.inteos.pl/ 23 * 24 * This is a Bacula statistics internal collector thread. 25 * Author: Radosław Korzeniewski, radekk@inteos.pl, Inteos Sp. z o.o. 26 */ 27 28 #ifndef __BCOLLECTOR_H_ 29 #define __BCOLLECTOR_H_ 30 31 /* Supported backend types */ 32 enum { 33 COLLECTOR_BACKEND_Undef = 0, 34 COLLECTOR_BACKEND_CSV, 35 COLLECTOR_BACKEND_Graphite, 36 }; 37 38 /* spooling status for supported backends */ 39 enum { 40 BCOLLECT_SPOOL_UNK, 41 BCOLLECT_SPOOL_YES, 42 BCOLLECT_SPOOL_NO, 43 BCOLLECT_SPOOL_DESPOOL, 44 }; 45 46 /* forward reference only */ 47 class COLLECTOR; 48 class OutputWriter; 49 50 class UPDATECOLLECTOR: public SMARTALLOC { 51 public: 52 utime_t interval; /* interval in seconds between metrics collection */ 53 utime_t lastupdate; /* when last update */ 54 pthread_t thid; /* thread id for collector thread */ 55 pthread_mutex_t mutex; /* when accessing collector resource data you should lock it first */ 56 bool valid; /* when set to false the collector thread should involuntary exit */ 57 bool running; /* show if the background update thread is running */ 58 void *data; /* data parameter for thread routine */ 59 bool (*routine)(void *data); /* routine for update collector thread */ 60 JCR *jcr; 61 public: 62 /* Methods */ 63 char *name() const; 64 void lock(); 65 void unlock(); 66 UPDATECOLLECTOR(); 67 ~UPDATECOLLECTOR(); 68 }; 69 70 typedef struct { 71 JCR *jcr; 72 utime_t interval; 73 void *data; 74 bool (*routine)(void *data); 75 } UPDATE_COLLECTOR_INIT_t; 76 77 void start_collector_thread(COLLECTOR *collector); 78 void stop_collector_thread(COLLECTOR *collector); 79 void start_updcollector_thread(UPDATE_COLLECTOR_INIT_t &initdata); 80 void stop_updcollector_thread(); 81 void dump_collector_resource(COLLECTOR &res_collector, void sendit(void *sock, const char *fmt, ...), void *sock); 82 void free_collector_resource(COLLECTOR &res_collector); 83 int render_updcollector_status(POOL_MEM &buf); 84 void api_render_updcollector_status(OutputWriter &ow); 85 86 #endif /* __BCOLLECTOR_H_ */ 87