ngx.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { http } from '@uozi-admin/request'
  2. export interface NgxConfig {
  3. file_name?: string
  4. name: string
  5. upstreams?: NgxUpstream[]
  6. servers: NgxServer[]
  7. custom?: string
  8. }
  9. export interface NgxServer {
  10. directives?: NgxDirective[]
  11. locations?: NgxLocation[]
  12. comments?: string
  13. }
  14. export interface NgxUpstream {
  15. name: string
  16. directives: NgxDirective[]
  17. comments?: string
  18. }
  19. export interface NgxDirective {
  20. idx?: number
  21. directive: string
  22. params: string
  23. comments?: string
  24. }
  25. export interface NgxLocation {
  26. path: string
  27. content: string
  28. comments: string
  29. }
  30. export type DirectiveMap = Record<string, { links: string[] }>
  31. export interface ProxyCacheConfig {
  32. enabled: boolean
  33. path: string
  34. levels: string
  35. use_temp_path: string
  36. keys_zone: string
  37. inactive: string
  38. max_size: string
  39. min_free: string
  40. manager_files: string
  41. manager_sleep: string
  42. manager_threshold: string
  43. loader_files: string
  44. loader_sleep: string
  45. loader_threshold: string
  46. purger: string
  47. purger_files: string
  48. purger_sleep: string
  49. purger_threshold: string
  50. }
  51. export interface NginxPerformanceInfo {
  52. active: number // Number of active connections
  53. accepts: number // Total number of accepted connections
  54. handled: number // Total number of handled connections
  55. requests: number // Total number of requests
  56. reading: number // Number of connections reading request data
  57. writing: number // Number of connections writing response data
  58. waiting: number // Number of idle connections waiting for requests
  59. workers: number // Number of worker processes
  60. master: number // Number of master processes
  61. cache: number // Number of cache manager processes
  62. other: number // Number of other Nginx-related processes
  63. cpu_usage: number // CPU usage percentage
  64. memory_usage: number // Memory usage in MB
  65. worker_processes: number // worker_processes configuration
  66. worker_connections: number // worker_connections configuration
  67. process_mode: string // Worker process configuration mode: 'auto' or 'manual'
  68. }
  69. export interface NginxConfigInfo {
  70. worker_processes: string
  71. worker_connections: number
  72. process_mode: string
  73. keepalive_timeout: string
  74. gzip: string
  75. gzip_min_length: number
  76. gzip_comp_level: number
  77. client_max_body_size: string
  78. server_names_hash_bucket_size: string
  79. client_header_buffer_size: string
  80. client_body_buffer_size: string
  81. proxy_cache: ProxyCacheConfig
  82. }
  83. export interface NginxPerfOpt {
  84. worker_processes: string
  85. worker_connections: string
  86. keepalive_timeout: string
  87. gzip: string
  88. gzip_min_length: string
  89. gzip_comp_level: string
  90. client_max_body_size: string
  91. server_names_hash_bucket_size: string
  92. client_header_buffer_size: string
  93. client_body_buffer_size: string
  94. proxy_cache: ProxyCacheConfig
  95. }
  96. export interface NgxModule {
  97. name: string
  98. params?: string
  99. dynamic: boolean
  100. loaded: boolean
  101. }
  102. const ngx = {
  103. build_config(ngxConfig: NgxConfig) {
  104. return http.post('/ngx/build_config', ngxConfig)
  105. },
  106. tokenize_config(content: string) {
  107. return http.post('/ngx/tokenize_config', { content })
  108. },
  109. format_code(content: string) {
  110. return http.post('/ngx/format_code', { content })
  111. },
  112. status(): Promise<{ running: boolean, message: string, level: number }> {
  113. return http.get('/nginx/status')
  114. },
  115. detail_status(): Promise<{ running: boolean, stub_status_enabled: boolean, info: NginxPerformanceInfo }> {
  116. return http.get('/nginx/detail_status')
  117. },
  118. toggle_stub_status(enable: boolean): Promise<{ stub_status_enabled: boolean, error: string }> {
  119. return http.post('/nginx/stub_status', { enable })
  120. },
  121. reload() {
  122. return http.post('/nginx/reload')
  123. },
  124. restart() {
  125. return http.post('/nginx/restart')
  126. },
  127. test() {
  128. return http.post('/nginx/test')
  129. },
  130. get_directives(): Promise<DirectiveMap> {
  131. return http.get('/nginx/directives')
  132. },
  133. get_performance(): Promise<NginxConfigInfo> {
  134. return http.get('/nginx/performance')
  135. },
  136. update_performance(params: NginxPerfOpt): Promise<NginxConfigInfo> {
  137. return http.post('/nginx/performance', params)
  138. },
  139. get_modules(): Promise<NgxModule[]> {
  140. return http.get('/nginx/modules')
  141. },
  142. }
  143. export default ngx