blob: 3967ae5163001ec92b50c2f9975429fbf5e4ed7b [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""System metrics."""
from __future__ import absolute_import
from __future__ import print_function
import collections
import platform
import sys
from chromite.lib import metrics
_os_name_metric = metrics.StringMetric(
description='OS name on the machine')
_os_version_metric = metrics.StringMetric(
description='OS version on the machine')
_os_arch_metric = metrics.StringMetric(
description='OS architecture on this machine')
_python_arch_metric = metrics.StringMetric(
description='python userland architecture on this machine')
def collect_os_info():
os_info = _get_osinfo()
class OSInfo(collections.namedtuple('OSInfo', 'name,version')):
"""namedtuple representing OS info (all fields lowercased)."""
def __new__(cls, name, version):
return super(OSInfo, cls).__new__(cls, name.lower(), version.lower())
def _get_osinfo():
"""Get OS name and version.
OSInfo instance
os_name = platform.system()
if os_name == 'Linux':
return _get_linux_osinfo()
return OSInfo(name='', version='')
def _get_linux_osinfo():
# will return something like ('Ubuntu', '14.04', 'trusty')
os_name, os_version, _ = platform.dist()
return OSInfo(name=os_name, version=os_version)
def _get_python_arch():
if sys.maxsize > 2**32:
return '64'
return '32'