prometheus.service.j2 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {{ ansible_managed | comment }}
  2. [Unit]
  3. Description=Prometheus
  4. After=network-online.target
  5. Requires=local-fs.target
  6. After=local-fs.target
  7. [Service]
  8. Type=simple
  9. Environment="GOMAXPROCS={{ ansible_processor_vcpus|default(ansible_processor_count) }}"
  10. User=prometheus
  11. Group=prometheus
  12. ExecReload=/bin/kill -HUP $MAINPID
  13. ExecStart={{ prometheus_binary_install_dir }}/prometheus \
  14. --storage.tsdb.path={{ prometheus_db_dir }} \
  15. {% if prometheus_version is version('2.7.0', '>=') %}
  16. --storage.tsdb.retention.time={{ prometheus_storage_retention }} \
  17. --storage.tsdb.retention.size={{ prometheus_storage_retention_size }} \
  18. {% else %}
  19. --storage.tsdb.retention={{ prometheus_storage_retention }} \
  20. {% endif %}
  21. {% if prometheus_version is version('2.24.0', '>=') %}
  22. --web.config.file={{ prometheus_config_dir }}/web.yml \
  23. {% endif %}
  24. --web.console.libraries={{ prometheus_config_dir }}/console_libraries \
  25. --web.console.templates={{ prometheus_config_dir }}/consoles \
  26. --web.listen-address={{ prometheus_web_listen_address }} \
  27. --web.external-url={{ prometheus_web_external_url }} \
  28. {% for flag, flag_value in prometheus_config_flags_extra.items() %}
  29. {% if not flag_value %}
  30. --{{ flag }} \
  31. {% elif flag_value is string %}
  32. --{{ flag }}={{ flag_value }} \
  33. {% elif flag_value is sequence %}
  34. {% for flag_value_item in flag_value %}
  35. --{{ flag }}={{ flag_value_item }} \
  36. {% endfor %}
  37. {% endif %}
  38. {% endfor %}
  39. --config.file={{ prometheus_config_dir }}/prometheus.yml
  40. CapabilityBoundingSet=CAP_SET_UID
  41. LimitNOFILE=65000
  42. LockPersonality=true
  43. NoNewPrivileges=true
  44. MemoryDenyWriteExecute=true
  45. PrivateDevices=true
  46. PrivateTmp=true
  47. ProtectHome=true
  48. RemoveIPC=true
  49. RestrictSUIDSGID=true
  50. #SystemCallFilter=@signal @timer
  51. {% if prometheus_systemd_version | int >= 231 %}
  52. ReadWritePaths={{ prometheus_db_dir }}
  53. {% for path in prometheus_read_only_dirs %}
  54. ReadOnlyPaths={{ path }}
  55. {% endfor %}
  56. {% else %}
  57. ReadWriteDirectories={{ prometheus_db_dir }}
  58. {% for path in prometheus_read_only_dirs %}
  59. ReadOnlyDirectories={{ path }}
  60. {% endfor %}
  61. {% endif %}
  62. {% if prometheus_systemd_version | int >= 232 %}
  63. PrivateUsers=true
  64. ProtectControlGroups=true
  65. ProtectKernelModules=true
  66. ProtectKernelTunables=true
  67. ProtectSystem=strict
  68. {% else %}
  69. ProtectSystem=full
  70. {% endif %}
  71. {% if http_proxy is defined %}
  72. Environment="HTTP_PROXY={{ http_proxy }}"{% if https_proxy is defined %} "HTTPS_PROXY={{ https_proxy }}{% endif %}"
  73. {% endif %}
  74. SyslogIdentifier=prometheus
  75. Restart=always
  76. [Install]
  77. WantedBy=multi-user.target