You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

n9e.sql 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. set names utf8;
  2. drop database if exists n9e;
  3. create database n9e;
  4. use n9e;
  5. CREATE TABLE `user` (
  6. `id` bigint unsigned not null auto_increment,
  7. `username` varchar(64) not null comment 'login name, cannot rename',
  8. `nickname` varchar(64) not null comment 'display name, chinese name',
  9. `password` varchar(128) not null,
  10. `phone` varchar(16) not null default '',
  11. `email` varchar(64) not null default '',
  12. `portrait` varchar(255) not null default '' comment 'portrait image url',
  13. `status` tinyint(1) not null default 0 comment '0: active, 1: disabled',
  14. `role` varchar(32) not null comment 'Admin | Standard | Guest',
  15. `contacts` varchar(1024) default '' comment 'json e.g. {wecom:xx, dingtalk_robot_token:yy}',
  16. `create_at` bigint not null default 0,
  17. `create_by` varchar(64) not null default '',
  18. `update_at` bigint not null default 0,
  19. `update_by` varchar(64) not null default '',
  20. PRIMARY KEY (`id`),
  21. UNIQUE KEY (`username`)
  22. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  23. CREATE TABLE `user_token` (
  24. `user_id` bigint unsigned not null,
  25. `username` varchar(64) not null,
  26. `token` varchar(128) not null,
  27. KEY (`user_id`),
  28. KEY (`username`),
  29. UNIQUE KEY (`token`)
  30. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  31. CREATE TABLE `user_group` (
  32. `id` bigint unsigned not null auto_increment,
  33. `name` varchar(128) not null default '',
  34. `note` varchar(255) not null default '',
  35. `create_at` bigint not null default 0,
  36. `create_by` varchar(64) not null default '',
  37. `update_at` bigint not null default 0,
  38. `update_by` varchar(64) not null default '',
  39. PRIMARY KEY (`id`),
  40. KEY (`create_by`)
  41. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  42. CREATE TABLE `user_group_member` (
  43. `group_id` bigint unsigned not null,
  44. `user_id` bigint unsigned not null,
  45. KEY (`group_id`),
  46. KEY (`user_id`)
  47. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  48. CREATE TABLE `configs` (
  49. `id` bigint unsigned not null auto_increment,
  50. `ckey` varchar(255) not null,
  51. `cval` varchar(1024) not null default '',
  52. PRIMARY KEY (`id`),
  53. UNIQUE KEY (`ckey`)
  54. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  55. CREATE TABLE `role` (
  56. `id` bigint unsigned not null auto_increment,
  57. `name` varchar(128) not null default '',
  58. `note` varchar(255) not null default '',
  59. PRIMARY KEY (`id`),
  60. UNIQUE KEY (`name`)
  61. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  62. insert into `role`(name, note) values('Admin', 'Administrator role');
  63. insert into `role`(name, note) values('Standard', 'Ordinary user role');
  64. insert into `role`(name, note) values('Guest', 'Readonly user role');
  65. CREATE TABLE `role_operation`(
  66. `role_name` varchar(128) not null,
  67. `operation` varchar(255) not null,
  68. KEY (`role_name`),
  69. KEY (`operation`)
  70. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  71. -- Admin is special, who has no concrete operation but can do anything.
  72. insert into `role_operation`(role_name, operation) values('Standard', 'classpath_create');
  73. insert into `role_operation`(role_name, operation) values('Standard', 'classpath_modify');
  74. insert into `role_operation`(role_name, operation) values('Standard', 'classpath_delete');
  75. insert into `role_operation`(role_name, operation) values('Standard', 'classpath_add_resource');
  76. insert into `role_operation`(role_name, operation) values('Standard', 'classpath_del_resource');
  77. insert into `role_operation`(role_name, operation) values('Standard', 'metric_description_create');
  78. insert into `role_operation`(role_name, operation) values('Standard', 'metric_description_modify');
  79. insert into `role_operation`(role_name, operation) values('Standard', 'metric_description_delete');
  80. insert into `role_operation`(role_name, operation) values('Standard', 'mute_create');
  81. insert into `role_operation`(role_name, operation) values('Standard', 'mute_delete');
  82. insert into `role_operation`(role_name, operation) values('Standard', 'dashboard_create');
  83. insert into `role_operation`(role_name, operation) values('Standard', 'dashboard_modify');
  84. insert into `role_operation`(role_name, operation) values('Standard', 'dashboard_delete');
  85. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_group_create');
  86. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_group_modify');
  87. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_group_delete');
  88. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_create');
  89. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_modify');
  90. insert into `role_operation`(role_name, operation) values('Standard', 'alert_rule_delete');
  91. insert into `role_operation`(role_name, operation) values('Standard', 'alert_event_delete');
  92. insert into `role_operation`(role_name, operation) values('Standard', 'collect_rule_create');
  93. insert into `role_operation`(role_name, operation) values('Standard', 'collect_rule_modify');
  94. insert into `role_operation`(role_name, operation) values('Standard', 'collect_rule_delete');
  95. insert into `role_operation`(role_name, operation) values('Standard', 'resource_modify');
  96. CREATE TABLE `instance` (
  97. `service` varchar(128) not null,
  98. `endpoint` varchar(255) not null comment 'ip:port',
  99. `clock` datetime not null,
  100. KEY (`service`)
  101. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  102. -- if mute_etime < now(), the two mute columns should be reset to 0
  103. CREATE TABLE `resource` (
  104. `id` bigint unsigned not null auto_increment,
  105. `ident` varchar(255) not null,
  106. `alias` varchar(128) not null default '' comment 'auto detect, just for debug',
  107. `tags` varchar(512) not null default '' comment 'will append to event',
  108. `note` varchar(255) not null default '',
  109. `mute_btime` bigint not null default 0 comment 'mute begin time',
  110. `mute_etime` bigint not null default 0 comment 'mute end time',
  111. PRIMARY KEY (`id`),
  112. UNIQUE KEY (`ident`)
  113. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  114. CREATE TABLE `classpath` (
  115. `id` bigint unsigned not null auto_increment,
  116. `path` varchar(512) not null comment 'required. e.g. duokan.tv.engine.x.y.z',
  117. `note` varchar(255) not null default '',
  118. `preset` tinyint(1) not null default 0 comment 'if preset, cannot delete and modify',
  119. `create_at` bigint not null default 0,
  120. `create_by` varchar(64) not null default '',
  121. `update_at` bigint not null default 0,
  122. `update_by` varchar(64) not null default '',
  123. PRIMARY KEY (`id`),
  124. KEY (`path`)
  125. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  126. -- new resource will bind classpath(id=1) automatically
  127. insert into classpath(id, path, note, preset, create_by, update_by, create_at, update_at) values(1, 'all', 'preset classpath, all resources belong to', 1, 'system', 'system', unix_timestamp(now()), unix_timestamp(now()));
  128. CREATE TABLE `classpath_resource` (
  129. `id` bigint unsigned not null auto_increment,
  130. `classpath_id` bigint unsigned not null,
  131. `res_ident` varchar(255) not null,
  132. PRIMARY KEY (`id`),
  133. KEY (`classpath_id`),
  134. KEY (`res_ident`)
  135. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  136. CREATE TABLE `classpath_favorite` (
  137. `id` bigint unsigned not null auto_increment,
  138. `classpath_id` bigint not null,
  139. `user_id` bigint not null,
  140. PRIMARY KEY (`id`),
  141. KEY (`user_id`)
  142. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  143. CREATE TABLE `mute` (
  144. `id` bigint unsigned not null auto_increment,
  145. `metric` varchar(255) not null comment 'required',
  146. `res_filters` varchar(4096) not null default 'resource filters',
  147. `tag_filters` varchar(8192) not null default '',
  148. `cause` varchar(255) not null default '',
  149. `btime` bigint not null default 0 comment 'begin time',
  150. `etime` bigint not null default 0 comment 'end time',
  151. `create_at` bigint not null default 0,
  152. `create_by` varchar(64) not null default '',
  153. PRIMARY KEY (`id`),
  154. KEY (`metric`),
  155. KEY (`create_by`)
  156. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  157. CREATE TABLE `dashboard` (
  158. `id` bigint unsigned not null auto_increment,
  159. `name` varchar(255) not null,
  160. `tags` varchar(255) not null,
  161. `configs` varchar(4096) comment 'dashboard variables',
  162. `create_at` bigint not null default 0,
  163. `create_by` varchar(64) not null default '',
  164. `update_at` bigint not null default 0,
  165. `update_by` varchar(64) not null default '',
  166. PRIMARY KEY (`id`),
  167. UNIQUE KEY (`name`)
  168. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  169. CREATE TABLE `dashboard_favorite` (
  170. `id` bigint unsigned not null auto_increment,
  171. `dashboard_id` bigint not null comment 'dashboard id',
  172. `user_id` bigint not null comment 'user id',
  173. PRIMARY KEY (`id`),
  174. KEY (`user_id`)
  175. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  176. -- auto create the first subclass 'Default chart group' of dashboard
  177. CREATE TABLE `chart_group` (
  178. `id` bigint unsigned not null auto_increment,
  179. `dashboard_id` bigint unsigned not null,
  180. `name` varchar(255) not null,
  181. `weight` int not null default 0,
  182. PRIMARY KEY (`id`),
  183. KEY (`dashboard_id`)
  184. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  185. CREATE TABLE `chart` (
  186. `id` bigint unsigned not null auto_increment,
  187. `group_id` bigint unsigned not null comment 'chart group id',
  188. `configs` varchar(8192),
  189. `weight` int not null default 0,
  190. PRIMARY KEY (`id`),
  191. KEY (`group_id`)
  192. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  193. CREATE TABLE `chart_tmp` (
  194. `id` bigint unsigned not null auto_increment,
  195. `configs` varchar(8192),
  196. `create_at` bigint not null default 0,
  197. `create_by` varchar(64) not null default '',
  198. primary key (`id`)
  199. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  200. CREATE TABLE `collect_rule` (
  201. `id` bigint unsigned not null auto_increment,
  202. `classpath_id` bigint not null,
  203. `prefix_match` tinyint(1) not null default 0 comment '0: no 1: yes',
  204. `name` varchar(255) not null default '',
  205. `note` varchar(255) not null default '',
  206. `step` int not null,
  207. `type` varchar(64) not null comment 'e.g. port proc log plugin mysql',
  208. `data` text not null,
  209. `append_tags` varchar(255) not null default '' comment 'e.g. mod=n9e',
  210. `create_at` bigint not null default 0,
  211. `create_by` varchar(64) not null default '',
  212. `update_at` bigint not null default 0,
  213. `update_by` varchar(64) not null default '',
  214. PRIMARY KEY (`id`),
  215. KEY (`classpath_id`, `type`),
  216. KEY (`name`)
  217. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  218. CREATE TABLE `alert_rule_group` (
  219. `id` bigint unsigned not null auto_increment,
  220. `name` varchar(255) not null,
  221. `user_group_ids` varchar(255) not null default '' comment 'readwrite user group ids',
  222. `create_at` bigint not null default 0,
  223. `create_by` varchar(64) not null default '',
  224. `update_at` bigint not null default 0,
  225. `update_by` varchar(64) not null default '',
  226. PRIMARY KEY (`id`),
  227. UNIQUE KEY (`name`)
  228. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  229. insert into alert_rule_group(name,create_at,create_by,update_at,update_by) values('Default Rule Group', unix_timestamp(now()), 'system', unix_timestamp(now()), 'system');
  230. CREATE TABLE `alert_rule_group_favorite` (
  231. `id` bigint unsigned not null auto_increment,
  232. `group_id` bigint not null comment 'alert_rule group id',
  233. `user_id` bigint not null comment 'user id',
  234. PRIMARY KEY (`id`),
  235. KEY (`user_id`)
  236. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  237. CREATE TABLE `alert_rule` (
  238. `id` bigint unsigned not null auto_increment,
  239. `group_id` bigint not null default 0 comment 'alert_rule group id',
  240. `name` varchar(255) not null,
  241. `note` varchar(255) not null,
  242. `type` tinyint(1) not null comment '0 n9e 1 promql',
  243. `status` tinyint(1) not null comment '0 enable 1 disable',
  244. `alert_duration` int not null comment 'unit:s',
  245. `expression` varchar(4096) not null comment 'rule expression',
  246. `enable_stime` char(5) not null default '00:00',
  247. `enable_etime` char(5) not null default '23:59',
  248. `enable_days_of_week` varchar(32) not null default '' comment 'split by space: 0 1 2 3 4 5 6',
  249. `recovery_notify` tinyint(1) not null comment 'whether notify when recovery',
  250. `priority` tinyint(1) not null,
  251. `notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
  252. `notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',
  253. `notify_users` varchar(255) not null default '' comment 'split by space: 2 5',
  254. `callbacks` varchar(255) not null default '' comment 'split by space: http://a.com/api/x http://a.com/api/y',
  255. `runbook_url` varchar(255),
  256. `append_tags` varchar(255) not null default '' comment 'split by space: service=n9e mod=api',
  257. `create_at` bigint not null default 0,
  258. `create_by` varchar(64) not null default '',
  259. `update_at` bigint not null default 0,
  260. `update_by` varchar(64) not null default '',
  261. PRIMARY KEY (`id`),
  262. KEY (`group_id`)
  263. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  264. CREATE TABLE `alert_event` (
  265. `id` bigint unsigned not null auto_increment,
  266. `hash_id` varchar(255) not null comment 'rule_id + point_pk',
  267. `rule_id` bigint unsigned not null,
  268. `rule_name` varchar(255) not null,
  269. `rule_note` varchar(512) not null default 'alert rule note',
  270. `res_classpaths` varchar(1024) not null default '' comment 'belong classpaths',
  271. `priority` tinyint(1) not null,
  272. `status` tinyint(1) not null,
  273. `is_prome_pull` tinyint(1) not null,
  274. `history_points` text comment 'metric, history points',
  275. `trigger_time` bigint not null,
  276. `notify_channels` varchar(255) not null default '',
  277. `notify_groups` varchar(255) not null default '',
  278. `notify_users` varchar(255) not null default '',
  279. `runbook_url` varchar(255),
  280. `readable_expression` varchar(1024) not null comment 'e.g. mem.bytes.used.percent(all,60s) > 0',
  281. `tags` varchar(1024) not null default 'merge data_tags rule_tags and res_tags',
  282. PRIMARY KEY (`id`),
  283. KEY (`hash_id`),
  284. KEY (`rule_id`),
  285. KEY (`trigger_time`)
  286. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  287. CREATE TABLE `metric_description` (
  288. `id` bigint unsigned not null auto_increment,
  289. `metric` varchar(255) not null default '',
  290. `description` varchar(255) not null default '',
  291. PRIMARY KEY (`id`),
  292. UNIQUE KEY (`metric`)
  293. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  294. insert into metric_description(metric, description) values('system_cpu_idle', '系统总体CPU空闲率(单位:%)');
  295. insert into metric_description(metric, description) values('system_cpu_util', '系统总体CPU使用率(单位:%)');