define_config_option(__monitor__, 'id',
                     'Optional. Included in each log message generated by this monitor, as a field named ``instance``.  '
                     'Allows you to distinguish between values recorded by different monitors. This is especially '
                     'useful if you are running multiple Apache instances on a single server; you can monitor each '
                     'instance with a separate apache_monitor record in the Scalyr Agent configuration.',
                     convert_to=str)
define_config_option(__monitor__, 'status_url',
                     'Optional.  Specifies the URL -- in particular, the port number -- at which the Apache status '
                     'module is served.  The URL should end in ``/?auto`` to indicate the machine-readable version of '
                     'the page should be returned.', default='http://localhost/server-status/?auto')
define_config_option(__monitor__, 'source_address',
                     'Optional (defaults to \'%s\'). The IP address to be used as the source address when fetching '
                     'the status URL.  Many servers require this to be 127.0.0.1 because they only server the status '
                     'page to requests from localhost.' % httpSourceAddress, default=httpSourceAddress)

define_log_field(__monitor__, 'monitor', 'Always ``apache_monitor``.')
define_log_field(__monitor__, 'metric', 'The metric name.  See the metric tables for more information.')
define_log_field(__monitor__, 'value', 'The value of the metric.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration.')

define_metric(__monitor__, 'apache.connections.active', 'The number of connections that are being handled '
                                                        'asynchronously (not using  workers) currently open on the '
                                                        'server')
define_metric(__monitor__, 'apache.connections.writing', 'The number of connections that are being handled '
                                                         'asynchronously (not using workers) that are currently '
                                                         'writing response data.')
define_metric(__monitor__, 'apache.connections.idle', 'The number of connections that are being handled '
                                                      'asynchronously (not using workers) that are currently '
                                                      'idle / sending keepalives.')
define_metric(__monitor__, 'apache.connections.closing', 'The number of connections that are being handled '
                                                         'asynchronously (not using workers) that are currently '
        memory_pools[i],
        extra_fields={"pool": i},
        cumulative=False,
        category="memory",
    )
    define_metric(
        __monitor__,
        "tomcat.memory_pools.used",
        "%s.  The total amount of memory used within the memory pool." %
        memory_pools[i],
        extra_fields={"pool": i},
        cumulative=False,
        category="memory",
    )

define_log_field(__monitor__, "monitor", "Always ``tomcat_monitor``.")
define_log_field(__monitor__, "instance",
                 "The ``id`` value from the monitor configuration.")
define_log_field(
    __monitor__, "metric",
    'The name of a metric being measured, e.g. "tomcat.runtime".')
define_log_field(__monitor__, "value", "The metric value.")


# Taken from:
#   http://stackoverflow.com/questions/1150332/source-interface-with-python-and-urllib2
#
# For connecting to local machine, specifying the source IP may be required.  So, using
# this mechanism should allow that.  Since getting status requires "opening up" a
# non-standard/user-facing web page, it is best to be cautious.
#
Example #3
0
define_config_option(__monitor__, 'command',
                     'The shell command to execute.', required_option=True)
define_config_option(__monitor__, 'extract',
                     'Optional: a regular expression to apply to the command output. If defined, this expression must '
                     'contain a matching group (i.e. a subexpression enclosed in parentheses). The monitor will record '
                     'only the content of that matching group. This allows you to discard unnecessary portions of the '
                     'command output and extract the information you need.', default="")
define_config_option(__monitor__, 'log_all_lines',
                     'Optional (defaults to false). If true, the monitor will record the entire command output; '
                     'otherwise, it only records the first line.', default=False)
define_config_option(__monitor__, 'max_characters',
                     'Optional (defaults to 200). At most this many characters of output are recorded. You may specify '
                     'a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.',
                     default=200, convert_to=int, min_value=0, max_value=10000)

define_log_field(__monitor__, 'monitor', 'Always ``shell_monitor``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration, e.g. ``kernel-version``.')
define_log_field(__monitor__, 'command', 'The shell command for this plugin instance, e.g. ``uname -r``.')
define_log_field(__monitor__, 'metric', 'Always ``output``.')
define_log_field(__monitor__, 'value', 'The output of the shell command, e.g. ``3.4.73-64.112.amzn1.x86_64``.')


# Pattern that matches the first line of a string
__first_line_pattern__ = re.compile('[^\r\n]+')


