예제 #1
0
    def send_telemetry(self):
        logger.info(
            'Uploading telemetry data to {0}'.format(TELEMETRY_ENDPOINT_PATH))
        conf = Configuration.Configuration()
        conf.LoadTrainsConfig()
        manifest = conf.SystemManifest()
        headers = {
            'X-iXSystems-Project': Configuration.Avatar(),
            'X-iXSystems-Version': manifest.Version(),
            'X-iXSystems-HostID': self.hostuuid,
            'X-iXSystems-Train': conf.CurrentTrain()
        }

        manifest = {
            'host_uuid': self.hostuuid,
            'cpu_type': sysctl.sysctlbyname("hw.model"),
            'cpu_clock': sysctl.sysctlbyname("hw.clockrate"),
            'cpu_cores': sysctl.sysctlbyname("hw.ncpu"),
            'hypervisor': sysctl.sysctlbyname("kern.vm_guest"),
            'mem_size': sysctl.sysctlbyname("hw.physmem")
        }

        files = {
            name: open(os.path.join(TELEMETRY_STAGING_PATH, name), 'rb')
            for name in os.listdir(TELEMETRY_STAGING_PATH)
        }

        files['manifest'] = (None, json.dumps(manifest), 'application/json')

        try:
            requests.post(TELEMETRY_ENDPOINT_PATH,
                          headers=headers,
                          files=files)
        except BaseException as err:
            logger.error('Cannot send telemerty data: {0}'.format(str(err)))