Esempio n. 1
0
def nova_hypervisors_stats():
    """Get stats from the nova API and add them as Goldstone metrics."""
    from goldstone.models import es_conn, daily_index

    novaclient = get_nova_client()
    response = novaclient.hypervisors.statistics()._info
    region = get_keystone_region()
    metric_prefix = 'nova.hypervisor.'
    now = arrow.utcnow()
    conn = es_conn()
    es_index = daily_index(METRIC_INDEX_PREFIX)
    es_doc_type = METRIC_DOCTYPE

    for key, value in response.items():
        doc = {
            'type': es_doc_type,
            'name': metric_prefix + key,
            'value': value,
            'metric_type': 'gauge',
            '@timestamp': now.isoformat(),
            'region': region
        }

        if key in ['disk_available_least', 'free_disk_gb', 'local_gb',
                   'local_gb_used']:
            doc['unit'] = 'GB'
        elif key in ['free_ram_mb', 'memory_mb', 'memory_mb_used']:
            doc['unit'] = 'MB'
        else:
            doc['unit'] = 'count'

        conn.create(es_index, es_doc_type, doc)
Esempio n. 2
0
def nova_hypervisors_stats():
    """Get stats from the nova API and add them as Goldstone metrics."""
    from goldstone.utils import get_nova_client
    from goldstone.models import es_conn, daily_index

    novaclient = get_nova_client()['client']
    response = \
        novaclient.hypervisors.statistics()._info     # pylint: disable=W0212
    region = get_region_for_nova_client(novaclient)
    metric_prefix = 'nova.hypervisor.'
    now = arrow.utcnow()
    conn = es_conn()
    es_index = daily_index(MetricData.INDEX_PREFIX)
    es_doc_type = MetricData._doc_type.name      # pylint: disable=W0212

    for key, value in response.items():
        doc = {
            'type': es_doc_type,
            'name': metric_prefix + key,
            'value': value,
            'metric_type': 'gauge',
            '@timestamp': now.isoformat(),
            'region': region
        }

        if key in ['disk_available_least', 'free_disk_gb', 'local_gb',
                   'local_gb_used']:
            doc['unit'] = 'GB'
        elif key in ['free_ram_mb', 'memory_mb', 'memory_mb_used']:
            doc['unit'] = 'MB'
        else:
            doc['unit'] = 'count'

        conn.create(es_index, es_doc_type, doc)
Esempio n. 3
0
    def save(self, using=None, index=None, **kwargs):
        """Posts a record to the database.

        See elasticsearch-dsl for parameter information.
        """

        if index is None:
            index = daily_index(self.INDEX_PREFIX)

        return super(DailyIndexDocType, self).save(using, index, **kwargs)
Esempio n. 4
0
 def test_daily_index(self):
     """Date string test."""
     date_str = arrow.utcnow().format("YYYY.MM.DD")
     self.assertEqual(daily_index("xyz-"), "xyz-" + date_str)
Esempio n. 5
0
 def test_daily_index(self):
     """Date string test."""
     date_str = arrow.utcnow().format('YYYY.MM.DD')
     self.assertEqual(daily_index("xyz-"), "xyz-" + date_str)