# ShellMonitor implementation
class ShellMonitor(ScalyrMonitor):
    """A Scalyr agent monitor which executes a specified shell command, and records the output.
    """
Example #4
0
    __monitor__,
    'log_all_lines',
    'Optional (defaults to false). If true, the monitor will record the entire command output; '
    'otherwise, it only records the first line.',
    default=False)
define_config_option(
    __monitor__,
    'max_characters',
    'Optional (defaults to 200). At most this many characters of output are recorded. You may specify '
    'a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.',
    default=200,
    convert_to=int,
    min_value=0,
    max_value=10000)

define_log_field(__monitor__, 'monitor', 'Always ``url_monitor``.')
define_log_field(
    __monitor__, 'instance',
    'The ``id`` value from the monitor configuration, e.g. ``instance-type``.')
define_log_field(
    __monitor__, 'url', 'The URL that was retrieved, e.g. '
    '``http:/^^^/169.254.169.254/latest/meta-data/instance-type``.')
define_log_field(__monitor__, 'metric', 'Always ``response``.')
define_log_field(__monitor__, 'status',
                 'The HTTP response code, e.g. 200 or 404.')
define_log_field(__monitor__, 'length', 'The length of the HTTP response.')
define_log_field(__monitor__, 'value', 'The body of the HTTP response.')

# Pattern that matches the first line of a string
first_line_pattern = re.compile('[^\r\n]+')
    "Optional (defaults to 100K).  The maximum size of a single request in bytes.",
    default=100 * 1024,
    min_value=1000,
    convert_to=int,
)
define_config_option(
    __monitor__,
    "buffer_size",
    "Optional (defaults to 100KB).  The maximum buffer size in bytes for buffering incoming requests "
    "per connection",
    default=100 * 1024,
    min_value=10 * 1024,
    convert_to=int,
)

define_log_field(__monitor__, "monitor", "Always ``graphite_monitor``.")
define_log_field(__monitor__, "metric", "The Graphite metric name.")
define_log_field(__monitor__, "value", "The Graphite metric value.")
define_log_field(__monitor__, "orig_time", "The Graphite timestamp.")


class GraphiteMonitor(ScalyrMonitor):
    """A Scalyr agent monitor acts as a Graphite server, accepting metrics over a network connection and then sends
    them to Scalyr.
    """
    def _initialize(self):
        """Performs monitor-specific initialization.
        """
        self.__only_accept_local = self._config.get("only_accept_local")
        self.__accept_plaintext = self._config.get("accept_plaintext")
        self.__accept_pickle = self._config.get("accept_pickle")
Example #6
0
    "Optional (defaults to false). If true, the monitor will record the entire command output; "
    "otherwise, it only records the first line.",
    default=False,
)
define_config_option(
    __monitor__,
    "max_characters",
    "Optional (defaults to 200). At most this many characters of output are recorded. You may specify "
    "a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.",
    default=200,
    convert_to=int,
    min_value=0,
    max_value=10000,
)

define_log_field(__monitor__, "monitor", "Always ``url_monitor``.")
define_log_field(
    __monitor__,
    "instance",
    "The ``id`` value from the monitor configuration, e.g. ``instance-type``.",
)
define_log_field(
    __monitor__,
    "url",
    "The URL that was retrieved, e.g. "
    "``http:/^^^/169.254.169.254/latest/meta-data/instance-type``.",
)
define_log_field(__monitor__, "metric", "Always ``response``.")
define_log_field(__monitor__, "status",
                 "The HTTP response code, e.g. 200 or 404.")
define_log_field(__monitor__, "length", "The length of the HTTP response.")
        "tomcat.memory_pools.max",
        "%s.  The maximum amount of memory allocated to the memory pool." % memory_pools[i],
        extra_fields={"pool": i},
        cumulative=False,
        category="memory",
    )
    define_metric(
        __monitor__,
        "tomcat.memory_pools.used",
        "%s.  The total amount of memory used within the memory pool." % memory_pools[i],
        extra_fields={"pool": i},
        cumulative=False,
        category="memory",
    )

define_log_field(__monitor__, "monitor", "Always ``tomcat_monitor``.")
define_log_field(__monitor__, "instance", "The ``id`` value from the monitor configuration.")
define_log_field(__monitor__, "metric", 'The name of a metric being measured, e.g. "tomcat.runtime".')
define_log_field(__monitor__, "value", "The metric value.")

