-
Notifications
You must be signed in to change notification settings - Fork 8
/
master.py
73 lines (55 loc) · 2.14 KB
/
master.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
# -*- coding: utf-8 -*-
import time
from amplify.agent.common.context import context
from amplify.ext.abstract.object import AbstractExtObject
from amplify.ext.phpfpm.util.parser import PHPFPMConfig
from amplify.ext.phpfpm.collectors.master.meta import PHPFPMMetaCollector
from amplify.ext.phpfpm.collectors.master.metrics import PHPFPMMetricsCollector
__author__ = "Grant Hulegaard"
__copyright__ = "Copyright (C) Nginx, Inc. All rights reserved."
__license__ = ""
__maintainer__ = "Grant Hulegaard"
__email__ = "grant.hulegaard@nginx.com"
class PHPFPMObject(AbstractExtObject):
type = 'phpfpm'
def __init__(self, **kwargs):
super(PHPFPMObject, self).__init__(**kwargs)
self.name = 'master'
# cached values
self._local_id = self.data.get('local_id', None)
# TODO: Think of a better way to handle this communication between asbtract and inherited objects.
# attributes
self.pid = self.data['pid']
self.cmd = self.data['cmd']
self.conf_path = self.data['conf_path']
self.workers = self.data['workers']
# state
self.parsed_conf = None
self.parsed = False
# collectors
self._setup_meta_collector()
self._setup_metrics_collector()
@property
def local_id_args(self):
return self.cmd, self.conf_path
def _setup_meta_collector(self):
self.collectors.append(
PHPFPMMetaCollector(object=self, interval=self.intervals['meta'])
)
def _setup_metrics_collector(self):
self.collectors.append(
PHPFPMMetricsCollector(object=self, interval=self.intervals['metrics'])
)
def parse(self, force=False):
if self.parsed and not force:
return self.parsed_conf
context.log.debug('parsing phpfpm conf "%s"', self.conf_path)
start_time = time.time()
self.parsed_conf = PHPFPMConfig(path=self.conf_path).parsed
self.parsed = True
end_time = time.time()
context.log.debug(
'finished parse of "%s" in %.2f' %
(self.conf_path, end_time - start_time)
)
return self.parsed_conf