예제 #1
0
from scalyr_agent.log_watcher import LogWatcher
from scalyr_agent.monitor_utils.server_processors import LineRequestParser
from scalyr_agent.monitor_utils.server_processors import RequestSizeExceeded
from scalyr_agent.monitor_utils.server_processors import RequestStream

from scalyr_agent.util import StoppableThread

from scalyr_agent.util import RunState

global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(__monitor__,
                     'module',
                     'Always ``scalyr_agent.builtin_monitors.docker_monitor``',
                     convert_to=str,
                     required_option=True)

define_config_option(
    __monitor__,
    'container_name',
    'Optional (defaults to scalyr-agent). Defines the name given to the container running the scalyr-agent\n'
    'You should make sure to specify this same name when creating the docker container running scalyr\n'
    'e.g. docker run --name scalyr-agent ...',
    convert_to=str,
    default='scalyr-agent')

define_config_option(
    __monitor__,
    'api_socket',
예제 #2
0
import six.moves.http_client

try:
    from __scalyr__ import SCALYR_VERSION
except ImportError:
    from scalyr_agent.__scalyr__ import SCALYR_VERSION

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field
from scalyr_agent.json_lib.objects import JsonArray

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.url_monitor``",
    required_option=True,
    convert_to=six.text_type,
)
define_config_option(
    __monitor__,
    "id",
    "Included in each log message generated by this monitor, as a field named ``instance``. Allows "
    "you to distinguish between values recorded by different monitors.",
)
define_config_option(
    __monitor__,
    "url",
    "The URL to fetch. Must be an http or https URL.",
    required_option=True,
)
예제 #3
0
from scalyr_agent.json_lib import JsonConversionException, JsonMissingFieldException
from scalyr_agent.log_watcher import LogWatcher
from scalyr_agent.monitor_utils.server_processors import LineRequestParser
from scalyr_agent.monitor_utils.server_processors import RequestSizeExceeded
from scalyr_agent.monitor_utils.server_processors import RequestStream

from scalyr_agent.util import StoppableThread

from scalyr_agent.util import RunState

global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.docker_monitor``',
                     convert_to=str, required_option=True)

define_config_option( __monitor__, 'container_name',
                     'Optional (defaults to scalyr-agent). Defines the name given to the container running the scalyr-agent\n'
                     'You should make sure to specify this same name when creating the docker container running scalyr\n'
                     'e.g. docker run --name scalyr-agent ...',
                     convert_to=str, default='scalyr-agent')

define_config_option( __monitor__, 'api_socket',
                     'Optional (defaults to /var/scalyr/docker.sock). Defines the unix socket used to communicate with the docker API.\n'
                     'Note:  You need to map the host\'s /run/docker.sock to the same value as specified here, using the -v parameter, e.g.\n'
                     '\tdocker run -v /run/docker.sock:/var/scalyr/docker.sock ...',
                     convert_to=str, default='/var/scalyr/docker.sock')