# Taken from:
#   http://stackoverflow.com/questions/1150332/source-interface-with-python-and-urllib2
#
# For connecting to local machine, specifying the source IP may be required.  So, using
# this mechanism should allow that.  Since getting status requires "opening up" a
# non-standard/user-facing web page, it is best to be cautious.
#
# Note - the use of a global is ugly, but this form is more compatible than with another
# method mentioned which would not require the global.  (The cleaner version was added
# in Python 2.7.)
class BindableHTTPConnection(httplib.HTTPConnection):
              'The total number of dropped packets broken down by interface and direction.',
              extra_fields={'direction': '', 'iface': ''}, cumulative=True, category='network interfaces')

define_metric(__monitor__, 'proc.meminfo.memtotal',
              'The total number of 1 KB pages of RAM.', unit='bytes:1024', category='memory')
define_metric(__monitor__, 'proc.meminfo.memfree',
              'The total number of unused 1 KB pages of RAM. This does not include the number of cached pages which '
              'can be used when allocating memory.', unit='bytes:1024', category='memory')
define_metric(__monitor__, 'proc.meminfo.cached',
              'The total number of 1 KB pages of RAM being used to cache blocks from the filesystem.  These can be '
              'reclaimed as used to allocate memory as needed.', unit='bytes:1024', category='memory')
define_metric(__monitor__, 'proc.meminfo.buffered',
              'The total number of 1 KB pages of RAM being used in system buffers.', unit='bytes:1024',
              category='memory')

define_log_field(__monitor__, 'monitor', 'Always ``linux_system_metrics``.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "proc.stat.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')


class TcollectorOptions(object):
    """Bare minimum implementation of an object to represent the tcollector options.

    We require this to pass into tcollector to control how it is run.
    """
    def __init__(self):
        # The collector directory.
        self.cdir = None
        # An option we created to prevent the tcollector code from failing on fatal in certain locations.
        # Instead, an exception will be thrown.
        self.no_fatal_on_error = True
Example #9
0
    "oid_groups",
    'A JSON object that maps custom names to a list of OIDs/variables defined as strings such "group1" : ["IF-MIB::ifDescr",  "1.3.6.1.2.1.2.2.1.16.1"].',
    default=None,
)

define_config_option(
    __monitor__,
    "poll_targets",
    "A JSON array contain a list of target devices to poll.  Each element of the array is a JSON object that contains"
    'a list of target devices, and a list of "oid_groups" to query.  Each "target device" in the list is a JSON object containing'
    'variables that define the target (host, port, authentication details) and each "oid_group" is a string key from the'
    'previously defined "oid_groups" configuration option.',
    default=None,
)

define_log_field(__monitor__, "monitor", "Always ``snmp_monitor``.")
define_log_field(
    __monitor__,
    "poll_target",
    "The device that was queried to retrieve this value, e.g. ``demo.snpmlabs.com``",
)
define_log_field(
    __monitor__, "oid",
    'The OID for the retrieved value, e.g. ``IF-MIB::ifDescr."1"``')
define_log_field(__monitor__, "value", "The value reported by the device.")


