diff --git a/prometheus_client/core.py b/prometheus_client/core.py index cb1e7c5b..b05bf645 100644 --- a/prometheus_client/core.py +++ b/prometheus_client/core.py @@ -505,11 +505,11 @@ class _MmapedDict(object): Not thread safe. """ def __init__(self, filename, read_mode=False): - self._f = open(filename, 'a+b') + self._f = open(filename, 'rb' if read_mode else 'a+b') if os.fstat(self._f.fileno()).st_size == 0: self._f.truncate(_INITIAL_MMAP_SIZE) self._capacity = os.fstat(self._f.fileno()).st_size - self._m = mmap.mmap(self._f.fileno(), self._capacity) + self._m = mmap.mmap(self._f.fileno(), self._capacity, access=mmap.ACCESS_READ if read_mode else mmap.ACCESS_WRITE) self._positions = {} self._used = _unpack_integer(self._m, 0)[0] diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index 1ebeba29..29494d08 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -37,7 +37,7 @@ def make_wsgi_app(registry=core.REGISTRY): def prometheus_app(environ, start_response): params = parse_qs(environ.get('QUERY_STRING', '')) r = registry - encoder, content_type = choose_encoder(environ.get['HTTP_ACCEPT']) + encoder, content_type = choose_encoder(environ.get('HTTP_ACCEPT')) if 'name[]' in params: r = r.restricted_registry(params['name[]']) output = encoder(r)