Exemple #1
0
def main(config_filename=Defaults.FETCH_CONFIG):
    client = InfluxdbClient(Settings())

    config = None
    with open(config_filename) as f:
        config = json.load(f)
        print "{0} Opened configuration: {1}".format(Symbol.OK_GREEN, f.name)
    assert config

    client.settings.influxdb.update(config['influxdb'])
    assert client.connect()

    for statefile in config['statefiles']:
        try:
            values = read_state_file(statefile)

        except Exception as e:
            print "{0} Could not read state file {1}: {2}".format(Symbol.NOK_RED, statefile, e.message)
            continue
        else:
            print "{0} Parsed: {1}".format(Symbol.OK_GREEN, statefile)

        data = pack_values(config, values)
        if len(data):
            client.upload_multiple_series(data)
            config['lastupdate'] = max(config['lastupdate'], int(values[1]))
        else:
            print Symbol.NOK_RED, "No data found, is Munin still running?"

    with open(config_filename, "w") as f:
        json.dump(config, f)
        print "{0} Updated configuration: {1}".format(Symbol.OK_GREEN, f.name)
Exemple #2
0
def main(config_filename=Defaults.FETCH_CONFIG):
    client = InfluxdbClient()

    config = None
    with open(config_filename) as f:
        config = json.load(f)
        print "{0} Opened configuration: {1}".format(Symbol.OK_GREEN, f.name)
    assert config

    client.settings.influxdb.update(config['influxdb'])
    assert client.connect()

    for statefile in config['statefiles']:
        try:
            values = read_state_file(statefile)

        except Exception as e:
            print "{0} Could not read state file {1}: {2}".format(
                Symbol.NOK_RED, statefile, e.message)
            continue
        else:
            print "{0} Parsed: {1}".format(Symbol.OK_GREEN, statefile)

        data = pack_values(config, values)
        if len(data):
            client.upload_multiple_series(data)
            config['lastupdate'] = max(config['lastupdate'], int(values[1]))
        else:
            print Symbol.NOK_RED, "No data found, is Munin still running?"

    with open(config_filename, "w") as f:
        json.dump(config, f)
        print "{0} Updated configuration: {1}".format(Symbol.OK_GREEN, f.name)
Exemple #3
0
def main(args):
    print("{0}Munin to InfluxDB migration tool{1}".format(Color.BOLD, Color.CLEAR))
    print("-" * 20)

    settings = Settings(args)
    settings = retrieve_munin_configuration(settings)

    # export RRD files as XML for (much) easier parsing (but takes much more time)
    print("\nExporting RRD databases:".format(settings.nb_rrd_files))
    nb_xml = rrd.export_to_xml(settings)
    print("  {0} Exported {1} RRD files to XML ({2})".format(Symbol.OK_GREEN, nb_xml, settings.paths['xml']))

    #reads every XML file and export as in the InfluxDB database
    exporter = InfluxdbClient(settings)
    if settings.interactive:
        exporter.prompt_setup()
    else:
        # even in non-interactive mode, we ask for the password if empty
        if not exporter.settings.influxdb['password']:
            exporter.settings.influxdb['password'] = InfluxdbClient.ask_password()
        exporter.connect()
        exporter.test_db(exporter.settings.influxdb['database'])    # needed to create db if missing

    exporter.import_from_xml()

    settings = exporter.get_settings()
    print("{0} Munin data successfully imported to {1}/db/{2}".format(Symbol.OK_GREEN, settings.influxdb['host'],
                                                                      settings.influxdb['database']))

    settings.save_fetch_config()
    print("{0} Configuration for 'munin-influxdb fetch' exported to {1}".format(Symbol.OK_GREEN,
                                                                                settings.paths['fetch_config']))

    # Generate a JSON file to be uploaded to Grafana
    print("\n{0}Grafaba dashboard{1}".format(Color.BOLD, Color.CLEAR))
    if not settings.influxdb['group_fields'] and settings.grafana['create']:
        print("%s Grafana dashboard generation is only supported in grouped fields mode.", Symbol.NOK_RED)
        return

    if settings.interactive:
        settings.grafana['create'] = (raw_input("Would you like to generate a Grafana dashboard? [y]/n: ") or "y") in ('y', 'Y')

    if settings.grafana['create']:
        dashboard = Dashboard(settings)
        if settings.interactive:
            dashboard.prompt_setup()

        dashboard.generate()

        if settings.grafana['host']:
            try:
                dash_url = dashboard.upload()
            except Exception as e:
                print("{0} Didn't quite work uploading: {1}".format(Symbol.NOK_RED, e))
            else:
                print("{0} A Grafana dashboard has been successfully uploaded to {1}".format(Symbol.OK_GREEN, dash_url))

        if settings.grafana['filename']:
            try:
                dashboard.save()
            except Exception as e:
                print("{0} Could not write Grafana dashboard: {1}".format(Symbol.NOK_RED, e))
            else:
                print("{0} A Grafana dashboard has been successfully generated to {1}".format(Symbol.OK_GREEN, settings.grafana['filename']))
    else:
        print("Then we're good! Have a nice day!")
