-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgunicorn.conf.py
104 lines (81 loc) · 2.81 KB
/
gunicorn.conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
###
# app configuration
# https://docs.gunicorn.org/en/stable/settings.html
###
import os
import gunicorn.arbiter
import gunicorn.workers.base
from c2cwsgiutils import get_config_defaults, prometheus
from prometheus_client import multiprocess
bind = ":8080"
worker_class = "gthread"
workers = os.environ.get("GUNICORN_WORKERS", 2)
threads = os.environ.get("GUNICORN_THREADS", 10)
preload = "true"
accesslog = "-"
access_log_format = os.environ.get(
"GUNICORN_ACCESS_LOG_FORMAT",
'%(H)s %({Host}i)s %(m)s %(U)s?%(q)s "%(f)s" "%(a)s" %(s)s %(B)s %(D)s %(p)s',
)
###
# logging configuration
# https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
###
logconfig_dict = {
"version": 1,
"root": {
"level": os.environ["OTHER_LOG_LEVEL"],
"handlers": [os.environ["LOG_TYPE"]],
},
"loggers": {
"gunicorn.error": {"level": os.environ["GUNICORN_LOG_LEVEL"]},
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)
"sqlalchemy.engine": {"level": os.environ["SQL_LOG_LEVEL"]},
"c2cwsgiutils": {"level": os.environ["C2CWSGIUTILS_LOG_LEVEL"]},
"tilecloud": {"level": os.environ["TILECLOUD_LOG_LEVEL"]},
"tilecloud_chain": {"level": os.environ["TILECLOUD_CHAIN_LOG_LEVEL"]},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "ext://sys.stdout",
},
"json": {
"class": "tilecloud_chain.JsonLogHandler",
"formatter": "generic",
"stream": "ext://sys.stdout",
},
},
"formatters": {
"generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)-5.5s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter",
}
},
}
raw_paste_global_conf = ["=".join(e) for e in get_config_defaults().items()]
def on_starting(server: gunicorn.arbiter.Arbiter) -> None:
"""
Will start the prometheus server.
Called just before the master process is initialized.
"""
del server
prometheus.start()
def post_fork(server: gunicorn.arbiter.Arbiter, worker: gunicorn.workers.base.Worker) -> None:
"""
Will cleanup the configuration we get from the main process.
Called just after a worker has been forked.
"""
del server, worker
prometheus.cleanup()
def child_exit(server: gunicorn.arbiter.Arbiter, worker: gunicorn.workers.base.Worker) -> None:
"""
Remove the metrics for the exited worker.
Called just after a worker has been exited, in the master process.
"""
del server
multiprocess.mark_process_dead(worker.pid) # type: ignore [no-untyped-call]