def __init__(self, name, init_config, instances=None):
     AgentCheck.__init__(self, name, init_config, instances)
     self.payload = None
     self.name = None
     self.baseurl = None
     self.http = None
     self.upstreams = {}
 def test_removal_of_empty_elements(self):
     check = AgentCheck()
     event = {'A': {'AA': u'AA123', 'AB': ''}, 'B': ['b1', '', 'b3']}
     fixed_event = check._sanitize(event)
     self.assertIn('AA', fixed_event['A'].keys())
     self.assertNotIn('AB', fixed_event['A'].keys())
     self.assertEqual(2, len(fixed_event['B']))
Example #3
0
 def __init__(self, name, init_config, agentConfig, instances=None):
     AgentCheck.__init__(self, name, init_config, agentConfig, instances)
     self.log.setLevel(logging.DEBUG)
     self.trace_ids = {}
     self.region = None
     self.account_id = None
     self.tags = None
     self.arns = {}
Example #4
0
 def __init__(self, name, init_config, agentConfig, instances=None):
     AgentCheck.__init__(self, name, init_config, agentConfig, instances)
     self.trace_ids = {}
     self.region = None
     # default the account id to the role_arn, this will be replaced by the account id after a successful login
     self.account_id = self.instance.get('role_arn', 'unknown-instance')
     self.tags = None
     self.arns = {}
 def __init__(self, name, init_config, instances=None):
     AgentCheck.__init__(self, name, init_config, instances)
     self.url = None
     self.token = None
     self.tags = []
     self.environment = None
     self.domain = None
     self.verify = None
     self.cert = None
     self.keyfile = None
    def __init__(self, name, init_config, instances=None):
        AgentCheck.__init__(self, name, init_config, instances)
        self.host = None
        self.url = None
        self.user = None
        self.password = None
        self.tags = None

        # `zeep` logs lots of stuff related to wsdl parsing on DEBUG level so we avoid that
        zeep_logger = logging.getLogger("zeep")
        zeep_logger.setLevel(logging.WARN)
        zeep_logger.propagate = True
    def test_fix_encoding(self):
        check = AgentCheck()
        event = {
            'timestamp': 123456789,
            'msg_title': 'new test event',
            'msg_text': u'a few strange characters öüéñ',
            'context': {
                'element_identifiers': [u'urn:test:/value', 123456789],
                "A": {
                    "B": u'bbbbbb',
                    "C": {u"ccc1", "ccc2"},
                    "D": [u'ddddd']
                },
                "E": ["eeeee", u"eeee1"]
            }
        }
        expected_py3 = [
            "key: Fixed, type: <class 'dict'>",
            "key: timestamp, type: <class 'int'>",
            "key: msg_title, type: <class 'str'>",
            "key: msg_text, type: <class 'str'>",
            "key: context, type: <class 'dict'>",
            "key: element_identifiers, type: <class 'list'>",
            "key: element_identifiers, type: <class 'str'>",
            "key: element_identifiers, type: <class 'int'>",
            "key: context, type: <class 'dict'>",
            "key: A, type: <class 'dict'>",
            "key: C, type: <class 'set'>",
            "key: C, type: <class 'str'>",
            "key: C, type: <class 'str'>",
            "key: B, type: <class 'str'>",
            "key: D, type: <class 'list'>",
            "key: D, type: <class 'str'>",
            "key: E, type: <class 'list'>",
            "key: E, type: <class 'str'>",
            "key: E, type: <class 'str'>",
        ]

        expected_py2 = [x.replace("<class", "<type") for x in expected_py3]

        expected_types = expected_py3 if PY3 else expected_py2
        fixed_event = check._sanitize(event)
        fixed_types = print_type('Fixed', fixed_event)
        for expected in expected_types:
            assert expected in fixed_types
    def __init__(self, name, init_config, agentConfig, instances=None):
        AgentCheck.__init__(self, name, init_config, agentConfig, instances)
        self.dbs = {}
        self.versions = {}
        self.instance_metrics = {}
        self.bgw_metrics = {}
        self.archiver_metrics = {}
        self.db_bgw_metrics = []
        self.db_archiver_metrics = []
        self.replication_metrics = {}
        self.activity_metrics = {}
        self.custom_metrics = {}

        # Deprecate custom_metrics in favor of custom_queries
        if instances is not None and any('custom_metrics' in instance
                                         for instance in instances):
            self.warning(
                "DEPRECATION NOTICE: Please use the new custom_queries option "
                "rather than the now deprecated custom_metrics")
    def __init__(self, name, init_config, agentConfig, instances=None):
        # We do not support more than one instance of kube-state-metrics
        instance = instances[0]
        self.cluster_name = AgentCheck.get_cluster_name()
        if self.cluster_name != "":
            instance.get('tags', []).extend(['cluster_name:%s' % self.cluster_name])

        kubernetes_state_instance = self._create_kubernetes_state_prometheus_instance(instance)

        generic_instances = [kubernetes_state_instance]
        super(KubernetesState, self).__init__(name, init_config, agentConfig, instances=generic_instances)

        self.condition_to_status_positive = {'true': self.OK, 'false': self.CRITICAL, 'unknown': self.UNKNOWN}

        self.condition_to_status_negative = {'true': self.CRITICAL, 'false': self.OK, 'unknown': self.UNKNOWN}

        # Parameters for the count_objects_by_tags method
        self.object_count_params = {
            'kube_persistentvolume_status_phase': {
                'metric_name': 'persistentvolumes.by_phase',
                'allowed_labels': ['storageclass', 'phase'],
            },
            'kube_service_spec_type': {'metric_name': 'service.count', 'allowed_labels': ['namespace', 'type']},
        }

        self.METRIC_TRANSFORMERS = {
            'kube_pod_status_phase': self.kube_pod_status_phase,
            'kube_pod_container_status_waiting_reason': self.kube_pod_container_status_waiting_reason,
            'kube_pod_container_status_terminated_reason': self.kube_pod_container_status_terminated_reason,
            'kube_cronjob_next_schedule_time': self.kube_cronjob_next_schedule_time,
            'kube_job_complete': self.kube_job_complete,
            'kube_job_failed': self.kube_job_failed,
            'kube_job_status_failed': self.kube_job_status_failed,
            'kube_job_status_succeeded': self.kube_job_status_succeeded,
            'kube_node_status_condition': self.kube_node_status_condition,
            'kube_node_status_ready': self.kube_node_status_ready,
            'kube_node_status_out_of_disk': self.kube_node_status_out_of_disk,
            'kube_node_status_memory_pressure': self.kube_node_status_memory_pressure,
            'kube_node_status_disk_pressure': self.kube_node_status_disk_pressure,
            'kube_node_status_network_unavailable': self.kube_node_status_network_unavailable,
            'kube_node_spec_unschedulable': self.kube_node_spec_unschedulable,
            'kube_resourcequota': self.kube_resourcequota,
            'kube_limitrange': self.kube_limitrange,
            'kube_persistentvolume_status_phase': self.count_objects_by_tags,
            'kube_service_spec_type': self.count_objects_by_tags,
        }

        # Handling jobs succeeded/failed counts
        self.failed_job_counts = defaultdict(KubernetesState.JobCount)
        self.succeeded_job_counts = defaultdict(KubernetesState.JobCount)
