|
4 | 4 |
|
5 | 5 | import copy
|
6 | 6 | import re
|
7 |
| -import resource |
8 | 7 | import os
|
9 | 8 | import time
|
10 | 9 | import threading
|
|
17 | 16 | unicode = str
|
18 | 17 | from http.server import BaseHTTPRequestHandler
|
19 | 18 | from http.server import HTTPServer
|
| 19 | +try: |
| 20 | + import resource |
| 21 | + _PAGESIZE = resource.getpagesize() |
| 22 | +except ImportError: |
| 23 | + # Not Unix |
| 24 | + _PAGESIZE = 4096 |
| 25 | + |
20 | 26 | from functools import wraps
|
21 | 27 | from threading import Lock
|
22 | 28 |
|
@@ -497,15 +503,14 @@ def __init__(self, namespace='', pid=lambda: 'self', proc='/proc', registry=REGI
|
497 | 503 | self._namespace = namespace
|
498 | 504 | self._pid = pid
|
499 | 505 | self._proc = proc
|
500 |
| - self._pagesize = resource.getpagesize() |
501 | 506 | if namespace:
|
502 | 507 | self._prefix = namespace + '_process_'
|
503 | 508 | else:
|
504 | 509 | self._prefix = 'process_'
|
505 | 510 | self._ticks = 100.0
|
506 | 511 | try:
|
507 | 512 | self._ticks = os.sysconf('SC_CLK_TCK')
|
508 |
| - except (ValueError, TypeError): |
| 513 | + except (ValueError, TypeError, AttributeError): |
509 | 514 | pass
|
510 | 515 |
|
511 | 516 | # This is used to test if we can access /proc.
|
@@ -541,7 +546,7 @@ def collect(self):
|
541 | 546 | vmem = Metric(self._prefix + 'virtual_memory_bytes', 'Virtual memory size in bytes', 'gauge')
|
542 | 547 | vmem.add_sample(self._prefix + 'virtual_memory_bytes', {}, float(parts[20]))
|
543 | 548 | rss = Metric(self._prefix + 'resident_memory_bytes', 'Resident memory size in bytes', 'gauge')
|
544 |
| - rss.add_sample(self._prefix + 'resident_memory_bytes', {}, float(parts[21]) * self._pagesize) |
| 549 | + rss.add_sample(self._prefix + 'resident_memory_bytes', {}, float(parts[21]) * _PAGESIZE) |
545 | 550 | start_time = Metric(self._prefix + 'start_time_seconds',
|
546 | 551 | 'Start time of the process since unix epoch in seconds.', 'gauge')
|
547 | 552 | start_time_secs = float(parts[19]) / self._ticks
|
|
0 commit comments