define_config_option( __monitor__, 'docker_log_prefix',
예제 #4
0
# limitations under the License.
# ------------------------------------------------------------------------
#
# A ScalyrMonitor which executes a specified shell command and records the output.

from __future__ import absolute_import
import re
import sys

from subprocess import PIPE, Popen

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field

__monitor__ = __name__

define_config_option(__monitor__, "module",
                     "Always ``scalyr_agent.builtin_monitors.shell_monitor``")
define_config_option(
    __monitor__,
    "id",
    "Included in each log message generated by this monitor, as a field named ``instance``. Allows "
    "you to distinguish between values recorded by different monitors.",
)
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 "
예제 #5
0
    win32con = None
    windll = None

from scalyr_agent import ScalyrMonitor, define_config_option
import scalyr_agent.scalyr_logging as scalyr_logging

__author__ = '*****@*****.**'

__monitor__ = __name__

DEFAULT_SOURCES = 'Application, Security, System'
DEFAULT_EVENTS = 'All'

define_config_option(
    __monitor__,
    'module',
    'Always ``scalyr_agent.builtin_monitors.windows_event_log_monitor``',
    convert_to=str,
    required_option=True)

define_config_option(
    __monitor__,
    'sources',
    'Optional (defaults to ``Application, Security, System``). A comma separated list of event sources.\n'
    'You can use this to specify which event sources you are interested in listening to.'
    '(Vista and later) Cannot be used.  Please use the "channels" parameter instead.',
    convert_to=str,
    default=DEFAULT_SOURCES)

define_config_option(
    __monitor__,
    'event_types',
예제 #6
0
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
#
# A ScalyrMonitor which executes a specified shell command and records the output.

import re
import sys

from subprocess import PIPE, Popen

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.shell_monitor``')
define_config_option(__monitor__, 'id',
                     'Included in each log message generated by this monitor, as a field named ``instance``. Allows '
                     'you to distinguish between values recorded by different monitors.')
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 '
예제 #7
0
import urllib2
import socket
import urlparse
import base64
import re

from scalyr_agent import ScalyrMonitor, UnsupportedSystem, define_config_option, define_metric, define_log_field

# needed for BindableHTTPConnection
httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(
    __monitor__,
    'module',
    'Always ``scalyr_agent.builtin_monitors.tomcat_monitor ``',
    required_option=True)
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 PostgreSQL instances on a single server; you can monitor each '
    'instance with a separate tomcatql_monitor record in the Scalyr Agent configuration.',
    convert_to=str)
define_config_option(
    __monitor__,
    'monitor_url',
    'Name of host machine the agent will connect to PostgreSQL to retrieve monitoring data.',
    convert_to=str,
예제 #8
0
import six

from scalyr_agent import ScalyrMonitor, define_config_option
from scalyr_agent.scalyr_monitor import BadMonitorConfiguration

import scalyr_agent.scalyr_logging as scalyr_logging

global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.garbage_monitor``",
    convert_to=six.text_type,
    required_option=True,
)

define_config_option(
    __monitor__,
    "disable_garbage_collection_before_dump",
    "Optional (defaults to False). By default the garbage_monitor will perform a garbage collection before it "
    "dumps the list of unreachable objects to ensure that objects are actually leaking.  If this flag is set to "
    "True then then garbage monitor will not perform this collection.  This is useful when trying to find objects "
    "with cyclic references that are not being readily collected by the garbage collector, but that would eventually "
    "be collected.",
    default=False,
    convert_to=bool,
)
    import win32evtlog
    import win32evtlogutil
    import win32con
except ImportError:
    win32evtlog = None
    win32evtlogutil = None
    win32con = None

from scalyr_agent import ScalyrMonitor, define_config_option

__author__ = '*****@*****.**'

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.windows_event_log_monitor``',
                     convert_to=str, required_option=True)
define_config_option( __monitor__, 'sources',
                     'Optional (defaults to ``Application, Security, System``). A comma separated list of event sources.\n'
                     'You can use this to specify which event sources you are interested in listening to.',
                     convert_to=str, default='Application, Security, System')

define_config_option(__monitor__, 'event_types',
                     'Optional (defaults to ``All``). A comma separated list of event types to log.\n'
                     'Valid values are: All, Error, Warning, Information, AuditSuccess and AuditFailure',
                     default='All', convert_to=str)

define_config_option(__monitor__, 'maximum_records_per_source',
                     'Optional (defaults to ``10000``). The maximum number of records to read from the end of each log source'
                     'per gather_sample.\n',
                     default='10000', convert_to=int)
예제 #10
0
__author__ = '*****@*****.**'

import gc
import traceback

from scalyr_agent import ScalyrMonitor, define_config_option
from scalyr_agent.scalyr_monitor import BadMonitorConfiguration

import scalyr_agent.scalyr_logging as scalyr_logging
global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.garbage_monitor``',
                     convert_to=str, required_option=True)

define_config_option(__monitor__, 'disable_garbage_collection_before_dump',
                     'Optional (defaults to False). By default the garbage_monitor will perform a garbage collection before it '
                     'dumps the list of unreachable objects to ensure that objects are actually leaking.  If this flag is set to '
                     'True then then garbage monitor will not perform this collection.  This is useful when trying to find objects '
                     'with cyclic references that are not being readily collected by the garbage collector, but that would eventually '
                     'be collected.',
                     default=False, convert_to=bool)

define_config_option(__monitor__, 'max_type_dump',
                     'Optional (defaults to 20). The maximum number of unreachable types to output each gather_sample',
                     default=20, convert_to=int)

define_config_option(__monitor__, 'max_object_dump',
예제 #11
0
# We must require 2.6 or greater right now because PyMySQL requires it.  We are considering
# forking PyMySQL and adding in support if there is enough customer demand.
if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1] < 6):
    raise UnsupportedSystem('mysql_monitor', 'Requires Python 2.6 or greater.')