Exemple #4
0
def main(args):
    print("{0}Munin to InfluxDB migration tool{1}".format(
        Color.BOLD, Color.CLEAR))
    print("-" * 20)

    settings = Settings(args)
    settings = retrieve_munin_configuration(settings)

    # export RRD files as XML for (much) easier parsing (but takes much more time)
    print("\nExporting RRD databases:".format(settings.nb_rrd_files))
    nb_xml = rrd.export_to_xml(settings)
    print("  {0} Exported {1} RRD files to XML ({2})".format(
        Symbol.OK_GREEN, nb_xml, settings.paths['xml']))

    #reads every XML file and export as in the InfluxDB database
    exporter = InfluxdbClient(settings)
    if settings.interactive:
        exporter.prompt_setup()
    else:
        # even in non-interactive mode, we ask for the password if empty
        if not exporter.settings.influxdb['password']:
            exporter.settings.influxdb[
                'password'] = InfluxdbClient.ask_password()
        exporter.connect()
        exporter.test_db(exporter.settings.influxdb['database']
                         )  # needed to create db if missing

    exporter.import_from_xml()

    settings = exporter.get_settings()
    print("{0} Munin data successfully imported to {1}/db/{2}".format(
        Symbol.OK_GREEN, settings.influxdb['host'],
        settings.influxdb['database']))

    settings.save_fetch_config()
    print(
        "{0} Configuration for 'munin-influxdb fetch' exported to {1}".format(
            Symbol.OK_GREEN, settings.paths['fetch_config']))

    # Generate a JSON file to be uploaded to Grafana
    print("\n{0}Grafaba dashboard{1}".format(Color.BOLD, Color.CLEAR))
    if not settings.influxdb['group_fields'] and settings.grafana['create']:
        print(
            "%s Grafana dashboard generation is only supported in grouped fields mode.",
            Symbol.NOK_RED)
        return

    if settings.interactive:
        settings.grafana['create'] = (raw_input(
            "Would you like to generate a Grafana dashboard? [y]/n: ")
                                      or "y") in ('y', 'Y')

    if settings.grafana['create']:
        dashboard = Dashboard(settings)
        if settings.interactive:
            dashboard.prompt_setup()

        dashboard.generate()

        if settings.grafana.get('host'):
            try:
                dash_url = dashboard.upload()
            except Exception as e:
                print("{0} Didn't quite work uploading: {1}".format(
                    Symbol.NOK_RED, e))
            else:
                print(
                    "{0} A Grafana dashboard has been successfully uploaded to {1}"
                    .format(Symbol.OK_GREEN, dash_url))

        if settings.grafana.get('filename'):
            try:
                dashboard.save()
            except Exception as e:
                print("{0} Could not write Grafana dashboard: {1}".format(
                    Symbol.NOK_RED, e))
            else:
                print(
                    "{0} A Grafana dashboard has been successfully generated to {1}"
                    .format(Symbol.OK_GREEN, settings.grafana['filename']))
    else:
        print("Then we're good! Have a nice day!")