StatsClient.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef __STATSCLIENT_H__
  18. #define __STATSCLIENT_H__
  19. #include <kopano/zcdefs.h>
  20. #include <atomic>
  21. #include <map>
  22. #include <mutex>
  23. #include <string>
  24. #include <ctime>
  25. #include <sys/socket.h>
  26. #include <sys/types.h>
  27. #include <sys/un.h>
  28. #include <kopano/ECLogger.h>
  29. namespace KC {
  30. class _kc_export StatsClient _kc_final {
  31. private:
  32. int fd = -1;
  33. struct sockaddr_un addr;
  34. int addr_len = 0;
  35. bool thread_running = false;
  36. ECLogger *const logger;
  37. pthread_t countsSubmitThread;
  38. public:
  39. std::atomic<bool> terminate{false};
  40. std::mutex mapsLock;
  41. std::map<std::string, double> countsMapDouble;
  42. std::map<std::string, int64_t> countsMapInt64;
  43. StatsClient(ECLogger *);
  44. ~StatsClient();
  45. int startup(const std::string &collector);
  46. _kc_hidden inline ECLogger *getLogger(void) { return logger; }
  47. void countInc(const std::string & key, const std::string & key_sub);
  48. _kc_hidden void countAdd(const std::string &key, const std::string &key_sub, double n);
  49. void countAdd(const std::string & key, const std::string & key_sub, const int64_t n);
  50. _kc_hidden void submit(const std::string &key, time_t ts, double value);
  51. _kc_hidden void submit(const std::string &key, time_t ts, int64_t value);
  52. };
  53. } /* namespace */
  54. #endif