コード例 #1
0
    def load_conf(self, section="cassandra"):
        """Load the Cassandra configuration in the Glances configuration file."""
        if self.config is None:
            return False
        try:
            self.host = self.config.get_value(section, 'host')
            self.port = self.config.get_value(section, 'port')
            self.keyspace = self.config.get_value(section, 'keyspace')
        except NoSectionError:
            logger.critical("No Cassandra configuration found")
            return False
        except NoOptionError as e:
            logger.critical("Error in the Cassandra configuration (%s)" % e)
            return False
        else:
            logger.debug("Load Cassandra from the Glances configuration file")

        # Optionals keys
        try:
            self.protocol_version = self.config.get_value(
                section, 'protocol_version')
        except NoOptionError:
            pass
        try:
            self.replication_factor = self.config.get_value(
                section, 'replication_factor')
        except NoOptionError:
            pass
        try:
            self.table = self.config.get_value(section, 'table')
        except NoOptionError:
            self.table = self.host

        return True
コード例 #2
0
    def init(self):
        """Init the connection to the ES server."""
        if not self.export_enable:
            return None

        try:
            es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)])
        except Exception as e:
            logger.critical(
                "Cannot connect to ElasticSearch server %s:%s (%s)" %
                (self.host, self.port, e))
            sys.exit(2)
        else:
            logger.info("Connected to the ElasticSearch server %s:%s" %
                        (self.host, self.port))

        try:
            index_count = es.count(index=self.index)['count']
        except Exception as e:
            # Index did not exist, it will be created at the first write
            # Create it...
            es.indices.create(self.index)
        else:
            logger.info(
                "There is already %s entries in the ElasticSearch %s index" %
                (index_count, self.index))

        return es
コード例 #3
0
ファイル: glances_opentsdb.py プロジェクト: mondo0/testgl
    def load_conf(self, section="opentsdb"):
        """Load the OpenTSDB configuration in the Glances configuration file."""
        if self.config is None:
            return False
        try:
            self.host = self.config.get_value(section, 'host')
            self.port = self.config.get_value(section, 'port')
        except NoSectionError:
            logger.critical("No OpenTSDB configuration found")
            return False
        except NoOptionError as e:
            logger.critical("Error in the OpenTSDB configuration (%s)" % e)
            return False
        else:
            logger.debug("Load OpenTSDB from the Glances configuration file")

        # Prefix is optional
        try:
            self.prefix = self.config.get_value(section, 'prefix')
        except NoOptionError:
            pass

        # Tags are optional, comma separated key:value pairs.
        try:
            self.tags = self.config.get_value(section, 'tags')
        except NoOptionError:
            pass

        return True
コード例 #4
0
ファイル: glances_riemann.py プロジェクト: mondo0/testgl
 def init(self):
     """Init the connection to the Riemann server."""
     if not self.export_enable:
         return None
     try:
         client = bernhard.Client(host=self.riemann_host,
                                  port=self.riemann_port)
         return client
     except Exception as e:
         logger.critical("Connection to Riemann failed : %s " % e)
         return None
コード例 #5
0
ファイル: glances_opentsdb.py プロジェクト: mondo0/testgl
    def init(self):
        """Init the connection to the OpenTSDB server."""
        if not self.export_enable:
            return None

        try:
            db = potsdb.Client(self.host, port=int(self.port), check_host=True)
        except Exception as e:
            logger.critical("Cannot connect to OpenTSDB server %s:%s (%s)" %
                            (self.host, self.port, e))
            sys.exit(2)

        return db
コード例 #6
0
ファイル: screen.py プロジェクト: mondo0/testgl
    def __init__(self, config=None, args=None):
        # Init
        self.config = config
        self.args = args

        # Init windows positions
        self.term_w = 80
        self.term_h = 24

        # Space between stats
        self.space_between_column = 3
        self.space_between_line = 2

        # Init the curses screen
        self.screen = curses.initscr()
        if not self.screen:
            logger.critical("Cannot init the curses library.\n")
            sys.exit(1)

        # Load the 'outputs' section of the configuration file
        # - Init the theme (default is black)
        self.theme = {'name': 'black'}
        self.load_config(self.config)

        # Init cursor
        self._init_cursor()

        # Init the colors
        self._init_colors()

        # Init main window
        self.term_window = self.screen.subwin(0, 0)

        # Init refresh time
        self.__refresh_time = args.time

        # Init edit filter tag
        self.edit_filter = False

        # Init the process min/max reset
        self.args.reset_minmax_tag = False

        # Catch key pressed with non blocking mode
        self.no_flash_cursor()
        self.term_window.nodelay(1)
        self.pressedkey = -1

        # History tag
        self._init_history()