Example #10
0
    def _create_cadvisor_prometheus_instance(self, instance):
        """
        Create a copy of the instance and set default values.
        This is so the base class can create a scraper_config with the proper values.
        """
        cadvisor_instance = deepcopy(instance)
        cadvisor_instance.update(
            {
                'namespace': self.NAMESPACE,
                # We need to specify a prometheus_url so the base class can use it as the key for our config_map,
                # we specify a dummy url that will be replaced in the `check()` function. We append it with "cadvisor"
                # so the key is different than the kubelet scraper.
                'prometheus_url': instance.get('cadvisor_metrics_endpoint', 'dummy_url/cadvisor'),
                'ignore_metrics': [
                    'container_cpu_cfs_periods_total',
                    'container_fs_inodes_free',
                    'container_fs_inodes_total',
                    'container_fs_io_current',
                    'container_fs_io_time_seconds_total',
                    'container_fs_io_time_weighted_seconds_total',
                    'container_fs_read_seconds_total',
                    'container_fs_reads_merged_total',
                    'container_fs_reads_total',
                    'container_fs_sector_reads_total',
                    'container_fs_sector_writes_total',
                    'container_fs_write_seconds_total',
                    'container_fs_writes_merged_total',
                    'container_fs_writes_total',
                    'container_last_seen',
                    'container_start_time_seconds',
                    'container_scrape_error',
                ],
                # Defaults that were set when CadvisorPrometheusScraper was based on PrometheusScraper
                'send_monotonic_counter': instance.get('send_monotonic_counter', False),
                'health_service_check': instance.get('health_service_check', False),
            }
        )

        clustername = AgentCheck.get_cluster_name()
        if clustername != "":
            cadvisor_instance.get('tags', []).extend(['cluster_name:%s' % clustername])

        return cadvisor_instance
Example #11
0
 def __init__(self, name, init_config, instances=None):
     AgentCheck.__init__(self, name, init_config, instances)
     self.url = None
     self.user = None
     self.password = None
 def __init__(self, name, init_config, instances=None):
     AgentCheck.__init__(self, name, init_config, instances)
     self.session = requests.Session()
     self.organization_id = None
Example #13
0
 def __init__(self, name, init_config, agentConfig, instances=None):
     AgentCheck.__init__(self, name, init_config, agentConfig, instances)
     self.dynatrace_entities_cache = None
Example #14
0
 def __init__(self, name, init_config, agentConfig, instances=None):
     AgentCheck.__init__(self, name, init_config, agentConfig, instances)
     self.url = None
     self.tags = None
     self.roles = None