class SNMPMonitor(ScalyrMonitor):
    """
    The SNMP Monitor polls SNMP-enabled devices on the network to collect values specified in the configuration
    file.
Example #10
0
    'Optional (defaults to 200). At most this many characters of output are recorded. You may specify '
    'a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.',
    default=200,
    convert_to=int,
    min_value=0,
    max_value=10000)
define_config_option(
    __monitor__,
    'interval_secs',
    'Optional (defaults to 30). The sample interval in seconds.  Min 1, Max 86400 (one day)',
    default=30,
    convert_to=int,
    min_value=1,
    max_value=86400)

define_log_field(__monitor__, 'monitor', 'Always ``shell_monitor``.')
define_log_field(
    __monitor__, 'instance',
    'The ``id`` value from the monitor configuration, e.g. ``kernel-version``.'
)
define_log_field(
    __monitor__, 'command',
    'The shell command for this plugin instance, e.g. ``uname -r``.')
define_log_field(__monitor__, 'metric', 'Always ``output``.')
define_log_field(
    __monitor__, 'value',
    'The output of the shell command, e.g. ``3.4.73-64.112.amzn1.x86_64``.')

# Pattern that matches the first line of a string
__first_line_pattern__ = re.compile('[^\r\n]+')
Example #11
0
        'tomcat.memory_pools.max',
        '%s.  The maximum amount of memory allocated to the memory pool.' %
        memory_pools[i],
        extra_fields={'pool': i},
        cumulative=False,
        category='memory')
    define_metric(
        __monitor__,
        'tomcat.memory_pools.used',
        '%s.  The total amount of memory used within the memory pool.' %
        memory_pools[i],
        extra_fields={'pool': i},
        cumulative=False,
        category='memory')

define_log_field(__monitor__, 'monitor', 'Always ``tomcat_monitor``.')
define_log_field(__monitor__, 'instance',
                 'The ``id`` value from the monitor configuration.')
define_log_field(
    __monitor__, 'metric',
    'The name of a metric being measured, e.g. "tomcat.runtime".')
define_log_field(__monitor__, 'value', 'The metric value.')


# Taken from:
#   http://stackoverflow.com/questions/1150332/source-interface-with-python-and-urllib2
#
# For connecting to local machine, specifying the source IP may be required.  So, using
# this mechanism should allow that.  Since getting status requires "opening up" a
# non-standard/user-facing web page, it is best to be cautious.
#
Example #12
0
for i in memory_pools.keys():
    define_metric(__monitor__, 'tomcat.memory_pools.initial',
              '%s.  The iniital amount of memory allocated to the memory pool.' % memory_pools[i]
              , extra_fields={'pool': i}, cumulative=False, category='memory')
    define_metric(__monitor__, 'tomcat.memory_pools.allocated',
              '%s.  The total amount of memory allocated to the memory pool.' % memory_pools[i]
              , extra_fields={'pool': i}, cumulative=False, category='memory')
    define_metric(__monitor__, 'tomcat.memory_pools.max',
              '%s.  The maximum amount of memory allocated to the memory pool.' % memory_pools[i]
              , extra_fields={'pool': i}, cumulative=False, category='memory')
    define_metric(__monitor__, 'tomcat.memory_pools.used',
              '%s.  The total amount of memory used within the memory pool.' % memory_pools[i]
              , extra_fields={'pool': i}, cumulative=False, category='memory')

define_log_field(__monitor__, 'monitor', 'Always ``tomcat_monitor``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "tomcat.runtime".')
define_log_field(__monitor__, 'value', 'The metric value.')

# Taken from:
#   http://stackoverflow.com/questions/1150332/source-interface-with-python-and-urllib2
#
# For connecting to local machine, specifying the source IP may be required.  So, using
# this mechanism should allow that.  Since getting status requires "opening up" a
# non-standard/user-facing web page, it is best to be cautious.
#
# Note - the use of a global is ugly, but this form is more compatible than with another
# method mentioned which would not require the global.  (The cleaner version was added
# in Python 2.7.)
class BindableHTTPConnection(httplib.HTTPConnection):
              category='innodb insert buffer')
define_metric(__monitor__, 'mysql.innodb.innodb.ibuf.merged_recs',
              'The total number of records merged in the insert buffer since server start.', cumulative=True,
              category='innodb insert buffer')
define_metric(__monitor__, 'mysql.innodb.innodb.ibuf.merges',
              'The total number of merges for the insert buffer since server start.', cumulative=True,
              category='innodb insert buffer')

define_metric(__monitor__, 'mysql.process.query',
              'The number of threads performing a query.', category='threads')
define_metric(__monitor__, 'mysql.process.sleep',
              'The number of threads sleeping.', category='threads')
define_metric(__monitor__, 'mysql.process.xxx',
              'The number of threads in state ``xxx``', category='threads')

define_log_field(__monitor__, 'monitor', 'Always ``mysql_monitor``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "mysql.vars".')
define_log_field(__monitor__, 'value', 'The metric value.')


def file_exists(path):
    if path is None:
        return False
    return os.path.exists(path)


def isyes(s):
    if s.lower() == "yes":
        return 1
    return 0
                     default=2003, min_value=1, max_value=65535, convert_to=int)
define_config_option(__monitor__, 'pickle_port',
                     'Optional (defaults to 2004). The port number on which the plugin listens for pickle connections. '
                     'Unused if ``accept_pickle `` is false.',
                     default=2004, min_value=1, max_value=65535, convert_to=int)
define_config_option(__monitor__, 'max_connection_idle_time',
                     'Optional (defaults to 300).  The maximum number of seconds allowed between requests before the '
                     'Graphite server will close the connection.', default=300.0, min_value=1, convert_to=float)
define_config_option(__monitor__, 'max_request_size',
                     'Optional (defaults to 100K).  The maximum size of a single request in bytes.', default=100*1024,
                     min_value=1000, convert_to=int)
define_config_option(__monitor__, 'buffer_size',
                     'Optional (defaults to 100KB).  The maximum buffer size in bytes for buffering incoming requests '
                     'per connection', default=100*1024, min_value=10*1024, convert_to=int)

define_log_field(__monitor__, 'monitor', 'Always ``graphite_monitor``.')
define_log_field(__monitor__, 'metric', 'The Graphite metric name.')
define_log_field(__monitor__, 'value', 'The Graphite metric value.')
define_log_field(__monitor__, 'orig_time', 'The Graphite timestamp.')


class GraphiteMonitor(ScalyrMonitor):
    """A Scalyr agent monitor acts as a Graphite server, accepting metrics over a network connection and then sends
    them to Scalyr.
    """

    def _initialize(self):
        """Performs monitor-specific initialization.
        """
        self.__only_accept_local = self._config.get('only_accept_local')
        self.__accept_plaintext = self._config.get('accept_plaintext')
Example #15
0
    "Optional (defaults to false). If true, the monitor will record the entire command output; "
    "otherwise, it only records the first line.",
    default=False,
)
define_config_option(
    __monitor__,
    "max_characters",
    "Optional (defaults to 200). At most this many characters of output are recorded. You may specify "
    "a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.",
    default=200,
    convert_to=int,
    min_value=0,
    max_value=10000,
)

define_log_field(__monitor__, "monitor", "Always ``shell_monitor``.")
define_log_field(
    __monitor__,
    "instance",
    "The ``id`` value from the monitor configuration, e.g. ``kernel-version``.",
)
define_log_field(
    __monitor__,
    "command",
    "The shell command for this plugin instance, e.g. ``uname -r``.",
)
define_log_field(__monitor__, "metric", "Always ``output``.")
define_log_field(
    __monitor__,
    "value",
    "The output of the shell command, e.g. ``3.4.73-64.112.amzn1.x86_64``.",
define_metric(__monitor__, 'app.disk.bytes',
              'Total bytes read from disk.', extra_fields={'type': 'read'}, unit='bytes', cumulative=True)

define_metric(__monitor__, 'app.disk.requests',
              'Total disk read requests.', extra_fields={'type': 'read'}, unit='bytes', cumulative=True)

define_metric(__monitor__, 'app.disk.bytes',
              'Total bytes written to disk.', extra_fields={'type': 'write'}, unit='bytes', cumulative=True)

define_metric(__monitor__, 'app.disk.requests',
              'Total disk write requests.', extra_fields={'type': 'write'}, unit='bytes', cumulative=True)

define_metric(__monitor__, 'app.io.fds',
              'The number of open file descriptors help by process.', extra_fields={'type': 'open'})

define_log_field(__monitor__, 'monitor', 'Always ``linux_process_metrics``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration, e.g. ``tomcat``.')
define_log_field(__monitor__, 'app', 'Same as ``instance``; provided for compatibility with the original Scalyr Agent.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "app.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')


class Metric(namedtuple('Metric', ['name', 'type'])):
    """
    This class is an abstraction for a linux metric that contains the
    metric name eg. CPU and type eg. system/user etc. A combination of the
    two make the metric unique.
    """

    __slots__ = ()
Example #17
0
define_metric(
    __monitor__,
    "postgres.database.stats_reset",
    "The time at which database statistics were last reset.",
    cumulative=False,
    category="general",
)
define_metric(
    __monitor__,
    "postgres.database.size",
    "The number of bytes the database is taking up on disk.",
    cumulative=False,
    category="general",
)

define_log_field(__monitor__, "monitor", "Always ``postgres_monitor``.")
define_log_field(
    __monitor__, "instance", "The ``id`` value from the monitor configuration."
)
define_log_field(
    __monitor__, "metric", 'The name of a metric being measured, e.g. "postgres.vars".'
)
define_log_field(__monitor__, "value", "The metric value.")


class PostgreSQLDb(object):
    """ Represents a PopstgreSQL database
    """

    _database_stats = {
        "pg_stat_database": {
    category='memory')
define_metric(
    __monitor__,
    'proc.meminfo.cached',
    'The total number of 1 KB pages of RAM being used to cache blocks from the filesystem.  These can be '
    'reclaimed as used to allocate memory as needed.',
    unit='bytes:1024',
    category='memory')
define_metric(
    __monitor__,
    'proc.meminfo.buffered',
    'The total number of 1 KB pages of RAM being used in system buffers.',
    unit='bytes:1024',
    category='memory')

define_log_field(__monitor__, 'monitor', 'Always ``linux_system_metrics``.')
define_log_field(__monitor__, 'metric',
                 'The name of a metric being measured, e.g. "proc.stat.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')

define_config_option(
    __monitor__, 'network_interface_prefixes',
    'The prefixes for the network interfaces to gather statistics for.  This is either a string '
    'or a list of strings.  The prefix must be the entire string starting after ``/dev/`` and to the'
    'first numeric digit.  For example, ``eth`` matches all devices starting with ``/dev/eth``.'
)


class TcollectorOptions(object):
    """Bare minimum implementation of an object to represent the tcollector options.
            extra_fields={"partition": ""},
        ),
        partion_disk_usage("free"),
    ),
]
# pylint: enable=bad-whitespace

