writer.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <library/cpp/json/json_writer.h>
  3. namespace NMonitoring {
  4. /**
  5. * Deprecated writer of Solomon JSON format
  6. * https://wiki.yandex-team.ru/solomon/api/dataformat/json
  7. *
  8. * This writer will be deleted soon, so please consider to use
  9. * high level library library/cpp/monlib/encode which is decoupled from the
  10. * particular format.
  11. */
  12. class TDeprecatedJsonWriter {
  13. private:
  14. NJson::TJsonWriter JsonWriter;
  15. enum EState {
  16. STATE_ROOT,
  17. STATE_DOCUMENT,
  18. STATE_COMMON_LABELS,
  19. STATE_METRICS,
  20. STATE_METRIC,
  21. STATE_LABELS,
  22. };
  23. EState State;
  24. public:
  25. explicit TDeprecatedJsonWriter(IOutputStream* out);
  26. void OpenDocument();
  27. void CloseDocument();
  28. void OpenCommonLabels();
  29. void CloseCommonLabels();
  30. void WriteCommonLabel(TStringBuf name, TStringBuf value);
  31. void OpenMetrics();
  32. void CloseMetrics();
  33. void OpenMetric();
  34. void CloseMetric();
  35. void OpenLabels();
  36. void CloseLabels();
  37. void WriteLabel(TStringBuf name, TStringBuf value);
  38. template <typename... T>
  39. void WriteLabels(T... pairs) {
  40. OpenLabels();
  41. WriteLabelsInner(pairs...);
  42. CloseLabels();
  43. }
  44. void WriteModeDeriv();
  45. void WriteValue(long long value);
  46. void WriteDoubleValue(double d);
  47. void WriteTs(ui64 ts);
  48. private:
  49. void WriteLabelsInner(TStringBuf name, TStringBuf value) {
  50. WriteLabel(name, value);
  51. }
  52. template <typename... T>
  53. void WriteLabelsInner(TStringBuf name, TStringBuf value, T... pairs) {
  54. WriteLabel(name, value);
  55. WriteLabelsInner(pairs...);
  56. }
  57. inline void TransitionState(EState current, EState next);
  58. };
  59. }