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 30 kB

4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. set names utf8mb4;
  2. drop database if exists n9e_v6;
  3. create database n9e_v6;
  4. use n9e_v6;
  5. CREATE TABLE `users` (
  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 default '',
  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. `roles` varchar(255) not null comment 'Admin | Standard | Guest, split by space',
  14. `contacts` varchar(1024) comment 'json e.g. {wecom:xx, dingtalk_robot_token:yy}',
  15. `maintainer` tinyint(1) not null default 0,
  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 = utf8mb4;
  23. insert into `users`(id, username, nickname, password, roles, create_at, create_by, update_at, update_by) values(1, 'root', '超管', 'root.2020', 'Admin', unix_timestamp(now()), 'system', unix_timestamp(now()), 'system');
  24. CREATE TABLE `user_group` (
  25. `id` bigint unsigned not null auto_increment,
  26. `name` varchar(128) not null default '',
  27. `note` varchar(255) not null default '',
  28. `create_at` bigint not null default 0,
  29. `create_by` varchar(64) not null default '',
  30. `update_at` bigint not null default 0,
  31. `update_by` varchar(64) not null default '',
  32. PRIMARY KEY (`id`),
  33. KEY (`create_by`),
  34. KEY (`update_at`)
  35. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  36. insert into user_group(id, name, create_at, create_by, update_at, update_by) values(1, 'demo-root-group', unix_timestamp(now()), 'root', unix_timestamp(now()), 'root');
  37. CREATE TABLE `user_group_member` (
  38. `id` bigint unsigned not null auto_increment,
  39. `group_id` bigint unsigned not null,
  40. `user_id` bigint unsigned not null,
  41. KEY (`group_id`),
  42. KEY (`user_id`),
  43. PRIMARY KEY(`id`)
  44. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  45. insert into user_group_member(group_id, user_id) values(1, 1);
  46. CREATE TABLE `configs` (
  47. `id` bigint unsigned not null auto_increment,
  48. `ckey` varchar(191) not null,
  49. `cval` varchar(4096) not null default '',
  50. PRIMARY KEY (`id`),
  51. UNIQUE KEY (`ckey`)
  52. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  53. CREATE TABLE `role` (
  54. `id` bigint unsigned not null auto_increment,
  55. `name` varchar(191) not null default '',
  56. `note` varchar(255) not null default '',
  57. PRIMARY KEY (`id`),
  58. UNIQUE KEY (`name`)
  59. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  60. insert into `role`(name, note) values('Admin', 'Administrator role');
  61. insert into `role`(name, note) values('Standard', 'Ordinary user role');
  62. insert into `role`(name, note) values('Guest', 'Readonly user role');
  63. CREATE TABLE `role_operation`(
  64. `id` bigint unsigned not null auto_increment,
  65. `role_name` varchar(128) not null,
  66. `operation` varchar(191) not null,
  67. KEY (`role_name`),
  68. KEY (`operation`),
  69. PRIMARY KEY(`id`)
  70. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  71. -- Admin is special, who has no concrete operation but can do anything.
  72. insert into `role_operation`(role_name, operation) values('Guest', '/metric/explorer');
  73. insert into `role_operation`(role_name, operation) values('Guest', '/object/explorer');
  74. insert into `role_operation`(role_name, operation) values('Guest', '/log/explorer');
  75. insert into `role_operation`(role_name, operation) values('Guest', '/trace/explorer');
  76. insert into `role_operation`(role_name, operation) values('Guest', '/help/version');
  77. insert into `role_operation`(role_name, operation) values('Guest', '/help/contact');
  78. insert into `role_operation`(role_name, operation) values('Standard', '/metric/explorer');
  79. insert into `role_operation`(role_name, operation) values('Standard', '/object/explorer');
  80. insert into `role_operation`(role_name, operation) values('Standard', '/log/explorer');
  81. insert into `role_operation`(role_name, operation) values('Standard', '/trace/explorer');
  82. insert into `role_operation`(role_name, operation) values('Standard', '/help/version');
  83. insert into `role_operation`(role_name, operation) values('Standard', '/help/contact');
  84. insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules-built-in');
  85. insert into `role_operation`(role_name, operation) values('Standard', '/dashboards-built-in');
  86. insert into `role_operation`(role_name, operation) values('Standard', '/trace/dependencies');
  87. insert into `role_operation`(role_name, operation) values('Standard', '/users');
  88. insert into `role_operation`(role_name, operation) values('Standard', '/user-groups');
  89. insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/add');
  90. insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/put');
  91. insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/del');
  92. insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups');
  93. insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/add');
  94. insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/put');
  95. insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/del');
  96. insert into `role_operation`(role_name, operation) values('Standard', '/targets');
  97. insert into `role_operation`(role_name, operation) values('Standard', '/targets/add');
  98. insert into `role_operation`(role_name, operation) values('Standard', '/targets/put');
  99. insert into `role_operation`(role_name, operation) values('Standard', '/targets/del');
  100. insert into `role_operation`(role_name, operation) values('Standard', '/dashboards');
  101. insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/add');
  102. insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/put');
  103. insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/del');
  104. insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules');
  105. insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/add');
  106. insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/put');
  107. insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/del');
  108. insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes');
  109. insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes/add');
  110. insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes/del');
  111. insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes');
  112. insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/add');
  113. insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/put');
  114. insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/del');
  115. insert into `role_operation`(role_name, operation) values('Standard', '/alert-cur-events');
  116. insert into `role_operation`(role_name, operation) values('Standard', '/alert-cur-events/del');
  117. insert into `role_operation`(role_name, operation) values('Standard', '/alert-his-events');
  118. insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls');
  119. insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/add');
  120. insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/put');
  121. insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/del');
  122. insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks');
  123. insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks/add');
  124. insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks/put');
  125. insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules');
  126. insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/add');
  127. insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/put');
  128. insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/del');
  129. -- for alert_rule | collect_rule | mute | dashboard grouping
  130. CREATE TABLE `busi_group` (
  131. `id` bigint unsigned not null auto_increment,
  132. `name` varchar(191) not null,
  133. `label_enable` tinyint(1) not null default 0,
  134. `label_value` varchar(191) not null default '' comment 'if label_enable: label_value can not be blank',
  135. `create_at` bigint not null default 0,
  136. `create_by` varchar(64) not null default '',
  137. `update_at` bigint not null default 0,
  138. `update_by` varchar(64) not null default '',
  139. PRIMARY KEY (`id`),
  140. UNIQUE KEY (`name`)
  141. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  142. insert into busi_group(id, name, create_at, create_by, update_at, update_by) values(1, 'Default Busi Group', unix_timestamp(now()), 'root', unix_timestamp(now()), 'root');
  143. CREATE TABLE `busi_group_member` (
  144. `id` bigint unsigned not null auto_increment,
  145. `busi_group_id` bigint not null comment 'busi group id',
  146. `user_group_id` bigint not null comment 'user group id',
  147. `perm_flag` char(2) not null comment 'ro | rw',
  148. PRIMARY KEY (`id`),
  149. KEY (`busi_group_id`),
  150. KEY (`user_group_id`)
  151. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  152. insert into busi_group_member(busi_group_id, user_group_id, perm_flag) values(1, 1, "rw");
  153. -- for dashboard new version
  154. CREATE TABLE `board` (
  155. `id` bigint unsigned not null auto_increment,
  156. `group_id` bigint not null default 0 comment 'busi group id',
  157. `name` varchar(191) not null,
  158. `ident` varchar(200) not null default '',
  159. `tags` varchar(255) not null comment 'split by space',
  160. `public` tinyint(1) not null default 0 comment '0:false 1:true',
  161. `built_in` tinyint(1) not null default 0 comment '0:false 1:true',
  162. `hide` tinyint(1) not null default 0 comment '0:false 1:true',
  163. `create_at` bigint not null default 0,
  164. `create_by` varchar(64) not null default '',
  165. `update_at` bigint not null default 0,
  166. `update_by` varchar(64) not null default '',
  167. PRIMARY KEY (`id`),
  168. UNIQUE KEY (`group_id`, `name`),
  169. KEY(`ident`)
  170. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  171. -- for dashboard new version
  172. CREATE TABLE `board_payload` (
  173. `id` bigint unsigned not null comment 'dashboard id',
  174. `payload` mediumtext not null,
  175. UNIQUE KEY (`id`)
  176. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  177. -- deprecated
  178. CREATE TABLE `dashboard` (
  179. `id` bigint unsigned not null auto_increment,
  180. `group_id` bigint not null default 0 comment 'busi group id',
  181. `name` varchar(191) not null,
  182. `tags` varchar(255) not null comment 'split by space',
  183. `configs` varchar(8192) comment 'dashboard variables',
  184. `create_at` bigint not null default 0,
  185. `create_by` varchar(64) not null default '',
  186. `update_at` bigint not null default 0,
  187. `update_by` varchar(64) not null default '',
  188. PRIMARY KEY (`id`),
  189. UNIQUE KEY (`group_id`, `name`)
  190. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  191. -- deprecated
  192. -- auto create the first subclass 'Default chart group' of dashboard
  193. CREATE TABLE `chart_group` (
  194. `id` bigint unsigned not null auto_increment,
  195. `dashboard_id` bigint unsigned not null,
  196. `name` varchar(255) not null,
  197. `weight` int not null default 0,
  198. PRIMARY KEY (`id`),
  199. KEY (`dashboard_id`)
  200. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  201. -- deprecated
  202. CREATE TABLE `chart` (
  203. `id` bigint unsigned not null auto_increment,
  204. `group_id` bigint unsigned not null comment 'chart group id',
  205. `configs` text,
  206. `weight` int not null default 0,
  207. PRIMARY KEY (`id`),
  208. KEY (`group_id`)
  209. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  210. CREATE TABLE `chart_share` (
  211. `id` bigint unsigned not null auto_increment,
  212. `cluster` varchar(128) not null,
  213. `dashboard_id` bigint unsigned not null,
  214. `configs` text,
  215. `create_at` bigint not null default 0,
  216. `create_by` varchar(64) not null default '',
  217. primary key (`id`),
  218. key (`create_at`)
  219. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  220. CREATE TABLE `alert_rule` (
  221. `id` bigint unsigned not null auto_increment,
  222. `group_id` bigint not null default 0 comment 'busi group id',
  223. `cate` varchar(128) not null,
  224. `datasource_ids` varchar(255) not null default '' comment 'datasource ids',
  225. `cluster` varchar(128) not null,
  226. `name` varchar(255) not null,
  227. `note` varchar(1024) not null default '',
  228. `prod` varchar(255) not null default '',
  229. `algorithm` varchar(255) not null default '',
  230. `algo_params` varchar(255),
  231. `delay` int not null default 0,
  232. `severity` tinyint(1) not null comment '1:Emergency 2:Warning 3:Notice',
  233. `disabled` tinyint(1) not null comment '0:enabled 1:disabled',
  234. `prom_for_duration` int not null comment 'prometheus for, unit:s',
  235. `rule_config` text not null comment 'rule_config',
  236. `prom_ql` text not null comment 'promql',
  237. `prom_eval_interval` int not null comment 'evaluate interval',
  238. `enable_stime` varchar(255) not null default '00:00',
  239. `enable_etime` varchar(255) not null default '23:59',
  240. `enable_days_of_week` varchar(255) not null default '' comment 'split by space: 0 1 2 3 4 5 6',
  241. `enable_in_bg` tinyint(1) not null default 0 comment '1: only this bg 0: global',
  242. `notify_recovered` tinyint(1) not null comment 'whether notify when recovery',
  243. `notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
  244. `notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',
  245. `notify_repeat_step` int not null default 0 comment 'unit: min',
  246. `notify_max_number` int not null default 0 comment '',
  247. `recover_duration` int not null default 0 comment 'unit: s',
  248. `callbacks` varchar(255) not null default '' comment 'split by space: http://a.com/api/x http://a.com/api/y',
  249. `runbook_url` varchar(255),
  250. `append_tags` varchar(255) not null default '' comment 'split by space: service=n9e mod=api',
  251. `annotations` text not null comment 'annotations',
  252. `create_at` bigint not null default 0,
  253. `create_by` varchar(64) not null default '',
  254. `update_at` bigint not null default 0,
  255. `update_by` varchar(64) not null default '',
  256. PRIMARY KEY (`id`),
  257. KEY (`group_id`),
  258. KEY (`update_at`)
  259. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  260. CREATE TABLE `alert_mute` (
  261. `id` bigint unsigned not null auto_increment,
  262. `group_id` bigint not null default 0 comment 'busi group id',
  263. `prod` varchar(255) not null default '',
  264. `note` varchar(1024) not null default '',
  265. `cate` varchar(128) not null,
  266. `cluster` varchar(128) not null,
  267. `datasource_ids` varchar(255) not null default '' comment 'datasource ids',
  268. `tags` varchar(4096) not null default '' comment 'json,map,tagkey->regexp|value',
  269. `cause` varchar(255) not null default '',
  270. `btime` bigint not null default 0 comment 'begin time',
  271. `etime` bigint not null default 0 comment 'end time',
  272. `disabled` tinyint(1) not null default 0 comment '0:enabled 1:disabled',
  273. `mute_time_type` tinyint(1) not null default 0,
  274. `periodic_mutes` varchar(4096) not null default '',
  275. `create_at` bigint not null default 0,
  276. `create_by` varchar(64) not null default '',
  277. `update_at` bigint not null default 0,
  278. `update_by` varchar(64) not null default '',
  279. PRIMARY KEY (`id`),
  280. KEY (`create_at`),
  281. KEY (`group_id`)
  282. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  283. CREATE TABLE `alert_subscribe` (
  284. `id` bigint unsigned not null auto_increment,
  285. `name` varchar(255) not null default '',
  286. `disabled` tinyint(1) not null default 0 comment '0:enabled 1:disabled',
  287. `group_id` bigint not null default 0 comment 'busi group id',
  288. `prod` varchar(255) not null default '',
  289. `cate` varchar(128) not null,
  290. `datasource_ids` varchar(255) not null default '' comment 'datasource ids',
  291. `cluster` varchar(128) not null,
  292. `rule_id` bigint not null default 0,
  293. `tags` varchar(4096) not null default '' comment 'json,map,tagkey->regexp|value',
  294. `redefine_severity` tinyint(1) default 0 comment 'is redefine severity?',
  295. `new_severity` tinyint(1) not null comment '0:Emergency 1:Warning 2:Notice',
  296. `redefine_channels` tinyint(1) default 0 comment 'is redefine channels?',
  297. `new_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
  298. `user_group_ids` varchar(250) not null comment 'split by space 1 34 5, notify cc to user_group_ids',
  299. `webhooks` text not null,
  300. `redefine_webhooks` tinyint(1) default 0,
  301. `for_duration` bigint not null default 0,
  302. `create_at` bigint not null default 0,
  303. `create_by` varchar(64) not null default '',
  304. `update_at` bigint not null default 0,
  305. `update_by` varchar(64) not null default '',
  306. PRIMARY KEY (`id`),
  307. KEY (`update_at`),
  308. KEY (`group_id`)
  309. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  310. CREATE TABLE `target` (
  311. `id` bigint unsigned not null auto_increment,
  312. `group_id` bigint not null default 0 comment 'busi group id',
  313. `datasource_id` bigint not null default 0 comment 'datasource id',
  314. `cluster` varchar(128) not null default '',
  315. `ident` varchar(191) not null comment 'target id',
  316. `note` varchar(255) not null default '' comment 'append to alert event as field',
  317. `tags` varchar(512) not null default '' comment 'append to series data as tags, split by space, append external space at suffix',
  318. `update_at` bigint not null default 0,
  319. `offset` bigint not null default 0,
  320. PRIMARY KEY (`id`),
  321. UNIQUE KEY (`ident`),
  322. KEY (`group_id`),
  323. KEY (`datasource_id`),
  324. KEY (`update_at`),
  325. KEY (`offset`)
  326. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  327. -- case1: target_idents; case2: target_tags
  328. -- CREATE TABLE `collect_rule` (
  329. -- `id` bigint unsigned not null auto_increment,
  330. -- `group_id` bigint not null default 0 comment 'busi group id',
  331. -- `cluster` varchar(128) not null,
  332. -- `target_idents` varchar(512) not null default '' comment 'ident list, split by space',
  333. -- `target_tags` varchar(512) not null default '' comment 'filter targets by tags, split by space',
  334. -- `name` varchar(191) not null default '',
  335. -- `note` varchar(255) not null default '',
  336. -- `step` int not null,
  337. -- `type` varchar(64) not null comment 'e.g. port proc log plugin',
  338. -- `data` text not null,
  339. -- `append_tags` varchar(255) not null default '' comment 'split by space: e.g. mod=n9e dept=cloud',
  340. -- `create_at` bigint not null default 0,
  341. -- `create_by` varchar(64) not null default '',
  342. -- `update_at` bigint not null default 0,
  343. -- `update_by` varchar(64) not null default '',
  344. -- PRIMARY KEY (`id`),
  345. -- KEY (`group_id`, `type`, `name`)
  346. -- ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  347. CREATE TABLE `metric_view` (
  348. `id` bigint unsigned not null auto_increment,
  349. `name` varchar(191) not null default '',
  350. `cate` tinyint(1) not null comment '0: preset 1: custom',
  351. `configs` varchar(8192) not null default '',
  352. `create_at` bigint not null default 0,
  353. `create_by` bigint not null default 0 comment 'user id',
  354. `update_at` bigint not null default 0,
  355. PRIMARY KEY (`id`),
  356. KEY (`create_by`)
  357. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  358. insert into metric_view(name, cate, configs) values('Host View', 0, '{"filters":[{"oper":"=","label":"__name__","value":"cpu_usage_idle"}],"dynamicLabels":[],"dimensionLabels":[{"label":"ident","value":""}]}');
  359. CREATE TABLE `recording_rule` (
  360. `id` bigint unsigned not null auto_increment,
  361. `group_id` bigint not null default '0' comment 'group_id',
  362. `datasource_id` bigint not null default 0 comment 'datasource id',
  363. `cluster` varchar(128) not null,
  364. `name` varchar(255) not null comment 'new metric name',
  365. `note` varchar(255) not null comment 'rule note',
  366. `disabled` tinyint(1) not null default 0 comment '0:enabled 1:disabled',
  367. `prom_ql` varchar(8192) not null comment 'promql',
  368. `prom_eval_interval` int not null comment 'evaluate interval',
  369. `append_tags` varchar(255) default '' comment 'split by space: service=n9e mod=api',
  370. `create_at` bigint default '0',
  371. `create_by` varchar(64) default '',
  372. `update_at` bigint default '0',
  373. `update_by` varchar(64) default '',
  374. PRIMARY KEY (`id`),
  375. KEY `group_id` (`group_id`),
  376. KEY `update_at` (`update_at`)
  377. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  378. CREATE TABLE `alert_aggr_view` (
  379. `id` bigint unsigned not null auto_increment,
  380. `name` varchar(191) not null default '',
  381. `rule` varchar(2048) not null default '',
  382. `cate` tinyint(1) not null comment '0: preset 1: custom',
  383. `create_at` bigint not null default 0,
  384. `create_by` bigint not null default 0 comment 'user id',
  385. `update_at` bigint not null default 0,
  386. PRIMARY KEY (`id`),
  387. KEY (`create_by`)
  388. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  389. insert into alert_aggr_view(name, rule, cate) values('By BusiGroup, Severity', 'field:group_name::field:severity', 0);
  390. insert into alert_aggr_view(name, rule, cate) values('By RuleName', 'field:rule_name', 0);
  391. CREATE TABLE `alert_cur_event` (
  392. `id` bigint unsigned not null comment 'use alert_his_event.id',
  393. `cate` varchar(128) not null,
  394. `datasource_id` bigint not null default 0 comment 'datasource id',
  395. `cluster` varchar(128) not null,
  396. `group_id` bigint unsigned not null comment 'busi group id of rule',
  397. `group_name` varchar(255) not null default '' comment 'busi group name',
  398. `hash` varchar(64) not null comment 'rule_id + vector_pk',
  399. `rule_id` bigint unsigned not null,
  400. `rule_name` varchar(255) not null,
  401. `rule_note` varchar(2048) not null default 'alert rule note',
  402. `rule_prod` varchar(255) not null default '',
  403. `rule_algo` varchar(255) not null default '',
  404. `severity` tinyint(1) not null comment '0:Emergency 1:Warning 2:Notice',
  405. `prom_for_duration` int not null comment 'prometheus for, unit:s',
  406. `prom_ql` varchar(8192) not null comment 'promql',
  407. `prom_eval_interval` int not null comment 'evaluate interval',
  408. `callbacks` varchar(255) not null default '' comment 'split by space: http://a.com/api/x http://a.com/api/y',
  409. `runbook_url` varchar(255),
  410. `notify_recovered` tinyint(1) not null comment 'whether notify when recovery',
  411. `notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
  412. `notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',
  413. `notify_repeat_next` bigint not null default 0 comment 'next timestamp to notify, get repeat settings from rule',
  414. `notify_cur_number` int not null default 0 comment '',
  415. `target_ident` varchar(191) not null default '' comment 'target ident, also in tags',
  416. `target_note` varchar(191) not null default '' comment 'target note',
  417. `first_trigger_time` bigint,
  418. `trigger_time` bigint not null,
  419. `trigger_value` varchar(255) not null,
  420. `annotations` text not null comment 'annotations',
  421. `rule_config` text not null comment 'annotations',
  422. `tags` varchar(1024) not null default '' comment 'merge data_tags rule_tags, split by ,,',
  423. PRIMARY KEY (`id`),
  424. KEY (`hash`),
  425. KEY (`rule_id`),
  426. KEY (`trigger_time`, `group_id`),
  427. KEY (`notify_repeat_next`)
  428. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  429. CREATE TABLE `alert_his_event` (
  430. `id` bigint unsigned not null AUTO_INCREMENT,
  431. `is_recovered` tinyint(1) not null,
  432. `cate` varchar(128) not null,
  433. `datasource_id` bigint not null default 0 comment 'datasource id',
  434. `cluster` varchar(128) not null,
  435. `group_id` bigint unsigned not null comment 'busi group id of rule',
  436. `group_name` varchar(255) not null default '' comment 'busi group name',
  437. `hash` varchar(64) not null comment 'rule_id + vector_pk',
  438. `rule_id` bigint unsigned not null,
  439. `rule_name` varchar(255) not null,
  440. `rule_note` varchar(2048) not null default 'alert rule note',
  441. `rule_prod` varchar(255) not null default '',
  442. `rule_algo` varchar(255) not null default '',
  443. `severity` tinyint(1) not null comment '0:Emergency 1:Warning 2:Notice',
  444. `prom_for_duration` int not null comment 'prometheus for, unit:s',
  445. `prom_ql` varchar(8192) not null comment 'promql',
  446. `prom_eval_interval` int not null comment 'evaluate interval',
  447. `callbacks` varchar(255) not null default '' comment 'split by space: http://a.com/api/x http://a.com/api/y',
  448. `runbook_url` varchar(255),
  449. `notify_recovered` tinyint(1) not null comment 'whether notify when recovery',
  450. `notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
  451. `notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',
  452. `notify_cur_number` int not null default 0 comment '',
  453. `target_ident` varchar(191) not null default '' comment 'target ident, also in tags',
  454. `target_note` varchar(191) not null default '' comment 'target note',
  455. `first_trigger_time` bigint,
  456. `trigger_time` bigint not null,
  457. `trigger_value` varchar(255) not null,
  458. `recover_time` bigint not null default 0,
  459. `last_eval_time` bigint not null default 0 comment 'for time filter',
  460. `tags` varchar(1024) not null default '' comment 'merge data_tags rule_tags, split by ,,',
  461. `annotations` text not null comment 'annotations',
  462. `rule_config` text not null comment 'annotations',
  463. PRIMARY KEY (`id`),
  464. KEY (`hash`),
  465. KEY (`rule_id`),
  466. KEY (`trigger_time`, `group_id`)
  467. ) ENGINE=InnoDB DEFAULT CHARSET = utf8mb4;
  468. CREATE TABLE `task_tpl`
  469. (
  470. `id` int unsigned NOT NULL AUTO_INCREMENT,
  471. `group_id` int unsigned not null comment 'busi group id',
  472. `title` varchar(255) not null default '',
  473. `account` varchar(64) not null,
  474. `batch` int unsigned not null default 0,
  475. `tolerance` int unsigned not null default 0,
  476. `timeout` int unsigned not null default 0,
  477. `pause` varchar(255) not null default '',
  478. `script` text not null,
  479. `args` varchar(512) not null default '',
  480. `tags` varchar(255) not null default '' comment 'split by space',
  481. `create_at` bigint not null default 0,
  482. `create_by` varchar(64) not null default '',
  483. `update_at` bigint not null default 0,
  484. `update_by` varchar(64) not null default '',
  485. PRIMARY KEY (`id`),
  486. KEY (`group_id`)
  487. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  488. CREATE TABLE `task_tpl_host`
  489. (
  490. `ii` int unsigned NOT NULL AUTO_INCREMENT,
  491. `id` int unsigned not null comment 'task tpl id',
  492. `host` varchar(128) not null comment 'ip or hostname',
  493. PRIMARY KEY (`ii`),
  494. KEY (`id`, `host`)
  495. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  496. CREATE TABLE `task_record`
  497. (
  498. `id` bigint unsigned not null comment 'ibex task id',
  499. `group_id` bigint not null comment 'busi group id',
  500. `ibex_address` varchar(128) not null,
  501. `ibex_auth_user` varchar(128) not null default '',
  502. `ibex_auth_pass` varchar(128) not null default '',
  503. `title` varchar(255) not null default '',
  504. `account` varchar(64) not null,
  505. `batch` int unsigned not null default 0,
  506. `tolerance` int unsigned not null default 0,
  507. `timeout` int unsigned not null default 0,
  508. `pause` varchar(255) not null default '',
  509. `script` text not null,
  510. `args` varchar(512) not null default '',
  511. `create_at` bigint not null default 0,
  512. `create_by` varchar(64) not null default '',
  513. PRIMARY KEY (`id`),
  514. KEY (`create_at`, `group_id`),
  515. KEY (`create_by`)
  516. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  517. CREATE TABLE `alerting_engines`
  518. (
  519. `id` int unsigned NOT NULL AUTO_INCREMENT,
  520. `instance` varchar(128) not null default '' comment 'instance identification, e.g. 10.9.0.9:9090',
  521. `datasource_id` bigint not null default 0 comment 'datasource id',
  522. `cluster` varchar(128) not null default '' comment 'n9e-alert cluster',
  523. `clock` bigint not null,
  524. PRIMARY KEY (`id`)
  525. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  526. CREATE TABLE `datasource`
  527. (
  528. `id` int unsigned NOT NULL AUTO_INCREMENT,
  529. `name` varchar(255) not null default '',
  530. `description` varchar(255) not null default '',
  531. `category` varchar(255) not null default '',
  532. `plugin_id` int unsigned not null default 0,
  533. `plugin_type` varchar(255) not null default '',
  534. `plugin_type_name` varchar(255) not null default '',
  535. `cluster_name` varchar(255) not null default '',
  536. `settings` text not null,
  537. `status` varchar(255) not null default '',
  538. `http` varchar(4096) not null default '',
  539. `auth` varchar(8192) not null default '',
  540. `created_at` bigint not null default 0,
  541. `created_by` varchar(64) not null default '',
  542. `updated_at` bigint not null default 0,
  543. `updated_by` varchar(64) not null default '',
  544. UNIQUE KEY (`name`),
  545. PRIMARY KEY (`id`)
  546. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  547. CREATE TABLE `builtin_cate` (
  548. `id` bigint unsigned not null auto_increment,
  549. `name` varchar(191) not null,
  550. `user_id` bigint not null default 0,
  551. PRIMARY KEY (`id`)
  552. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  553. CREATE TABLE `notify_tpl` (
  554. `id` bigint unsigned not null auto_increment,
  555. `channel` varchar(32) not null,
  556. `name` varchar(255) not null,
  557. `content` text not null,
  558. PRIMARY KEY (`id`),
  559. UNIQUE KEY (`channel`)
  560. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
  561. CREATE TABLE `sso_config` (
  562. `id` bigint unsigned not null auto_increment,
  563. `name` varchar(255) not null,
  564. `content` text not null,
  565. PRIMARY KEY (`id`),
  566. UNIQUE KEY (`name`)
  567. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;