METRICS = (_SYSTEM_CPU_METRICS + _UPTIME_METRICS + _VIRTUAL_MEMORY_METRICS +
           _PHYSICAL_MEMORY_METRICS + _NETWORK_IO_METRICS + _DISK_IO_METRICS +
           _DISK_USAGE_METRICS)
_ = [define_metric(__monitor__, **metric.config) for metric in METRICS]

#
# Logging / Reporting - defines the method and content in which the metrics are reported.
#
define_log_field(__monitor__, "monitor", "Always ``windows_system_metrics``.")
define_log_field(__monitor__, "metric",
                 'The name of a metric being measured, e.g. "winsys.cpu".')
define_log_field(__monitor__, "value", "The metric value.")


class SystemMonitor(ScalyrMonitor):
    # fmt: off
    """
    A Scalyr agent monitor that records system metrics for Windows platforms.

    This agent monitor plugin records CPU consumption, memory usage, and other metrics for the server on which
    the agent is running.

    There is no required configuration for this monitor and is generally automatically run by the agent.
    """
Example #20
0
    __monitor__,
    'max_request_size',
    'Optional (defaults to 100K).  The maximum size of a single request in bytes.',
    default=100 * 1024,
    min_value=1000,
    convert_to=int)
define_config_option(
    __monitor__,
    'buffer_size',
    'Optional (defaults to 100KB).  The maximum buffer size in bytes for buffering incoming requests '
    'per connection',
    default=100 * 1024,
    min_value=10 * 1024,
    convert_to=int)