# We import pymysql from the third_party directory.  This
# relies on PYTHONPATH being set up correctly, which is done
# in both agent_main.py and config_main.py
#
# noinspection PyUnresolvedReferences,PyPackageRequirements
import pymysql

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.mysql_monitor ``', required_option=True)
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 MySQL instances on a single server; you can monitor each '
                     'instance with a separate mysql_monitor record in the Scalyr Agent configuration.',
                     convert_to=str)
define_config_option(__monitor__, 'database_username',
                     'Username which the agent uses to connect to MySQL to retrieve monitoring data.',
                     convert_to=str)
define_config_option(__monitor__, 'database_password',
                     'Password for connecting to MySQL.', convert_to=str)
define_config_option(__monitor__, 'database_socket',
                     'Location of the socket file for connecting to MySQL, e.g. '
                     '``/var/run/mysqld_instance2/mysqld.sock``. If MySQL is running on the same server as the Scalyr '
                     'Agent, you can usually set this to "default".', convert_to=str)
예제 #12
0
              '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.')

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__, 'network_interface_suffix',
                     'The suffix for network interfaces to gather statistics for.  This is a single regex that '
                     'defaults to [0-9A-Z]+ - multiple digits or uppercase letters in a row.  This is appended to each of the network_interface_prefixes '
                     'to create the full interface name when interating over network interfaces in /dev'
                     )

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.
예제 #13
0
from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field
from scalyr_agent.monitor_utils import ServerProcessor, LineRequestParser, Int32RequestParser

__monitor__ = __name__

# Configuration parameters are:
# only_accept_local: (defaults to True)
# accept_plaintext: (defaults to True)
# accept_pickle: (defaults to True)
# plaintext_port: (defaults to 2003)
# pickle_port: (defaults to 2004)
# max_connection_idle_time: (defaults to 300)
# max_request_size: (defaults to 100K)
# buffer_size: (defaults to 100K)
define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.graphite_monitor``',
                     convert_to=str, required_option=True)
define_config_option(__monitor__, 'only_accept_local',
                     'Optional (defaults to true). If true, then the plugin only accepts connections from localhost. '
                     'If false, all network connections are accepted.',
                     default=True, convert_to=bool)
define_config_option(__monitor__, 'accept_plaintext',
                     'Optional (defaults to true). If true, then the plugin accepts connections in Graphite\'s "plain '
                     'text" procotol.', default=True, convert_to=bool)
define_config_option(__monitor__, 'accept_pickle',
                     'Optional (defaults to true). If true, then the plugin accepts connections in Graphite\'s '
                     '"pickle" procotol.', default=True, convert_to=bool)
define_config_option(__monitor__, 'plaintext_port',
                     'Optional (defaults to 2003). The port number on which the plugin listens for plain text '
                     'connections. Unused if ``accept_plaintext`` is false.',
                     default=2003, min_value=1, max_value=65535, convert_to=int)
    win32evtlog = None
    win32evtlogutil = None
    win32con = None
    windll = None

from scalyr_agent import ScalyrMonitor, define_config_option

__author__ = '*****@*****.**'

__monitor__ = __name__

DEFAULT_SOURCES = 'Application, Security, System'
DEFAULT_EVENTS = 'All'

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.windows_event_log_monitor``',
                     convert_to=str, required_option=True)

define_config_option( __monitor__, 'sources',
                     'Optional (defaults to ``Application, Security, System``). A comma separated list of event sources.\n'
                     'You can use this to specify which event sources you are interested in listening to.'
                     '(Vista and later) Cannot be used.  Please use the "channels" parameter instead.',
                     convert_to=str, default=DEFAULT_SOURCES)

define_config_option(__monitor__, 'event_types',
                     'Optional (defaults to ``All``). A comma separated list of event types to log.\n'
                     'Valid values are: All, Error, Warning, Information, AuditSuccess and AuditFailure'
                     '(Vista and later) Cannot be used.  Please use the "channels" parameter instead.',
                     default=DEFAULT_EVENTS, convert_to=str)

define_config_option(__monitor__, 'channels',
        "ignored if the ``commandline`` is specified.",
        default=None,
        convert_to=six.text_type,
    ),
    dict(
        option_name="id",
        option_description=
        "Included in each log message generated by this monitor, as a field named ``instance``. "
        "Allows you to distinguish between values recorded by different instances of this monitor.",
        required_option=True,
        convert_to=six.text_type,
    ),
]

_ = [
    define_config_option(__monitor__, **option)
    for option in CONFIG_OPTIONS  # type: ignore
]

