Ejemplo n.º 1
0
    def test_utc(self):
        nyc = tz.gettz('America/New_York')
        now = datetime.now(nyc)

        normalized = ensure_aware_datetime(now)

        assert normalized is now
        assert normalized.tzinfo is nyc
Ejemplo n.º 2
0
def test_stats_metrics(aggregator, instance):
    instance['mqcd_version'] = os.getenv('IBM_MQ_VERSION')

    check = IbmMqCheck('ibm_mq', {}, [instance])

    # make sure time is before fixture messages start time
    check.config.instance_creation_datetime = ensure_aware_datetime(
        dt.datetime(year=2000, month=1, day=1))

    with open(os.path.join(common.HERE, 'fixtures', 'statistics_channel.data'),
              'rb') as channel_file, open(
                  os.path.join(common.HERE, 'fixtures',
                               'statistics_queue.data'), 'rb') as queue_file:
        channel_data = channel_file.read()
        queue_data = queue_file.read()
        with mock.patch(
                'datadog_checks.ibm_mq.collectors.stats_collector.Queue'
        ) as queue:
            queue().get.side_effect = [
                channel_data,
                queue_data,
                MQMIError(MQCC_FAILED, MQRC_NO_MSG_AVAILABLE),
            ]
            check.check(instance)

    common_tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
        'connection_name:{}({})'.format(common.HOST, common.PORT),
        'foo:bar',
    ]
    channel_tags = common_tags + [
        'channel:GCP.A',
        'channel_type:clusrcvr',
        'remote_q_mgr_name:QM2',
        'connection_name:192.168.32.2',
    ]
    for metric, metric_type in common.CHANNEL_STATS_METRICS:
        aggregator.assert_metric(metric,
                                 metric_type=getattr(aggregator,
                                                     metric_type.upper()),
                                 tags=channel_tags)

    queue_tags = common_tags + [
        'definition_type:predefined',
        'queue:SYSTEM.CHLAUTH.DATA.QUEUE',
        'queue_type:local',
    ]
    for metric, metric_type in common.QUEUE_STATS_METRICS:
        aggregator.assert_metric(metric,
                                 metric_type=getattr(aggregator,
                                                     metric_type.upper()),
                                 tags=queue_tags)

    assert_all_metrics(aggregator)
    aggregator.assert_metrics_using_metadata(get_metadata_metrics())
Ejemplo n.º 3
0
def to_time_elapsed(datetime):
    # type: (dt.datetime) -> float
    datetime = ensure_aware_datetime(datetime)
    elapsed = dt.datetime.now(datetime.tzinfo) - datetime
    return elapsed.total_seconds()
Ejemplo n.º 4
0
    def test_replace(self):
        now = datetime.now()
        assert now.tzinfo is None

        assert ensure_aware_datetime(now).tzinfo is UTC