define_log_field(__monitor__, 'monitor', 'Always ``graphite_monitor``.')
define_log_field(__monitor__, 'metric', 'The Graphite metric name.')
define_log_field(__monitor__, 'value', 'The Graphite metric value.')
define_log_field(__monitor__, 'orig_time', 'The Graphite timestamp.')


class GraphiteMonitor(ScalyrMonitor):
    """A Scalyr agent monitor acts as a Graphite server, accepting metrics over a network connection and then sends
    them to Scalyr.
    """
    def _initialize(self):
        """Performs monitor-specific initialization.
        """
        self.__only_accept_local = self._config.get('only_accept_local')
        self.__accept_plaintext = self._config.get('accept_plaintext')
        self.__accept_pickle = self._config.get('accept_pickle')
Example #21
0
    category='innodb insert buffer')

define_metric(__monitor__,
              'mysql.process.query',
              'The number of threads performing a query.',
              category='threads')
define_metric(__monitor__,
              'mysql.process.sleep',
              'The number of threads sleeping.',
              category='threads')
define_metric(__monitor__,
              'mysql.process.xxx',
              'The number of threads in state ``xxx``',
              category='threads')

define_log_field(__monitor__, 'monitor', 'Always ``mysql_monitor``.')
define_log_field(__monitor__, 'instance',
                 'The ``id`` value from the monitor configuration.')
define_log_field(__monitor__, 'metric',
                 'The name of a metric being measured, e.g. "mysql.vars".')
define_log_field(__monitor__, 'value', 'The metric value.')


def file_exists(path):
    if path is None:
        return False
    return os.path.exists(path)


def isyes(s):
    if s.lower() == "yes":