# End Monitor Configuration
# #########################################################################################


# #########################################################################################
# #########################################################################################
# ## Process's Metrics / Dimensions -
# ##
# ##    Metrics define the capibilities of this monitor.  These some utility functions
# ##    along with the list(s) of metrics themselves.
# ##
def _gather_metric(method, attribute=None, transform=None):
예제 #16
0
# limitations under the License.
# ------------------------------------------------------------------------
#
# A ScalyrMonitor which retrieves a specified URL and records the response status and body.

import re
import urllib2
import cookielib

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field

__monitor__ = __name__

define_config_option(__monitor__,
                     'module',
                     'Always ``scalyr_agent.builtin_monitors.url_monitor``',
                     required_option=True,
                     convert_to=str)
define_config_option(
    __monitor__, 'id',
    'Included in each log message generated by this monitor, as a field named ``instance``. Allows '
    'you to distinguish between values recorded by different monitors.')
define_config_option(__monitor__,
                     'url',
                     'The URL to fetch. Must be an http or https URL.',
                     required_option=True)
define_config_option(
    __monitor__,
    'timeout',
    'Optional (defaults to 10): the maximum amount of time, in seconds, to wait for the URL to load.',
    default=10,
예제 #17
0
# python -m scalyr_agent.run_monitor
# scalyr_agent.builtin_monitors.apache_monitor
import httplib
import urllib2
import socket
import urlparse

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field, define_metric

httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(__monitor__,
                     'module',
                     'Always ``scalyr_agent.builtin_monitors.apache_monitor``',
                     convert_to=str,
                     required_option=True)
define_config_option(
    __monitor__,
    'status_url',
    'Optional (defaults to \'http://localhost/server-status/?auto\').  The URL the monitor will fetch'
    'to retrieve the Apache status information.',
    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)
예제 #18
0
        option_description="The pid of the process from which the monitor instance will collect metrics.  This is "
        "ignored if the ``commandline`` is specified.",
        default=None,
        convert_to=str,
    ),
    dict(
        option_name="id",
        option_description="Included in each log message generated by this monitor, as a field named ``instance``. "
        "Allows you to distinguish between values recorded by different instances of this monitor.",
        required_option=True,
        convert_to=str,
    ),
]

_ = [
    define_config_option(__monitor__, **option) for option in CONFIG_OPTIONS
]  # pylint: disable=star-args
## End Monitor Configuration
# #########################################################################################


