├── Dockerfile ├── Dockerfile-alpine ├── Dockerfile-ubuntu ├── README.md ├── entrypoint.sh ├── heartbeat.sh ├── requirements.txt ├── s247_setup.sh └── singleinstance.py /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | MAINTAINER site24x7 4 | 5 | RUN apt-get update && \ 6 | apt-get install -y python3 python3-dev python3-pip python3-venv && \ 7 | apt-get install -y wget && \ 8 | apt-get install -y vim && \ 9 | apt-get install -y libssl-dev && \ 10 | apt-get install -y tini && \ 11 | rm -rf /var/lib/apt/lists/* 12 | 13 | WORKDIR /opt 14 | 15 | COPY ["s247_setup.sh", "entrypoint.sh", "requirements.txt", "heartbeat.sh", "./"] 16 | 17 | RUN chmod +x entrypoint.sh && chmod +x s247_setup.sh 18 | 19 | RUN ./s247_setup.sh 20 | 21 | HEALTHCHECK --interval=10s --timeout=3s --retries=1 \ 22 | CMD ./heartbeat.sh 23 | 24 | ENTRYPOINT ["tini", "--", "/opt/entrypoint.sh"] 25 | 26 | CMD ["bash", "-c", "while true; do sleep 300; done"] 27 | -------------------------------------------------------------------------------- /Dockerfile-alpine: -------------------------------------------------------------------------------- 1 | FROM alpine:3.6 2 | 3 | MAINTAINER site24x7plus 4 | 5 | WORKDIR /opt 6 | 7 | RUN apk add -qU --no-cache coreutils openssl libffi-dev openssl-dev make wget python-dev bash gcc musl-dev linux-headers supervisor ca-certificates 8 | 9 | COPY ["s247_setup.sh", "entrypoint.sh", "heartbeat.sh", "requirements.txt", "singleinstance.py", "./"] 10 | 11 | RUN chmod +x entrypoint.sh && chmod +x heartbeat.sh && chmod +x s247_setup.sh 12 | 13 | RUN addgroup site24x7-group 14 | 15 | RUN adduser -D site24x7-agent -s /bin/bash -G site24x7-group 16 | 17 | RUN ./s247_setup.sh 18 | 19 | RUN wget https://staticdownloads.site24x7.com/server/Site24x7MonitoringAgent.install 20 | 21 | HEALTHCHECK --interval=10s --timeout=3s --retries=1 \ 22 | CMD ./heartbeat.sh 23 | 24 | ENTRYPOINT ["/opt/entrypoint.sh"] 25 | 26 | CMD ["supervisord", "-n", "-c", "/etc/supervisord.conf"] 27 | -------------------------------------------------------------------------------- /Dockerfile-ubuntu: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | MAINTAINER site24x7 4 | 5 | WORKDIR /opt 6 | 7 | RUN apt-get update && \ 8 | apt-get install -y python python-dev python-pip python-virtualenv && \ 9 | apt-get install -y wget && \ 10 | apt-get install -y vim && \ 11 | apt-get install -y libssl-dev && \ 12 | apt-get install -y supervisor && \ 13 | rm -rf /var/lib/apt/lists/* 14 | 15 | COPY ["s247_setup.sh", "entrypoint.sh", "heartbeat.sh", "requirements.txt", "singleinstance.py", "./"] 16 | 17 | RUN chmod +x entrypoint.sh && chmod +x heartbeat.sh && chmod +x s247_setup.sh 18 | 19 | RUN ./s247_setup.sh 20 | 21 | RUN wget https://staticdownloads.site24x7.com/server/Site24x7MonitoringAgent.install 22 | 23 | HEALTHCHECK --interval=10s --timeout=3s --retries=1 \ 24 | CMD ./heartbeat.sh 25 | 26 | ENTRYPOINT ["/opt/entrypoint.sh"] 27 | 28 | CMD ["supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Site24x7 Agent Dockerfile 2 | 3 | This repository is meant to build the base image for a Site24x7 Agent container. You will have to use the resulting image to configure and run the Agent. 4 | 5 | 6 | ## Quick Start 7 | 8 | Run the below command in your server to monitor the host via site24x7-agent container 9 | 10 | ``` 11 | docker run -d --name site24x7-agent \ 12 | -v /var/run/docker.sock:/var/run/docker.sock:ro \ 13 | -v /proc/:/host/proc/:ro \ 14 | -v /sys:/host/sys/:ro \ 15 | -e KEY= \ 16 | site24x7/docker-agent:latest 17 | ``` 18 | 19 | ## Configuration 20 | 21 | 22 | ### Hostname 23 | 24 | By default the agent container will use the `Name` field found in the `docker info` command from the host as a hostname. To change this behavior you can update the `hostname` field in `/opt/site24x7/monagent/conf/monagent.cfg`. The easiest way for this is to use the `HOSTNAME` environment variable (see below). 25 | 26 | ``` 27 | docker run -d --name site24x7-agent \ 28 | -v /var/run/docker.sock:/var/run/docker.sock:ro \ 29 | -v /proc/:/host/proc/:ro \ 30 | -v /sys:/host/sys/:ro \ 31 | -e KEY= \ 32 | -e HOSTNAME= \ 33 | site24x7/docker-agent:latest 34 | ``` 35 | 36 | ## Limitations 37 | 38 | Only volumes that are mounted into the container can have the disk metrics being reported 39 | 40 | ## Contribute 41 | 42 | If you notice a limitation or a bug with this container, feel free to open a [Github issue](https://github.com/site24x7/docker-agent/issues). -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Author : Arunagiriswaran E 3 | #Company : ZOHOCORP 4 | SUCCESS=0 5 | WARNING=1 6 | FAILURE=2 7 | BOOL_TRUE='True' 8 | BOOL_FALSE='False' 9 | 10 | ERROR_MSG="" 11 | SEVERE_FLAG=$BOOL_FALSE 12 | PRODUCT_NAME_UPPERCASE='SITE24X7' 13 | PRODUCT_NAME_LOWERCASE='site24x7' 14 | AGENT_VERSION=2000 15 | INSTALL_FILE_NAME=Site24x7MonitoringAgent.install 16 | 17 | 18 | if [ -z $KEY ]; then 19 | SEVERE_FLAG=$BOOL_TRUE 20 | ERROR_MSG="KEY not set as env variable!!!" 21 | fi 22 | 23 | if [[ -z $EKS_FARGATE && -z $GKE_AUTOPILOT && -z $SERVERLESS ]]; then 24 | if [ ! -d /host/proc ]; then 25 | SEVERE_FLAG=$BOOL_TRUE 26 | ERROR_MSG="$ERROR_MSG /proc folder not mounted from host to /host/proc in container." 27 | fi 28 | if [ ! -d /host/sys ]; then 29 | SEVERE_FLAG=$BOOL_TRUE 30 | ERROR_MSG="$ERROR_MSG /sys folder not mounted from host to /host/sys in container." 31 | fi 32 | fi 33 | 34 | if [ "$SEVERE_FLAG" == "$BOOL_TRUE" ]; then 35 | printf "$ERROR_MSG Hence quitting!!! \n" 36 | exit $FAILURE 37 | fi 38 | 39 | setupVenv(){ 40 | if [ ! -d $PRODUCT_HOME ]; then 41 | mkdir $PRODUCT_HOME 42 | fi 43 | if [ ! -d $PRODUCT_HOME/venv ]; then 44 | cp -r /opt/venv $PRODUCT_HOME 45 | fi 46 | } 47 | 48 | variableUpdate(){ 49 | PRODUCT_HOME=$INSTALL_DIR/$PRODUCT_NAME_LOWERCASE 50 | MON_AGENT_NAME=monagent 51 | PYTHON_VENV_HOME=$PRODUCT_HOME/venv 52 | PYTHON_VENV_HOME_ACTIVATE=$PYTHON_VENV_HOME/bin/activate 53 | PYTHON_VENV_BIN_PATH=$PYTHON_VENV_HOME/bin/python 54 | PYTHON_VENV_PIP_PATH=$PYTHON_VENV_HOME/bin/pip 55 | MON_AGENT_HOME=$PRODUCT_HOME/$MON_AGENT_NAME 56 | MON_AGENT_BIN_DIR=$MON_AGENT_HOME/bin 57 | MON_AGENT_LIB_DIR=$MON_AGENT_HOME/lib 58 | MON_AGENT_LOG_DIR=$MON_AGENT_HOME/logs 59 | MON_AGENT_PYPI_DIR=$MON_AGENT_HOME/pypi 60 | MON_AGENT_LOG_DETAIL_DIR=$MON_AGENT_LOG_DIR/details 61 | MON_AGENT_UNINSTALL_FILE=$MON_AGENT_BIN_DIR/uninstall 62 | MON_AGENT_BIN_BOOT_SERVICE_FILE=$MON_AGENT_BIN_DIR/monagentservice 63 | MON_AGENT_BIN_BOOT_FILE=$MON_AGENT_BIN_DIR/monagent 64 | MON_AGENT_WATCHDOG_BIN_BOOT_FILE=$MON_AGENT_BIN_DIR/monagentwatchdog 65 | MON_AGENT_BIN_PROFILE=$MON_AGENT_BIN_DIR/profile.sh 66 | MON_AGENT_BIN_PROFILE_ENV=$MON_AGENT_BIN_DIR/profile.env.sh 67 | MON_AGENT_PROFILE=$MON_AGENT_HOME/.profile 68 | MON_AGENT_PROFILE_ENV=$MON_AGENT_HOME/.profile.env 69 | MON_AGENT_CONF_DIR=$MON_AGENT_HOME/conf 70 | MON_AGENT_CONF_FILE=$MON_AGENT_CONF_DIR/monagent.cfg 71 | MON_AGENT_ERR_FILE=$MON_AGENT_LOG_DETAIL_DIR/monagent_err 72 | MON_AGENT_WATCHDOG_ERR_FILE=$MON_AGENT_LOG_DETAIL_DIR/monagent_watchdog_err 73 | BINARY_TAR_FILE=site24x7agent.tar.gz 74 | MON_AGENT_INSTALL_LOG=$PRODUCT_HOME/site24x7install.log 75 | MON_AGENT_CONTACT_SUPPORT_MESSAGE="Please contact support with $MON_AGENT_INSTALL_LOG , $MON_AGENT_LOG_DIR and $MON_AGENT_LOG_DETAIL_DIR folder." 76 | PRESENT_INIT_DAEMON_NAME="" 77 | #user varaibles 78 | MON_AGENT_GROUP=$PRODUCT_NAME_LOWERCASE'-group' 79 | MON_AGENT_USER=$PRODUCT_NAME_LOWERCASE'-agent' 80 | MON_AGENT_SUPERVISOR_CONF_FILE=$MON_AGENT_CONF_DIR/supervisor.conf 81 | SUPERVISOR_CONFD_DIR=/etc/supervisor/conf.d 82 | SUPERVISOR_CONFD_FILE=$SUPERVISOR_CONFD_DIR/site24x7-agent.conf 83 | ALPINE_SUPERVISOR_CONFD_FILE=/etc/supervisor.d/site24x7-agent.ini 84 | MON_AGENT_TEMP_FOLDER=$MON_AGENT_HOME/temp 85 | UPGRADE_LOCK_FILE=$MON_AGENT_TEMP_FOLDER/upgrade-lock.txt 86 | } 87 | 88 | log(){ 89 | echo $(date +"%F %T.%N") " $1" >> $MON_AGENT_INSTALL_LOG 2>&1 90 | } 91 | 92 | findAndReplace() { 93 | log "FIND AND REPLACE : String : $1 File : $2" 94 | sed -i "$1" "$2" 95 | } 96 | 97 | python_function(){ 98 | VALUE=`/opt/site24x7/venv/bin/python <> pip_out.txt 16 | } 17 | 18 | setup_venv 19 | install_packages 20 | -------------------------------------------------------------------------------- /singleinstance.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on 25-Jan-2018 3 | 4 | @author: giri 5 | ''' 6 | import psutil 7 | import sys 8 | psutil.PROCFS_PATH = "/host/proc" 9 | filter_list = ["Site24x7Agent", "MonitoringAgent.py"] 10 | for proc in psutil.process_iter(): 11 | try: 12 | pinfo = proc.as_dict(attrs=["name", "exe", "cmdline", "pid"]) 13 | except Exception as e: 14 | continue 15 | if type(pinfo["cmdline"]) is list: 16 | process_name = " ".join(pinfo["cmdline"]).strip() 17 | if process_name: 18 | final_list = list(filter(lambda x : x in process_name, filter_list)) 19 | if final_list: 20 | print("Site24x7Agent already running with pid {} hence quitting!!!".format(pinfo["pid"])) 21 | sys.exit(1) 22 | --------------------------------------------------------------------------------