Example #22
0
    "status_url",
    "Optional.  Specifies the URL -- in particular, the port number -- at which the Apache status "
    "module is served.  The URL should end in ``/?auto`` to indicate the machine-readable version of "
    "the page should be returned.",
    default="http://localhost/server-status/?auto",
)
define_config_option(
    __monitor__,
    "source_address",
    "Optional (defaults to '%s'). The IP address to be used as the source address when fetching "
    "the status URL.  Many servers require this to be 127.0.0.1 because they only server the status "
    "page to requests from localhost." % httpSourceAddress,
    default=httpSourceAddress,
)

define_log_field(__monitor__, "monitor", "Always ``apache_monitor``.")
define_log_field(
    __monitor__,
    "metric",
    "The metric name.  See the metric tables for more information.",
)
define_log_field(__monitor__, "value", "The value of the metric.")
define_log_field(__monitor__, "instance",
                 "The ``id`` value from the monitor configuration.")

define_metric(
    __monitor__,
    "apache.connections.active",
    "The number of connections that are being handled "
    "asynchronously (not using  workers) currently open on the "
    "server",
    __monitor__,
    "proc.meminfo.cached",
    "The total number of 1 KB pages of RAM being used to cache blocks from the filesystem.  These can be "
    "reclaimed as used to allocate memory as needed.",
    unit="bytes:1024",
    category="memory",
)
define_metric(
    __monitor__,
    "proc.meminfo.buffers",
    "The total number of 1 KB pages of RAM being used in system buffers.",
    unit="bytes:1024",
    category="memory",
)

define_log_field(__monitor__, "monitor", "Always ``linux_system_metrics``.")
define_log_field(__monitor__, "metric",
                 'The name of a metric being measured, e.g. "proc.stat.cpu".')
define_log_field(__monitor__, "value", "The metric value.")

define_config_option(
    __monitor__,
    "network_interface_prefixes",
    "The prefixes for the network interfaces to gather statistics for.  This is either a string "
    "or a list of strings.  The prefix must be the entire string starting after ``/dev/`` and to the"
    "regex defined by network_interface_suffix, which defaults to [0-9A-Z]+ (multiple digits or uppercase letters).  "
    "For example, ``eth`` matches all devices starting with ``/dev/eth`` that end in a digit or an uppercase letter, "
    "that is eth0, eth1, ethA, ethB and so on.",
)
define_config_option(
    __monitor__,
Example #24
0
                     'Optional (defaults to 10): the maximum amount of time, in seconds, to wait for the URL to load.',
                     default=10, convert_to=float, min_value=0, max_value=30)
define_config_option(__monitor__, 'extract',
                     'Optional: a regular expression to apply to the command output. If defined, this expression must '
                     'contain a matching group (i.e. a subexpression enclosed in parentheses). The monitor will record '
                     'only the content of that matching group. This allows you to discard unnecessary portions of the '
                     'command output and extract the information you need.', default="")
define_config_option(__monitor__, 'log_all_lines',
                     'Optional (defaults to false). If true, the monitor will record the entire command output; '
                     'otherwise, it only records the first line.', default=False)
define_config_option(__monitor__, 'max_characters',
                     'Optional (defaults to 200). At most this many characters of output are recorded. You may specify '
                     'a value up to 10000, but the Scalyr server currently truncates all fields to 3500 characters.',
                     default=200, convert_to=int, min_value=0, max_value=10000)

define_log_field(__monitor__, 'monitor', 'Always ``url_monitor``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration, e.g. ``instance-type``.')
define_log_field(__monitor__, 'url', 'The URL that was retrieved, e.g. '
                                     '``http:/^^^/169.254.169.254/latest/meta-data/instance-type``.')
define_log_field(__monitor__, 'metric', 'Always ``response``.')
define_log_field(__monitor__, 'status', 'The HTTP response code, e.g. 200 or 404.')
define_log_field(__monitor__, 'length', 'The length of the HTTP response.')
define_log_field(__monitor__, 'value', 'The body of the HTTP response.')


# Pattern that matches the first line of a string
first_line_pattern = re.compile('[^\r\n]+')


# Redirect handler that doesn't follow any redirects
class NoRedirection(urllib2.HTTPErrorProcessor):
Example #25
0
METRICS = (
    _PROCESS_CPU_METRICS
    + _PROCESS_ATTRIBUTE_METRICS
    + _PROCESS_MEMORY_METRICS
    + _PROCESS_DISK_IO_METRICS
)
_ = [
    define_metric(__monitor__, **metric.config) for metric in METRICS
]  # pylint: disable=star-args