# #########################################################################################
# #########################################################################################
# ## Process's Metrics / Dimensions -
# ##
# ##    Metrics define the capibilities of this monitor.  These some utility functions
# ##    along with the list(s) of metrics themselves.
# ##
def _gather_metric(method, attribute=None, transform=None):
    """Curry arbitrary process metric extraction
예제 #19
0
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'
    '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__, 'network_interface_suffix',
    'The suffix for network interfaces to gather statistics for.  This is a single regex that '
    'defaults to [0-9A-Z]+ - multiple digits or uppercase letters in a row.  This is appended to each of the network_interface_prefixes '
    'to create the full interface name when interating over network interfaces in /dev'
)


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.
예제 #20
0
    raise Exception(
        "Python systemd library not installed.\n\nYou must install the systemd python library in order "
        "to use the journald monitor.\n\nThis can be done via package manager e.g.:\n\n"
        "  apt-get install python-systemd  (debian/ubuntu)\n"
        "  dnf install python-systemd  (CentOS/rhel/Fedora)\n\n"
        "or installed from source using pip e.g.\n\n"
        "  pip install systemd-python\n\n"
        "See here for more info: https://github.com/systemd/python-systemd/\n")

global_log = scalyr_logging.getLogger(__name__)
__monitor__ = __name__

define_config_option(
    __monitor__,
    "journal_path",
    "Optional (defaults to /var/log/journal). Location on the filesystem of the journald logs.",
    convert_to=str,
    default="/var/log/journal",
)

define_config_option(
    __monitor__,
    "journal_poll_interval",
    "Optional (defaults to 5). The number of seconds to wait for data while polling the journal file. "
    "Fractional values are supported. Note: This values overrides the sample_interval of the monitor",
    convert_to=float,
    default=5,
)

define_config_option(
    __monitor__,
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.')

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.

    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
        # A list of the prefixes for network interfaces to report.  Usually defaults to ["eth"]
        self.network_interface_prefixes = None
예제 #22
0
__author__ = '*****@*****.**'

import gc
import traceback

from scalyr_agent import ScalyrMonitor, define_config_option
from scalyr_agent.scalyr_monitor import BadMonitorConfiguration

import scalyr_agent.scalyr_logging as scalyr_logging
global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(
    __monitor__,
    'module',
    'Always ``scalyr_agent.builtin_monitors.garbage_monitor``',
    convert_to=str,
    required_option=True)

define_config_option(
    __monitor__,
    'max_type_dump',
    'Optional (defaults to 20). The maximum number of unreachable types to output each gather_sample',
    default=20,
    convert_to=int)

define_config_option(
    __monitor__,
    'max_object_dump',
    'Optional (defaults to 0). The maximum number of unreachable objects to dump for each type on the ``object_dump_types`` list. '
    'Set to -1 to include all objects',
예제 #23
0
from scalyr_agent.monitor_utils.server_processors import RequestSizeExceeded
from scalyr_agent.monitor_utils.server_processors import RequestStream

from scalyr_agent.util import StoppableThread

from scalyr_agent.util import RunState

from requests.packages.urllib3.exceptions import ProtocolError

global_log = scalyr_logging.getLogger(__name__)

__monitor__ = __name__

define_config_option(__monitor__,
                     'module',
                     'Always ``scalyr_agent.builtin_monitors.docker_monitor``',
                     convert_to=str,
                     required_option=True)

define_config_option(
    __monitor__,
    'container_name',
    'Optional (defaults to None). Defines a regular expression that matches the name given to the '
    'container running the scalyr-agent.\n'
    'If this is None, the scalyr agent will look for a container running /usr/sbin/scalyr-agent-2 as the main process.\n',
    convert_to=str,
    default=None)

define_config_option(
    __monitor__,
    'container_check_interval',
예제 #24
0
# Note, this can be run in standalone mode by:
# python -m scalyr_agent.run_monitor
# scalyr_agent.builtin_monitors.apache_monitor
import httplib
import urllib2
import socket
import urlparse

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field, define_metric

httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.apache_monitor``',
                     convert_to=str, required_option=True)
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)
예제 #25
0
from pysnmp.smi.error import MibNotFoundError  # pylint: disable=import-error

import pysnmp  # pylint: disable=import-error
from pysnmp.hlapi import (  # pylint: disable=import-error
    CommunityData, ObjectIdentity, ObjectType, SnmpEngine, UdpTransportTarget,
    UsmUserData,
)

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.snmp_monitor``",
    convert_to=six.text_type,
    required_option=True,
)

define_config_option(
    __monitor__,
    "error_repeat_interval",
    "Optional (defaults to 300). The number of seconds to wait before repeating an error message.",
    default=300,
    convert_to=int,
)

define_config_option(
    __monitor__,
    "mib_path",
예제 #26
0
from subprocess import Popen, PIPE
from io import open

import six
from six.moves import range

from scalyr_agent.compat import custom_defaultdict as defaultdict
from scalyr_agent import ScalyrMonitor, BadMonitorConfiguration
from scalyr_agent import define_config_option, define_metric, define_log_field

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.linux_process_metrics``",
    convert_to=six.text_type,
    required_option=True,
)
define_config_option(
    __monitor__,
    "commandline",
    "A regular expression which will match the command line of the process you're interested in, as "
    "shown in the output of ``ps aux``. (If multiple processes match the same command line pattern, "
    "only one will be monitored.)",
    default=None,
    convert_to=six.text_type,
)
define_config_option(
    __monitor__,
    "pid",
__author__ = '*****@*****.**'

import os
import re
import time
from collections import defaultdict, namedtuple
from datetime import datetime, timedelta
from subprocess import Popen, PIPE

from scalyr_agent import ScalyrMonitor, BadMonitorConfiguration
from scalyr_agent import define_config_option, define_metric, define_log_field

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.linux_process_metrics``',
                     convert_to=str, required_option=True)
define_config_option(__monitor__, 'commandline',
                     'A regular expression which will match the command line of the process you\'re interested in, as '
                     'shown in the output of ``ps aux``. (If multiple processes match the same command line pattern, '
                     'only one will be monitored.)', default=None, convert_to=str)
define_config_option(__monitor__, 'pid',
                     'The pid of the process from which the monitor instance will collect metrics.  This is ignored '
                     'if the ``commandline`` is specified.',
                     default=None, convert_to=str)
define_config_option(__monitor__, 'id',
                     'Included in each log message generated by this monitor, as a field named ``instance``. Allows '
                     'you to distinguish between values recorded by different monitors.',
                     required_option=True, convert_to=str)

define_metric(__monitor__, 'app.cpu',
예제 #28
0
    define_metric,
    define_log_field,
)

# We must require 2.5 or greater right now because pg8000 requires it.
if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1] < 5):
    raise UnsupportedSystem("postgresql_monitor", "Requires Python 2.5 or greater.")

import pg8000

__monitor__ = __name__


define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.postgres_monitor ``",
    required_option=True,
)
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 PostgreSQL instances on a single server; you can monitor each "
    "instance with a separate postgresql_monitor record in the Scalyr Agent configuration.",
    convert_to=str,
)
define_config_option(
    __monitor__,
    "database_host",
    "Name of host machine the agent will connect to PostgreSQL to retrieve monitoring data.",
예제 #29
0
from scalyr_agent import ScalyrMonitor, define_config_option

from redis.client import Redis, parse_info  # pylint: disable=import-error
from redis.exceptions import (  # pylint: disable=import-error
    ConnectionError, TimeoutError,
)

MORE_BYTES = re.compile(b"\.\.\. \(\d+ more bytes\)$")  # NOQA

__monitor__ = __name__

define_config_option(
    __monitor__,
    "log_cluster_replication_info",
    "Optional (defaults to false). If true, the monitor will record redis cluster's replication "
    "offsets, difference between master and replica, and how many seconds the replica is falling behind",
    default=False,
)


class RedisHost(object):
    """Class that holds various information about a specific redis connection"""
    def __init__(self, host, port, password, connection_timeout):
        # redis instance information
        self.__host = host
        self.__port = port
        self.__password = password
        self.__connection_timeout = connection_timeout

        # how long to delay between invalid utf8 warnings
예제 #30
0
import httplib
import urllib2
import socket
import urlparse
import base64
import re

from scalyr_agent import ScalyrMonitor, UnsupportedSystem, define_config_option, define_metric, define_log_field

# needed for BindableHTTPConnection
httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(
    __monitor__, "module", "Always ``scalyr_agent.builtin_monitors.tomcat_monitor ``", required_option=True
)
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 PostgreSQL instances on a single server; you can monitor each "
    "instance with a separate tomcatql_monitor record in the Scalyr Agent configuration.",
    convert_to=str,
)
define_config_option(
    __monitor__,
    "monitor_url",
    "Name of host machine the agent will connect to PostgreSQL to retrieve monitoring data.",
    convert_to=str,
    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.

    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
예제 #32
0
if sys.version_info[0] < 2 or (sys.version_info[0] == 2
                               and sys.version_info[1] < 7):
    raise UnsupportedSystem("mysql_monitor", "Requires Python 2.7 or greater")

# We import pymysql from the third_party directory.  This
# relies on PYTHONPATH being set up correctly, which is done
# in both agent_main.py and config_main.py
#
# noinspection PyUnresolvedReferences,PyPackageRequirements
import pymysql

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.mysql_monitor ``",
    required_option=True,
)
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 MySQL instances on a single server; you can monitor each "
    "instance with a separate mysql_monitor record in the Scalyr Agent configuration.",
    convert_to=str,
)
define_config_option(
    __monitor__,
    "database_username",
    "Username which the agent uses to connect to MySQL to retrieve monitoring data.",
예제 #33
0
from scalyr_agent.monitor_utils import ServerProcessor, LineRequestParser, Int32RequestParser

__monitor__ = __name__

# Configuration parameters are:
# only_accept_local: (defaults to True)
# accept_plaintext: (defaults to True)
# accept_pickle: (defaults to True)
# plaintext_port: (defaults to 2003)
# pickle_port: (defaults to 2004)
# max_connection_idle_time: (defaults to 300)
# max_request_size: (defaults to 100K)
# buffer_size: (defaults to 100K)
define_config_option(
    __monitor__,
    'module',
    'Always ``scalyr_agent.builtin_monitors.graphite_monitor``',
    convert_to=str,
    required_option=True)
define_config_option(
    __monitor__,
    'only_accept_local',
    'Optional (defaults to true). If true, then the plugin only accepts connections from localhost. '
    'If false, all network connections are accepted.',
    default=True,
    convert_to=bool)
define_config_option(
    __monitor__,
    'accept_plaintext',
    'Optional (defaults to true). If true, then the plugin accepts connections in Graphite\'s "plain '
    'text" procotol.',
    default=True,
    "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__,
    "network_interface_suffix",
    "The suffix for network interfaces to gather statistics for.  This is a single regex that "
    "defaults to [0-9A-Z]+ - multiple digits or uppercase letters in a row.  This is appended to each of the network_interface_prefixes "
    "to create the full interface name when interating over network interfaces in /dev",
)

define_config_option(
    __monitor__,
    "local_disks_only",
예제 #35
0
from scalyr_agent import (
    ScalyrMonitor,
    define_config_option,
    define_log_field,
    define_metric,
)

httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.apache_monitor``",
    convert_to=six.text_type,
    required_option=True,
)
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=six.text_type,
)
define_config_option(
    __monitor__,
    "status_url",
예제 #36
0
__monitor__ = __name__

# Configuration parameters are:
# only_accept_local: (defaults to True)
# accept_plaintext: (defaults to True)
# accept_pickle: (defaults to True)
# plaintext_port: (defaults to 2003)
# pickle_port: (defaults to 2004)
# max_connection_idle_time: (defaults to 300)
# max_request_size: (defaults to 100K)
# buffer_size: (defaults to 100K)
define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.graphite_monitor``",
    convert_to=str,
    required_option=True,
)
define_config_option(
    __monitor__,
    "only_accept_local",
    "Optional (defaults to true). If true, then the plugin only accepts connections from localhost. "
    "If false, all network connections are accepted.",
    default=True,
    convert_to=bool,
)
define_config_option(
    __monitor__,
    "accept_plaintext",
    "Optional (defaults to true). If true, then the plugin accepts connections in Graphite's \"plain "
예제 #37
0
# ------------------------------------------------------------------------
#
# A ScalyrMonitor which retrieves a specified URL and records the response status and body.

import httplib
import re
import urllib2
import cookielib

from scalyr_agent import ScalyrMonitor, define_config_option, define_log_field
from scalyr_agent.json_lib.objects import JsonArray

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.url_monitor``',
                     required_option=True, convert_to=str)
define_config_option(__monitor__, 'id',
                     'Included in each log message generated by this monitor, as a field named ``instance``. Allows '
                     'you to distinguish between values recorded by different monitors.')
define_config_option(__monitor__, 'url',
                     'The URL to fetch. Must be an http or https URL.', required_option=True)
define_config_option(__monitor__, 'request_method',
                     'The request method to be used. Default is GET.', required_option=False, default='GET')
define_config_option(__monitor__, 'request_data',
                     'The request data(payload) to be passed. Not used for GET request method.',
                     required_option=False, default=None)
define_config_option(__monitor__, 'request_headers',
                     'The HTTP headers to be passed when making a request. '
                     'e.g. [{"header": "Accept-Encoding", "value": "gzip"}]',
                     required_option=False, default=[])
예제 #38
0
from scalyr_agent import (
    ScalyrMonitor,
    UnsupportedSystem,
    define_config_option,
    define_metric,
    define_log_field,
)

# needed for BindableHTTPConnection
httpSourceAddress = "127.0.0.1"

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.tomcat_monitor ``",
    required_option=True,
)
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 PostgreSQL instances on a single server; you can monitor each "
    "instance with a separate tomcatql_monitor record in the Scalyr Agent configuration.",
    convert_to=str,
)
define_config_option(
    __monitor__,
    "monitor_url",
    "Name of host machine the agent will connect to PostgreSQL to retrieve monitoring data.",
예제 #39
0
import os
import errno
import re
import sys
import time
from subprocess import Popen, PIPE

from scalyr_agent.compat import custom_defaultdict as defaultdict
from scalyr_agent import ScalyrMonitor, BadMonitorConfiguration
from scalyr_agent import define_config_option, define_metric, define_log_field

__monitor__ = __name__

define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.linux_process_metrics``',
                     convert_to=str, required_option=True)
define_config_option(__monitor__, 'commandline',
                     'A regular expression which will match the command line of the process you\'re interested in, as '
                     'shown in the output of ``ps aux``. (If multiple processes match the same command line pattern, '
                     'only one will be monitored.)', default=None, convert_to=str)
define_config_option(__monitor__, 'pid',
                     'The pid of the process from which the monitor instance will collect metrics.  This is ignored '
                     'if the ``commandline`` is specified.',
                     default=None, convert_to=str)
define_config_option(__monitor__, 'id',
                     'Included in each log message generated by this monitor, as a field named ``instance``. Allows '
                     'you to distinguish between values recorded by different monitors.',
                     required_option=True, convert_to=str)

define_metric(__monitor__, 'app.cpu',
예제 #40
0
from scalyr_agent.json_lib.objects import ArrayOfStrings
import scalyr_agent.util as scalyr_util
from scalyr_agent.json_lib import JsonObject

import scalyr_agent.scalyr_logging as scalyr_logging

global_log = scalyr_logging.getLogger(__name__)

SCALYR_CONFIG_ANNOTATION_RE = re.compile(r"^(agent\.config\.scalyr\.com/)(.+)")

__monitor__ = __name__

define_config_option(
    __monitor__,
    "module",
    "Always ``scalyr_agent.builtin_monitors.kubernetes_events_monitor``",
    convert_to=six.text_type,
    required_option=True,
)

define_config_option(
    __monitor__,
    "max_log_size",
    "Optional (defaults to None). How large the log file will grow before it is rotated. If None, then the "
    "default value will be taken from the monitor level or the global level log_rotation_max_bytes config option.  Set to zero "
    "for infinite size. Note that rotation is not visible in Scalyr; it is only relevant for managing "
    "disk space on the host running the agent. However, a very small limit could cause logs to be "
    "dropped if there is a temporary network outage and the log overflows before it can be sent to "
    "Scalyr",
    convert_to=int,
    default=None,
        option_name='pid',
        option_description='The pid of the process from which the monitor instance will collect metrics.  This is '
        'ignored if the ``commandline`` is specified.',
        default=None,
        convert_to=str
    ),
    dict(
        option_name='id',
        option_description='Included in each log message generated by this monitor, as a field named ``instance``. '
        'Allows you to distinguish between values recorded by different instances of this monitor.',
        required_option=True,
        convert_to=str
    )
]

_ = [define_config_option(__monitor__, **option) for option in CONFIG_OPTIONS] # pylint: disable=star-args
## End Monitor Configuration
# #########################################################################################




# #########################################################################################
# #########################################################################################
# ## Process's Metrics / Dimensions -
# ##
# ##    Metrics define the capibilities of this monitor.  These some utility functions
# ##    along with the list(s) of metrics themselves.
# ##
def _gather_metric(method, attribute=None, transform=None):
    """Curry arbitrary process metric extraction
