Exemple #1
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 Symbol.NOK_RED, "Grafana dashboard generation is only supported in grouped fields mode."
        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()

        try:
            dashboard.save()
        except Exception as e:
            print "{0} Could not write Grafana dashboard: {1}".format(Symbol.NOK_RED, e.message)
        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 #2
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!")