#
# Logging / Reporting - defines the method and content in which the metrics are reported.
#
define_log_field(__monitor__, "monitor", "Always ``windows_process_metrics``.")
define_log_field(
    __monitor__,
    "instance",
    "The ``id`` value from the monitor configuration, e.g. ``iis``.",
)
define_log_field(
    __monitor__,
    "app",
    "Same as ``instance``; provided for compatibility with the original Scalyr Agent.",
)
define_log_field(
    __monitor__, "metric", 'The name of a metric being measured, e.g. "winproc.cpu".'
)
define_log_field(__monitor__, "value", "The metric value.")
    )
    # TODO: Additional attributes for this section
    #  * ...
]
# pylint: enable=bad-whitespace

METRICS = _PROCESS_CPU_METRICS + _PROCESS_ATTRIBUTE_METRICS + _PROCESS_MEMORY_METRICS + _PROCESS_DISK_IO_METRICS
_ = [define_metric(__monitor__, **metric.config) for metric in METRICS]     # pylint: disable=star-args




#
# Logging / Reporting - defines the method and content in which the metrics are reported.
#
define_log_field(__monitor__, 'monitor', 'Always ``windows_process_metrics``.')
define_log_field(__monitor__, 'instance', 'The ``id`` value from the monitor configuration, e.g. ``iis``.')
define_log_field(__monitor__, 'app', 'Same as ``instance``; provided for compatibility with the original Scalyr Agent.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "winproc.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')







#
#
#
def commandline_matcher(regex, flags=re.IGNORECASE):
Example #27
0
            metric_name='winsys.disk.usage.free',
            description='The number of free bytes on each disk partition.',
            category='Disk',
            unit='byte',
            cumulative=False,
            extra_fields={'partition': ''}), partion_disk_usage('free')),
]
# pylint: enable=bad-whitespace

METRICS = _SYSTEM_CPU_METRICS + _UPTIME_METRICS + _VIRTUAL_MEMORY_METRICS + _PHYSICAL_MEMORY_METRICS + _NETWORK_IO_METRICS + _DISK_IO_METRICS + _DISK_USAGE_METRICS
_ = [define_metric(__monitor__, **metric.config) for metric in METRICS]  # pylint: disable=star-args

#
# Logging / Reporting - defines the method and content in which the metrics are reported.
#
define_log_field(__monitor__, 'monitor', 'Always ``windows_system_metrics``.')
define_log_field(__monitor__, 'metric',
                 'The name of a metric being measured, e.g. "winsys.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')


class SystemMonitor(ScalyrMonitor):
    """A Scalyr agent monitor that records system metrics for Windows platforms.

    This agent monitor plugin records CPU consumption, memory usage, and other metrics for the server on which
    the agent is running.

    There is no required configuration for this monitor and is generally automatically run by the agent.
    """
    def __init__(self, config, logger, **kwargs):
        """TODO: Fucntion documentation
            category        = 'Disk',
            unit            = 'byte',
            cumulative      = False,
            extra_fields    = { 'partition': ''}
        ),
        partion_disk_usage('free')
    ),]
# pylint: enable=bad-whitespace

METRICS = _SYSTEM_CPU_METRICS + _UPTIME_METRICS + _VIRTUAL_MEMORY_METRICS + _PHYSICAL_MEMORY_METRICS + _NETWORK_IO_METRICS + _DISK_IO_METRICS + _DISK_USAGE_METRICS
_ = [define_metric(__monitor__, **metric.config) for metric in METRICS]     # pylint: disable=star-args

#
# Logging / Reporting - defines the method and content in which the metrics are reported.
#
define_log_field(__monitor__, 'monitor', 'Always ``windows_system_metrics``.')
define_log_field(__monitor__, 'metric', 'The name of a metric being measured, e.g. "winsys.cpu".')
define_log_field(__monitor__, 'value', 'The metric value.')


class SystemMonitor(ScalyrMonitor):
    """A Scalyr agent monitor that records system metrics for Windows platforms.

    This agent monitor plugin records CPU consumption, memory usage, and other metrics for the server on which
    the agent is running.

    There is no required configuration for this monitor and is generally automatically run by the agent.
    """

    def __init__(self, config, logger, **kwargs):
        """TODO: Fucntion documentation