Ejemplo n.º 1
0
def run_test():
    print('Running test ...')
    num_tries = 0
    test_result = fastdotcom.fast_com()

    while test_result == 0 and num_tries < MAX_TRIES_NUMBER:
        num_tries += 1
        test_result = fastdotcom.fast_com()

    print('Test result: {} MB'.format(test_result))
    return test_result
Ejemplo n.º 2
0
    def update(self, now=None):
        """Get the latest data from fast.com."""
        from fastdotcom import fast_com

        _LOGGER.debug("Executing fast.com speedtest")
        self.data = {"download": fast_com()}
        dispatcher_send(self._hass, DATA_UPDATED)
Ejemplo n.º 3
0
    def poll(self):
        """Poll the device for changes."""
        while True:
            value = None

            if self.provider == 'fast.com':
                try:
                    value = fastdotcom.fast_com()
                except:  # noqa
                    pass
            elif self.provider == 'speedtest.net':
                try:
                    t = speedtest.Speedtest()

                    if self.server_id is not None:
                        t.get_servers(servers=[self.server_id])
                    else:
                        t.get_servers()

                    t.get_best_server()
                    t.download()
                    value = t.results.download / 1000 / 1000
                except speedtest.SpeedtestException:
                    pass
            else:
                return

            if value is not None and value != 0:
                prop = self.properties['download']
                prop.set_cached_value(round(value))
                self.notify_property_changed(prop)

            time.sleep(self.poll_interval * 60)
def runTest(thing, duration=10):
    logger.log("Running speed test for:", thing.name, "with maximum duration",
               duration)
    thing.setStateValue(speedtestTestRunningStateTypeId, True)
    result = fast_com(maxtime=duration, verbose=True)
    thing.setStateValue(speedtestLastResultStateTypeId, result)
    logger.log("Speed test result:", result)
    thing.setStateValue(speedtestTestRunningStateTypeId, False)
    param = nymea.Param(speedtestTestCompletedEventResultParamTypeId, result)
    params = [param]
    thing.emitEvent(speedtestTestCompletedEventTypeId, params)
    logger.log("all done")
Ejemplo n.º 5
0
 def update(self, now):
     """Get the latest data from fast.com."""
     from fastdotcom import fast_com
     _LOGGER.info("Executing fast.com speedtest")
     self.data = {'download': fast_com()}
Ejemplo n.º 6
0
 def update(self, now):
     """Get the latest data from fast.com."""
     from fastdotcom import fast_com
     _LOGGER.info('Executing fast.com speedtest')
     self.data = {'download': fast_com()}
Ejemplo n.º 7
0
        web.run_app(app, port=port, loop=loop, handle_signals=False)
    except Exception as e:
        print(e)


if __name__ == '__main__':
    print("Starting Logger")

    open(output_file, "a+").close()

    p = Process(target=run_webserver,
                args=(
                    listen_port,
                    asyncio.get_event_loop(),
                ))
    p.start()

    try:
        while True:
            speed = fastdotcom.fast_com(maxtime=6)
            date = time.strftime(date_format)
            output = log_format.format(date, speed)

            with open(output_file, "a+") as f:
                f.write(output + "\n")

            time.sleep(60 * sleep_min)
    except Exception as e:
        print(e)
        pass
Ejemplo n.º 8
0
    def update(self, now: datetime | None = None) -> None:
        """Get the latest data from fast.com."""

        _LOGGER.debug("Executing fast.com speedtest")
        self.data = {"download": fast_com()}
        dispatcher_send(self._hass, DATA_UPDATED)
Ejemplo n.º 9
0
 def update(self, now=None):
     """Get the latest data from fast.com."""
     from fastdotcom import fast_com
     _LOGGER.debug("Executing fast.com speedtest")
     self.data = {'download': fast_com()}
     dispatcher_send(self._hass, DATA_UPDATED)
Ejemplo n.º 10
0
 def performTest(self):
     """Perform the Fast.com SpeedTest."""
     startTime = datetime.datetime.now()
     downloadSpeed = FastSpeedTest.fast_com() * 1000.0  # convert to Kbps
     return SpeedTestResult(downloadSpeed, startTime)
Ejemplo n.º 11
0
    "ZABBIX_SERVER", os.getenv("ZABBIX_SERVER_PORT_10051_TCP_ADDR",
                               "127.0.0.1"))
zabbix_port = int(
    os.getenv("ZABBIX_PORT",
              os.getenv("ZABBIX_SERVER_PORT_10051_TCP_PORT", 10051)))
zabbix_metric_hostname = os.getenv("ZABBIX_METRIC_HOST", "Zabbix server")
zabbix_metric_key = os.getenv("ZABBIX_METRIC_KEY", "speedtest[fastdotcom]")

if __name__ == '__main__':
    print("Starting Logger")

    open(output_file, "a+").close()

    try:
        while True:
            speed = fastdotcom.fast_com(maxtime=test_duration)
            date = time.strftime(date_format)
            packet = [
                ZabbixMetric(zabbix_metric_hostname, zabbix_metric_key, speed)
            ]
            try:
                result = ZabbixSender(zabbix_server, zabbix_port).send(packet)
            except socket_error as serr:
                result = serr
            output = log_format.format(date, speed, result)

            with open(output_file, "a+") as f:
                f.write(output + "\n")

            time.sleep(60 * sleep_min)
    except Exception as e:
Ejemplo n.º 12
0
def get_network_speed():
    logger.debug('Fetching from fast.com')
    return fastdotcom.fast_com()