Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions traffic_monitor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This is a very simple Dockerfile.
# All it does is install and start the Traffic Monitor, given a Traffic Ops to point it to.
# It doesn't do any of the complex things the Dockerfiles in infrastructure/docker or infrastructure/cdn-in-a-box do, like inserting itself into Traffic Ops.
# It is designed for a very simple use case, where the complex orchestration of other Traffic Control components is done elsewhere (or manually).

# Example Build and Run:
# docker build --build-arg RPM=traffic_monitor.rpm --tag traffic_monitor:latest .
#
# docker run --detach --name tm --hostname tm --net=tmi --env TO_URI=http://to.invalid:3000 --env TO_USER=user --env TO_PASS=pass traffic_monitor:latest

FROM centos/systemd
MAINTAINER dev@trafficcontrol.apache.org

ARG RPM=traffic_monitor.rpm
ADD $RPM /

RUN yum install -y initscripts
RUN yum install -y /$(basename $RPM)
RUN rm /$(basename $RPM)

RUN curl -L jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 > /usr/sbin/jq && chmod +x /usr/sbin/jq

ADD Dockerfile_run.sh /
ENTRYPOINT /Dockerfile_run.sh
81 changes: 81 additions & 0 deletions traffic_monitor/Dockerfile_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# The following environment variables must be set (ordinarily by `docker run -e` arguments):
# TO_URI
# TO_USER
# TO_PASS
# CDN

# Check that env vars are set
envvars=( TO_URI TO_USER TO_PASS CDN PORT )
for v in $envvars
do
if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
done

start() {
service traffic_monitor start
touch /opt/traffic_monitor/var/log/traffic_monitor.log
exec tail -f /opt/traffic_monitor/var/log/traffic_monitor.log
}

init() {
mkdir -p /opt/traffic_monitor/conf
cat > /opt/traffic_monitor/conf/traffic_monitor.cfg <<- EOF
{
"cache_health_polling_interval_ms": 6000,
"cache_stat_polling_interval_ms": 6000,
"monitor_config_polling_interval_ms": 15000,
"http_timeout_ms": 2000,
"peer_polling_interval_ms": 5000,
"peer_optimistic": true,
"max_events": 200,
"max_stat_history": 5,
"max_health_history": 5,
"health_flush_interval_ms": 20,
"stat_flush_interval_ms": 20,
"log_location_event": "/opt/traffic_monitor/var/log/event.log",
"log_location_error": "/opt/traffic_monitor/var/log/traffic_monitor.log",
"log_location_warning": "/opt/traffic_monitor/var/log/traffic_monitor.log",
"log_location_info": "null",
"log_location_debug": "null",
"serve_read_timeout_ms": 10000,
"serve_write_timeout_ms": 10000,
"http_poll_no_sleep": false,
"static_file_dir": "/opt/traffic_monitor/static/"
}
EOF

cat > /opt/traffic_monitor/conf/traffic_ops.cfg <<- EOF
{
"username": "$TO_USER",
"password": "$TO_PASS",
"url": "$TO_URI",
"insecure": true,
"cdnName": "$CDN",
"httpListener": ":$PORT"
}
EOF

echo "INITIALIZED=1" >> /etc/environment
}

source /etc/environment
if [ -z "$INITIALIZED" ]; then init; fi
start
11 changes: 11 additions & 0 deletions traffic_monitor/health/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package health
*/

import (
"errors"
"fmt"
"strconv"
"sync"
"time"

Expand All @@ -33,6 +35,15 @@ func (t Time) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%d", time.Time(t).Unix())), nil
}

func (t *Time) UnmarshalJSON(data []byte) error {
i, err := strconv.ParseInt(string(data), 10, 64)
if err != nil {
return errors.New("health.Time (" + string(data) + ") must be a unix epoch integer: " + err.Error())
}
*t = Time(time.Unix(i, 0))
return nil
}

// Event represents an event change in aggregated data. For example, a cache being marked as unavailable.
type Event struct {
Time Time `json:"time"`
Expand Down
48 changes: 48 additions & 0 deletions traffic_monitor/tests/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This is a very simple Dockerfile.
# All it does is install and start the Traffic Monitor, given a Traffic Ops to point it to.
# It doesn't do any of the complex things the Dockerfiles in infrastructure/docker or infrastructure/cdn-in-a-box do, like inserting itself into Traffic Ops.
# It is designed for a very simple use case, where the complex orchestration of other Traffic Control components is done elsewhere (or manually).

# Example Build and Run:
# docker build --build-arg RPM=traffic_monitor.rpm --tag traffic_monitor:latest .
#
# docker run --detach --name tm --hostname tm --net=tmi --env TO_URI=http://to.invalid:3000 --env TO_USER=user --env TO_PASS=pass traffic_monitor:latest

FROM centos/systemd
MAINTAINER dev@trafficcontrol.apache.org

# ARG RPM=traffic_monitor.rpm
# ADD $RPM /

RUN yum install -y initscripts
RUN yum install -y epel-release
RUN yum install -y golang
# RUN yum install -y /$(basename $RPM)
# RUN rm /$(basename $RPM)

COPY traffic_monitor_integration_test /

# TODO build go test here, instead of requiring it manually be built beforehand
# See /infrastructure/cdn-in-a-box/traffic_ops_integration_test/Dockerfile

RUN curl -L jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 > /usr/sbin/jq && chmod +x /usr/sbin/jq

COPY Dockerfile_run.sh /
ENTRYPOINT /Dockerfile_run.sh
Loading