예제 #42
0
    import psutil
except ImportError:
    psutil = None

#
# Monitor Configuration - defines the runtime environment and resources available
#
CONFIG_OPTIONS = [
    dict(option_name='module',
         option_description='A ScalyrAgent plugin monitor module',
         convert_to=str,
         required_option=True,
         default='windows_system_metrics')
]

_ = [define_config_option(__monitor__, **option) for option in CONFIG_OPTIONS]  # pylint: disable=star-args
# # End Monitor Configuration
# #########################################################################################

# A special value we return as the result of the disk_io_counters metric evaluation if we
# get an exception indicating diskperf has not been run to turn on the counters.
# We have to use this special value as a hack because there's too many layers in the way to
# do it a more direct route.
__NO_DISK_PERF__ = 'no_disk_perf_signal'


# #########################################################################################
# #########################################################################################
# ## System Metrics / Dimensions -
# ##
# ##    Metrics define the capibilities of this monitor.  These some utility functions
예제 #43
0
import errno
import string
from datetime import datetime

from scalyr_agent import ScalyrMonitor, UnsupportedSystem, define_config_option, define_metric, define_log_field

# We must require 2.5 or greater right now because pg8000 requires it.
if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1] < 5):
    raise UnsupportedSystem('postgresql_monitor', 'Requires Python 2.5 or greater.')

import pg8000

__monitor__ = __name__


define_config_option(__monitor__, 'module',
                     'Always ``scalyr_agent.builtin_monitors.postgres_monitor ``', required_option=True)
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 PostgreSQL instances on a single server; you can monitor each '
                     'instance with a separate postgresql_monitor record in the Scalyr Agent configuration.',
                     convert_to=str)
define_config_option(__monitor__, 'database_host',
                     'Name of host machine the agent will connect to PostgreSQL to retrieve monitoring data.',
                     convert_to=str)
define_config_option(__monitor__, 'database_port',
                     'Name of port on the host machine the agent will connect to PostgreSQL to retrieve monitoring data.',
                     convert_to=str)
define_config_option(__monitor__, 'database_name',
                     'Name of database the agent will connect to PostgreSQL to retrieve monitoring data.',
                     convert_to=str)