コード例 #7
0
ファイル: glances_rabbitmq.py プロジェクト: mondo0/testgl
 def init(self):
     """Init the connection to the rabbitmq server."""
     if not self.export_enable:
         return None
     try:
         parameters = pika.URLParameters('amqp://' + self.rabbitmq_user +
                                         ':' + self.rabbitmq_password +
                                         '@' + self.rabbitmq_host + ':' +
                                         self.rabbitmq_port + '/')
         connection = pika.BlockingConnection(parameters)
         channel = connection.channel()
         return channel
     except Exception as e:
         logger.critical("Connection to rabbitMQ failed : %s " % e)
         return None
コード例 #8
0
ファイル: glances_riemann.py プロジェクト: mondo0/testgl
 def load_conf(self, section="riemann"):
     """Load the Riemann configuration in the Glances configuration file."""
     if self.config is None:
         return False
     try:
         self.riemann_host = self.config.get_value(section, 'host')
         self.riemann_port = int(self.config.get_value(section, 'port'))
     except NoSectionError:
         logger.critical("No riemann configuration found")
         return False
     except NoOptionError as e:
         logger.critical("Error in the Riemann configuration (%s)" % e)
         return False
     else:
         logger.debug("Load Riemann from the Glances configuration file")
     return True
コード例 #9
0
ファイル: glances_rabbitmq.py プロジェクト: mondo0/testgl
 def load_conf(self, section="rabbitmq"):
     """Load the rabbitmq configuration in the Glances configuration file."""
     if self.config is None:
         return False
     try:
         self.rabbitmq_host = self.config.get_value(section, 'host')
         self.rabbitmq_port = self.config.get_value(section, 'port')
         self.rabbitmq_user = self.config.get_value(section, 'user')
         self.rabbitmq_password = self.config.get_value(section, 'password')
         self.rabbitmq_queue = self.config.get_value(section, 'queue')
     except NoSectionError:
         logger.critical("No rabbitmq configuration found")
         return False
     except NoOptionError as e:
         logger.critical("Error in the RabbitM configuration (%s)" % e)
         return False
     else:
         logger.debug("Load RabbitMQ from the Glances configuration file")
     return True
コード例 #10
0
    def init(self):
        """Init the connection to the InfluxDB server."""
        if not self.export_enable:
            return None

        # Cluster
        try:
            cluster = Cluster([self.host],
                              port=int(self.port),
                              protocol_version=int(self.protocol_version))
            session = cluster.connect()
        except Exception as e:
            logger.critical(
                "Cannot connect to Cassandra cluster '%s:%s' (%s)" %
                (self.host, self.port, e))
            sys.exit(2)

        # Keyspace
        try:
            session.set_keyspace(self.keyspace)
        except InvalidRequest as e:
            logger.info("Create keyspace {} on the Cassandra cluster".format(
                self.keyspace))
            c = "CREATE KEYSPACE %s WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '%s' }" % (
                self.keyspace, self.replication_factor)
            session.execute(c)
            session.set_keyspace(self.keyspace)

        logger.info(
            "Stats will be exported to Cassandra cluster {0} ({1}) in keyspace {2}"
            .format(cluster.metadata.cluster_name,
                    cluster.metadata.all_hosts(), self.keyspace))

        # Table
        try:
            session.execute(
                "CREATE TABLE %s (plugin text, time timeuuid, stat map<text,float>, PRIMARY KEY (plugin, time)) WITH CLUSTERING ORDER BY (time DESC)"
                % self.table)
        except:
            logger.debug("Cassandra table %s already exist" % self.table)

        return cluster, session
コード例 #11
0
    def load_conf(self, section="elasticsearch"):
        """Load the ES configuration in the Glances configuration file."""
        if self.config is None:
            return False
        try:
            self.host = self.config.get_value(section, 'host')
            self.port = self.config.get_value(section, 'port')
            self.index = self.config.get_value(section, 'index')
        except NoSectionError:
            logger.critical("No ElasticSearch configuration found")
            return False
        except NoOptionError as e:
            logger.critical("Error in the ElasticSearch configuration (%s)" %
                            e)
            return False
        else:
            logger.debug(
                "Load ElasticSearch from the Glances configuration file")

        return True
コード例 #12
0
 def load_conf(self, section="statsd"):
     """Load the Statsd configuration in the Glances configuration file."""
     if self.config is None:
         return False
     try:
         self.host = self.config.get_value(section, 'host')
         self.port = self.config.get_value(section, 'port')
     except NoSectionError:
         logger.critical("No Statsd configuration found")
         return False
     except NoOptionError as e:
         logger.critical("Error in the Statsd configuration (%s)" % e)
         return False
     else:
         logger.debug("Load Statsd from the Glances configuration file")
     # Prefix is optional
     try:
         self.prefix = self.config.get_value(section, 'prefix')
     except NoOptionError:
         pass
     return True
