智慧水务管理系统 - 精河县供水工程综合管理平台

docker-compose.monitoring.yml 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # ============================================================
  2. # 监控栈 Docker Compose 编排
  3. #
  4. # 使用方式:
  5. # docker compose -f deploy/production/monitoring/docker-compose.monitoring.yml up -d
  6. #
  7. # 包含组件:
  8. # - Prometheus (指标收集与告警)
  9. # - Grafana (可视化仪表盘)
  10. # - Node Exporter (主机指标)
  11. # - cAdvisor (容器指标)
  12. # - AlertManager (告警管理)
  13. # ============================================================
  14. services:
  15. # ==================== Prometheus ====================
  16. prometheus:
  17. image: prom/prometheus:v2.51.0
  18. container_name: wm-prometheus
  19. restart: always
  20. command:
  21. - '--config.file=/etc/prometheus/prometheus.yml'
  22. - '--storage.tsdb.path=/prometheus'
  23. - '--storage.tsdb.retention.time=30d'
  24. - '--storage.tsdb.retention.size=10GB'
  25. - '--web.console.libraries=/etc/prometheus/console_libraries'
  26. - '--web.console.templates=/etc/prometheus/consoles'
  27. - '--web.enable-lifecycle'
  28. - '--web.enable-admin-api'
  29. ports:
  30. - "127.0.0.1:9090:9090"
  31. volumes:
  32. - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
  33. - ./alert_rules.yml:/etc/prometheus/alert_rules.yml:ro
  34. - prometheus_data:/prometheus
  35. networks:
  36. - wm-network
  37. - monitoring
  38. deploy:
  39. resources:
  40. limits:
  41. cpus: '1.0'
  42. memory: 2G
  43. reservations:
  44. cpus: '0.25'
  45. memory: 512M
  46. logging:
  47. driver: json-file
  48. options:
  49. max-size: "50m"
  50. max-file: "3"
  51. healthcheck:
  52. test: ["CMD", "wget", "--spider", "-q", "http://localhost:9090/-/healthy"]
  53. interval: 30s
  54. timeout: 10s
  55. retries: 3
  56. # ==================== Grafana ====================
  57. grafana:
  58. image: grafana/grafana:10.4.0
  59. container_name: wm-grafana
  60. restart: always
  61. ports:
  62. - "127.0.0.1:3000:3000"
  63. environment:
  64. GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
  65. GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-admin}
  66. GF_SERVER_ROOT_URL: ${GRAFANA_ROOT_URL:-http://localhost:3000}
  67. GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-simple-json-datasource
  68. GF_USERS_ALLOW_SIGN_UP: "false"
  69. GF_AUTH_ANONYMOUS_ENABLED: "false"
  70. GF_SECURITY_COOKIE_SECURE: "true"
  71. GF_SECURITY_STRICT_TRANSPORT_SECURITY: "true"
  72. volumes:
  73. - ./grafana/provisioning/datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
  74. - grafana_data:/var/lib/grafana
  75. networks:
  76. - monitoring
  77. - wm-network
  78. deploy:
  79. resources:
  80. limits:
  81. cpus: '0.5'
  82. memory: 512M
  83. reservations:
  84. cpus: '0.1'
  85. memory: 128M
  86. logging:
  87. driver: json-file
  88. options:
  89. max-size: "30m"
  90. max-file: "3"
  91. healthcheck:
  92. test: ["CMD", "wget", "--spider", "-q", "http://localhost:3000/api/health"]
  93. interval: 30s
  94. timeout: 10s
  95. retries: 3
  96. # ==================== Node Exporter ====================
  97. node-exporter:
  98. image: prom/node-exporter:v1.7.0
  99. container_name: wm-node-exporter
  100. restart: always
  101. command:
  102. - '--path.rootfs=/host'
  103. - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
  104. ports:
  105. - "127.0.0.1:9100:9100"
  106. volumes:
  107. - /:/host:ro,rslave
  108. pid: host
  109. networks:
  110. - monitoring
  111. deploy:
  112. resources:
  113. limits:
  114. cpus: '0.2'
  115. memory: 128M
  116. reservations:
  117. cpus: '0.05'
  118. memory: 32M
  119. logging:
  120. driver: json-file
  121. options:
  122. max-size: "10m"
  123. max-file: "3"
  124. # ==================== cAdvisor ====================
  125. cadvisor:
  126. image: gcr.io/cadvisor/cadvisor:v0.49.1
  127. container_name: wm-cadvisor
  128. restart: always
  129. ports:
  130. - "127.0.0.1:8880:8080"
  131. volumes:
  132. - /:/rootfs:ro
  133. - /var/run:/var/run:ro
  134. - /sys:/sys:ro
  135. - /var/lib/docker/:/var/lib/docker:ro
  136. - /dev/disk/:/dev/disk:ro
  137. privileged: true
  138. devices:
  139. - /dev/kmsg:/dev/kmsg
  140. networks:
  141. - monitoring
  142. deploy:
  143. resources:
  144. limits:
  145. cpus: '0.3'
  146. memory: 256M
  147. reservations:
  148. cpus: '0.1'
  149. memory: 64M
  150. logging:
  151. driver: json-file
  152. options:
  153. max-size: "20m"
  154. max-file: "3"
  155. # ==================== AlertManager ====================
  156. alertmanager:
  157. image: prom/alertmanager:v0.27.0
  158. container_name: wm-alertmanager
  159. restart: always
  160. command:
  161. - '--config.file=/etc/alertmanager/alertmanager.yml'
  162. - '--storage.path=/alertmanager'
  163. ports:
  164. - "127.0.0.1:9093:9093"
  165. volumes:
  166. - ./alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
  167. - alertmanager_data:/alertmanager
  168. networks:
  169. - monitoring
  170. deploy:
  171. resources:
  172. limits:
  173. cpus: '0.2'
  174. memory: 256M
  175. reservations:
  176. cpus: '0.05'
  177. memory: 64M
  178. logging:
  179. driver: json-file
  180. options:
  181. max-size: "10m"
  182. max-file: "3"
  183. # ==================== PostgreSQL Exporter ====================
  184. postgres-exporter:
  185. image: prometheuscommunity/postgres-exporter:v0.15.0
  186. container_name: wm-postgres-exporter
  187. restart: always
  188. environment:
  189. DATA_SOURCE_NAME: "postgresql://${POSTGRES_USER:-water}:${POSTGRES_PASSWORD:-water123}@postgres:5432/${POSTGRES_DB:-water_management}?sslmode=disable"
  190. ports:
  191. - "127.0.0.1:9187:9187"
  192. depends_on:
  193. - postgres
  194. networks:
  195. - monitoring
  196. - wm-network
  197. deploy:
  198. resources:
  199. limits:
  200. cpus: '0.2'
  201. memory: 128M
  202. reservations:
  203. cpus: '0.05'
  204. memory: 32M
  205. logging:
  206. driver: json-file
  207. options:
  208. max-size: "10m"
  209. max-file: "3"
  210. # ==================== Redis Exporter ====================
  211. redis-exporter:
  212. image: oliver006/redis_exporter:v1.58.0
  213. container_name: wm-redis-exporter
  214. restart: always
  215. environment:
  216. REDIS_ADDR: redis://redis:6379
  217. REDIS_PASSWORD: ${REDIS_PASSWORD:-water123}
  218. ports:
  219. - "127.0.0.1:9121:9121"
  220. depends_on:
  221. - redis
  222. networks:
  223. - monitoring
  224. - wm-network
  225. deploy:
  226. resources:
  227. limits:
  228. cpus: '0.1'
  229. memory: 64M
  230. reservations:
  231. cpus: '0.02'
  232. memory: 16M
  233. logging:
  234. driver: json-file
  235. options:
  236. max-size: "10m"
  237. max-file: "3"
  238. # ==================== 数据卷 ====================
  239. volumes:
  240. prometheus_data:
  241. grafana_data:
  242. alertmanager_data:
  243. # ==================== 网络 ====================
  244. networks:
  245. monitoring:
  246. driver: bridge
  247. name: wm-monitoring
  248. wm-network:
  249. external: true
  250. name: wm-network