emqx_dashboard.hrl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -define(ADMIN, emqx_admin).
  17. %% TODO:
  18. %% The predefined roles of the preliminary RBAC implementation,
  19. %% these may be removed when developing the full RBAC feature.
  20. %% In full RBAC feature, the role may be customised created and deleted,
  21. %% a predefined configuration would replace these macros.
  22. -define(ROLE_VIEWER, <<"viewer">>).
  23. -define(ROLE_SUPERUSER, <<"administrator">>).
  24. -define(ROLE_DEFAULT, ?ROLE_SUPERUSER).
  25. -define(BACKEND_LOCAL, local).
  26. -define(SSO_USERNAME(Backend, Name), {Backend, Name}).
  27. -type dashboard_sso_backend() :: atom().
  28. -type dashboard_sso_username() :: {dashboard_sso_backend(), binary()}.
  29. -type dashboard_username() :: binary() | dashboard_sso_username().
  30. -type dashboard_user_role() :: binary().
  31. -record(?ADMIN, {
  32. username :: dashboard_username(),
  33. pwdhash :: binary(),
  34. description :: binary(),
  35. role = ?ROLE_DEFAULT :: dashboard_user_role(),
  36. extra = #{} :: map()
  37. }).
  38. -type dashboard_user() :: #?ADMIN{}.
  39. -define(ADMIN_JWT, emqx_admin_jwt).
  40. -record(?ADMIN_JWT, {
  41. token :: binary(),
  42. username :: binary(),
  43. exptime :: integer(),
  44. extra = #{} :: map()
  45. }).
  46. -define(TAB_COLLECT, emqx_collect).
  47. -define(EMPTY_KEY(Key), ((Key == undefined) orelse (Key == <<>>))).
  48. -define(DASHBOARD_SHARD, emqx_dashboard_shard).
  49. -ifdef(TEST).
  50. %% for test
  51. -define(DEFAULT_SAMPLE_INTERVAL, 1).
  52. -define(RPC_TIMEOUT, 50).
  53. -else.
  54. %% dashboard monitor do sample interval, default 10s
  55. -define(DEFAULT_SAMPLE_INTERVAL, 10).
  56. -define(RPC_TIMEOUT, 5000).
  57. -endif.
  58. -define(DELTA_SAMPLER_LIST, [
  59. received,
  60. %, received_bytes
  61. sent,
  62. %, sent_bytes
  63. dropped
  64. ]).
  65. -define(GAUGE_SAMPLER_LIST, [
  66. subscriptions,
  67. topics,
  68. connections,
  69. live_connections
  70. ]).
  71. -define(SAMPLER_LIST, ?GAUGE_SAMPLER_LIST ++ ?DELTA_SAMPLER_LIST).
  72. -define(DELTA_SAMPLER_RATE_MAP, #{
  73. received => received_msg_rate,
  74. %% In 5.0.0, temporarily comment it to suppress bytes rate
  75. %received_bytes => received_bytes_rate,
  76. %sent_bytes => sent_bytes_rate,
  77. sent => sent_msg_rate,
  78. dropped => dropped_msg_rate
  79. }).