コード例 #13
0
ファイル: glances_influxdb.py プロジェクト: mondo0/testgl
    def init(self):
        """Init the connection to the InfluxDB server."""
        if not self.export_enable:
            return None

        try:
            db = InfluxDBClient(host=self.host,
                                port=self.port,
                                username=self.user,
                                password=self.password,
                                database=self.db)
            get_all_db = [i['name'] for i in db.get_list_database()]
            self.version = INFLUXDB_09PLUS
        except InfluxDBClientError:
            # https://github.com/influxdb/influxdb-python/issues/138
            logger.info("Trying fallback to InfluxDB v0.8")
            db = InfluxDBClient08(host=self.host,
                                  port=self.port,
                                  username=self.user,
                                  password=self.password,
                                  database=self.db)
            get_all_db = [i['name'] for i in db.get_list_database()]
            self.version = INFLUXDB_08
        except InfluxDBClientError08 as e:
            logger.critical("Cannot connect to InfluxDB database '%s' (%s)" %
                            (self.db, e))
            sys.exit(2)

        if self.db in get_all_db:
            logger.info("Stats will be exported to InfluxDB server: {}".format(
                db._baseurl))
        else:
            logger.critical(
                "InfluxDB database '%s' did not exist. Please create it" %
                self.db)
            sys.exit(2)

        return db
コード例 #14
0
    def __init__(self, config=None, args=None):
        """Init the CSV export IF."""
        super(Export, self).__init__(config=config, args=args)

        # CSV file name
        self.csv_filename = args.export_csv

        # Set the CSV output file
        try:
            if PY3:
                self.csv_file = open(self.csv_filename, 'w', newline='')
            else:
                self.csv_file = open(self.csv_filename, 'wb')
            self.writer = csv.writer(self.csv_file)
        except IOError as e:
            logger.critical("Cannot create the CSV file: {}".format(e))
            sys.exit(2)

        logger.info("Stats exported to CSV file: {}".format(self.csv_filename))

        self.export_enable = True

        self.first_line = True
コード例 #15
0
ファイル: main.py プロジェクト: mondo0/testgl
    def parse_args(self):
        """Parse command line arguments."""
        args = self.init_args().parse_args()

        # Load the configuration file, if it exists
        self.config = Config(args.conf_file)

        # Debug mode
        if args.debug:
            from logging import DEBUG
            logger.setLevel(DEBUG)

        # By default help is hidden
        args.help_tag = False

        # Display Rx and Tx, not the sum for the network
        args.network_sum = False
        args.network_cumul = False

        # Manage full quicklook option
        if args.full_quicklook:
            logger.info("Disable QuickLook menu")
            args.disable_quicklook = False
            args.disable_cpu = True
            args.disable_mem = True
            args.disable_swap = True
            args.disable_load = False

        # Manage disable_top option
        if args.disable_top:
            logger.info("Disable top menu")
            args.disable_quicklook = True
            args.disable_cpu = True
            args.disable_mem = True
            args.disable_swap = True
            args.disable_load = True

        # Control parameter and exit if it is not OK
        self.args = args

        # Check graph output path
        if args.export_graph and args.path_graph is not None:
            if not os.access(args.path_graph, os.W_OK):
                logger.critical(
                    "Graphs output path {0} do not exist or is not writable".
                    format(args.path_graph))
                sys.exit(2)
            logger.debug("Graphs output path is set to {0}".format(
                args.path_graph))

        # For export graph, history is mandatory
        if args.export_graph and args.disable_history:
            logger.critical("Can not export graph if history is disabled")
            sys.exit(2)

        # Disable HDDTemp if sensors are disabled
        if args.disable_sensors:
            args.disable_hddtemp = True
            logger.debug("Sensors and HDDTemp are disabled")

        return args
コード例 #16
0
ファイル: screen.py プロジェクト: mondo0/testgl
import re
import sys

from gl.compat import u
from gl.logger import logger
from gl.logs import glances_logs
from gl.processes import gl_processes
from gl.timer import Timer

# Import curses lib for "normal" operating system and consolelog for Windows
try:
    import curses
    import curses.panel
    from curses.textpad import Textbox
except ImportError:
    logger.critical(
        "Curses module not found. Glances cannot start in standalone mode.")
    sys.exit(1)


class Screen(object):
    """This class manages the curses display (and key pressed)."""
    def __init__(self, config=None, args=None):
        # Init
        self.config = config
        self.args = args

        # Init windows positions
        self.term_w = 80
        self.term_h = 24

        # Space between stats