예제 #1
0
def monitor_standalone(cli, args, log):
    datasources_by_instance = cli.list_datasources()
    log.info("Format: Instance - DSName: active/available (max used) - %")
    for instance in datasources_by_instance:
        datasources = datasources_by_instance[instance].keys()
        for ds in datasources:
            stats = cli.read_datasource_statistics(ds, instance)

            active_count = int(stats['ActiveCount'])
            available_count = int(stats['AvailableCount'])
            max_used_count = int(stats['MaxUsedCount'])
            in_use_count = int(stats['InUseCount'])

            active_percentage = 100 * (float(active_count) / float(available_count)) if available_count > 0 else 0
            idle_count = active_count - in_use_count
            in_use_percentage = 100 * (float(in_use_count) / float(active_count)) if active_count > 0 else 0

            log.info("%s - %s: %i/%i (%.2f%% active) (%i max), %i/%i (%.2f%% in use)", instance, ds, active_count, available_count, active_percentage, max_used_count, in_use_count, idle_count, in_use_percentage)

            header = "host;server;ds;active_count;available_count;active_percentage;max_used_count;in_use_count;idle_count;in_use_percentage"
            stats = "{0};{1};{2};{3};{4};{5:.2f};{6};{7};{8};{9:.2f}".format(instance.host, instance.name, ds, active_count, available_count, active_percentage, max_used_count, in_use_count, idle_count, in_use_percentage)
            monitor.write_statistics(header, stats, "stats-ds.csv")

            if (active_percentage > 95):
                log.critical("%s - %s is critical: %.2f%% active connections.", instance, ds, active_percentage)
                cli.flush_idle_connections(ds, instance)
                log.critical("%s - %s %i idle connections flushed.", instance, ds, idle_count)
예제 #2
0
def monitor_domain(cli, args, log):
    instances = cli.instances
    max_heap_usage = args.max_heap_usage

    instances_to_restart = []

    for instance in instances:
        try:
            used_heap, max_heap = cli.read_used_heap(
                instance.host, instance.name
            )

            heap_usage = 100 * (used_heap / max_heap)
            log.info(
                "%s heap: %.2f gb (out of %.2f - %.2f%%)",
                instance, used_heap, max_heap, heap_usage
            )

            header = "host;server;used_heap;max_heap;heap_usage"
            stats = "{0};{1};{2:.2f};{3:.2f};{4:.2f}".format(
                instance.host, instance.name, used_heap, max_heap, heap_usage
            )

            monitor.write_statistics(header, stats, "stats-heap.csv")

            if (heap_usage > max_heap_usage):
                log.critical("%s is critical: %.2f%%", instance, heap_usage)
                instances_to_restart.append(instance)

        except Exception as e:
            log.error("An error occurred while monitoring %s", instance)
            log.exception(e)

    restart_count = len(instances_to_restart)
    if (restart_count > 0):
        log.info("Restarting %i instances", restart_count)
        for instance in instances_to_restart:
            log.critical("Restarting %s...", instance)
            cli.restart(instance.host, instance.name)
예제 #3
0
def monitor_standalone(cli, args, log):
    datasources_by_instance = cli.list_datasources()
    log.info("Format: Instance - DSName: active/available (max used) - %")
    for instance in datasources_by_instance:
        datasources = datasources_by_instance[instance].keys()
        for ds in datasources:
            stats = cli.read_datasource_statistics(ds, instance)

            active_count = int(stats['ActiveCount'])
            available_count = int(stats['AvailableCount'])
            max_used_count = int(stats['MaxUsedCount'])
            in_use_count = int(stats['InUseCount'])

            active_percentage = 100 * (
                float(active_count) /
                float(available_count)) if available_count > 0 else 0
            idle_count = active_count - in_use_count
            in_use_percentage = 100 * (
                float(in_use_count) /
                float(active_count)) if active_count > 0 else 0

            log.info(
                "%s - %s: %i/%i (%.2f%% active) (%i max), %i/%i (%.2f%% in use)",
                instance, ds, active_count, available_count, active_percentage,
                max_used_count, in_use_count, idle_count, in_use_percentage)

            header = "host;server;ds;active_count;available_count;active_percentage;max_used_count;in_use_count;idle_count;in_use_percentage"
            stats = "{0};{1};{2};{3};{4};{5:.2f};{6};{7};{8};{9:.2f}".format(
                instance.host, instance.name, ds, active_count,
                available_count, active_percentage, max_used_count,
                in_use_count, idle_count, in_use_percentage)
            monitor.write_statistics(header, stats, "stats-ds.csv")

            if (active_percentage > 95):
                log.critical("%s - %s is critical: %.2f%% active connections.",
                             instance, ds, active_percentage)
                cli.flush_idle_connections(ds, instance)
                log.critical("%s - %s %i idle connections flushed.", instance,
                             ds, idle_count)