├── misc └── prometheus-dcos.png ├── node_exporter.json ├── Dockerfile ├── prometheus.yml ├── cadvisor.json ├── prometheus.rules ├── mkalertmanagercfg ├── startup ├── server.json ├── srv2file_sd.go ├── README.md ├── group.json └── LICENSE /misc/prometheus-dcos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lloesche/prometheus-dcos/HEAD/misc/prometheus-dcos.png -------------------------------------------------------------------------------- /node_exporter.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "/prometheus/node-exporter", 3 | "instances": 1, 4 | "cpus": 0.01, 5 | "mem": 256, 6 | "ports": [0], 7 | "uris": ["https://github.com/prometheus/node_exporter/releases/download/0.12.0/node_exporter-0.12.0.linux-amd64.tar.gz"], 8 | "cmd": "node_exporter-0.12.0.linux-amd64/node_exporter -web.listen-address :$PORT", 9 | "constraints": [ 10 | [ 11 | "hostname", 12 | "UNIQUE" 13 | ] 14 | ], 15 | "healthChecks": [ 16 | { 17 | "path": "/metrics", 18 | "portIndex": 0, 19 | "protocol": "HTTP" 20 | } 21 | ], 22 | "acceptedResourceRoles": [ 23 | "*", 24 | "slave_public" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM prom/prometheus:v2.2.1 2 | MAINTAINER Lukas Loesche 3 | EXPOSE 9093 4 | EXPOSE 9090 5 | ADD prometheus.yml /etc/prometheus/ 6 | ADD prometheus.rules /etc/prometheus/ 7 | ADD mkalertmanagercfg /bin/mkalertmanagercfg 8 | ADD startup / 9 | ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init 10 | ADD https://github.com/lloesche/prometheus-dcos/releases/download/0.1/srv2file_sd /bin/srv2file_sd 11 | ADD https://github.com/prometheus/alertmanager/releases/download/v0.15.0-rc.1/alertmanager-0.15.0-rc.1.linux-amd64.tar.gz /tmp/alertmanager.tar.gz 12 | USER root 13 | RUN mkdir -p /tmp/alertmanager && \ 14 | tar -xzf /tmp/alertmanager.tar.gz -C /tmp/alertmanager/ --strip-components=1 && \ 15 | mv /tmp/alertmanager/alertmanager /bin/ && \ 16 | rm -rf /tmp/alertmanager /tmp/alertmanager.tar.gz && \ 17 | chmod +x /startup /bin/dumb-init /bin/srv2file_sd /bin/alertmanager 18 | 19 | ENTRYPOINT [ "/bin/dumb-init", "--" ] 20 | CMD ["/startup"] 21 | -------------------------------------------------------------------------------- /prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | 5 | rule_files: 6 | - prometheus.rules 7 | 8 | scrape_configs: 9 | - job_name: prometheus 10 | static_configs: 11 | - targets: ['localhost:9090'] 12 | - job_name: alertmanager 13 | static_configs: 14 | - targets: ['localhost:9093'] 15 | - job_name: node 16 | file_sd_configs: 17 | - files: ['/etc/prometheus/node_exporter.json'] 18 | relabel_configs: 19 | - source_labels: ['__address__'] 20 | target_label: 'host' 21 | regex: '(.*):.*' 22 | - source_labels: ['__address__'] 23 | target_label: 'instance' 24 | regex: '(.*):.*' 25 | replacement: '${1}:9100' 26 | - job_name: cadvisor 27 | file_sd_configs: 28 | - files: ['/etc/prometheus/cadvisor.json'] 29 | relabel_configs: 30 | - source_labels: ['__address__'] 31 | target_label: 'host' 32 | regex: '(.*):.*' 33 | - source_labels: ['__address__'] 34 | target_label: 'instance' 35 | regex: '(.*):.*' 36 | replacement: '${1}:8080' 37 | 38 | alerting: 39 | alertmanagers: 40 | - scheme: @ALERTMANAGER_SCHEME@ 41 | static_configs: 42 | - targets: 43 | - "@ALERTMANAGER_URL@" 44 | -------------------------------------------------------------------------------- /cadvisor.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "/prometheus/cadvisor", 3 | "instances": 1, 4 | "cpus": 0.04, 5 | "mem": 128, 6 | "constraints": [ 7 | [ 8 | "hostname", 9 | "UNIQUE" 10 | ] 11 | ], 12 | "container": { 13 | "docker": { 14 | "image": "google/cadvisor", 15 | "portMappings": [ 16 | { 17 | "containerPort": 8080, 18 | "protocol": "tcp" 19 | } 20 | ], 21 | "network": "BRIDGE" 22 | }, 23 | "type": "DOCKER", 24 | "volumes": [ 25 | { 26 | "containerPath": "/rootfs", 27 | "hostPath": "/", 28 | "mode": "RO" 29 | }, 30 | { 31 | "containerPath": "/var/run", 32 | "hostPath": "/var/run", 33 | "mode": "RW" 34 | }, 35 | { 36 | "containerPath": "/sys", 37 | "hostPath": "/sys", 38 | "mode": "RO" 39 | }, 40 | { 41 | "containerPath": "/var/lib/docker", 42 | "hostPath": "/var/lib/docker", 43 | "mode": "RO" 44 | } 45 | ] 46 | }, 47 | "healthChecks": [ 48 | { 49 | "protocol": "HTTP", 50 | "path": "/metrics", 51 | "gracePeriodSeconds": 300, 52 | "intervalSeconds": 60, 53 | "timeoutSeconds": 20, 54 | "maxConsecutiveFailures": 3, 55 | "ignoreHttp1xx": false 56 | } 57 | ], 58 | "acceptedResourceRoles": [ 59 | "*", 60 | "slave_public" 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /prometheus.rules: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: prometheus.rules 3 | rules: 4 | - alert: InstanceDown 5 | expr: up == 0 6 | for: 5m 7 | labels: 8 | severity: high-priority 9 | annotations: 10 | description: '{{ $labels.host }} of job {{ $labels.job }} has been down for 11 | more than 5 minutes.' 12 | summary: Instance {{ $labels.host }} down 13 | - alert: InstanceLowDisk 14 | expr: 100 - (node_filesystem_avail{device=~"^(?:/.*)$",mountpoint!~"^(?:/var/lib/mesos/slave/.*)$"} 15 | / node_filesystem_size * 100) > 90 16 | for: 5m 17 | labels: 18 | severity: high-priority 19 | annotations: 20 | description: '{{$labels.host}} has less than 10% free disk space' 21 | summary: 'Instance {{$labels.host}}: low disk space' 22 | - alert: InstanceHighCpu 23 | expr: 100 - (avg(irate(node_cpu{job="node",mode="idle"}[5m])) BY (instance) * 24 | 100) > 99 25 | for: 6h 26 | labels: 27 | severity: low-priority 28 | annotations: 29 | description: '{{$labels.host}} has high CPU activity' 30 | summary: 'Instance {{$labels.host}}: CPU high' 31 | - alert: InstanceLowMemory 32 | expr: node_memory_MemAvailable < 268435456 33 | for: 10m 34 | labels: 35 | severity: low-priority 36 | annotations: 37 | description: '{{$labels.host}} has less than 256M memory available' 38 | summary: 'Instance {{$labels.host}}: memory low' 39 | -------------------------------------------------------------------------------- /mkalertmanagercfg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -o errexit -o nounset -o pipefail 3 | 4 | if [ -z "${SMTP_TO-}" ]; then 5 | echo "SMTP_TO recipient required" 6 | exit 1 7 | fi 8 | 9 | alertmanager_cfg="$1" 10 | 11 | cat > "$alertmanager_cfg" << EOF 12 | global: 13 | smtp_smarthost: '${SMTP_SMARTHOST:-localhost:25}' 14 | smtp_from: '${SMTP_FROM:-noreply@example.com}' 15 | EOF 16 | if [ -n "${SMTP_LOGIN-}" -a -n "${SMTP_PASSWORD-}" ]; then 17 | cat >> "$alertmanager_cfg" << EOF 18 | smtp_auth_username: '$SMTP_LOGIN' 19 | smtp_auth_password: '$SMTP_PASSWORD' 20 | EOF 21 | fi 22 | 23 | cat >> "$alertmanager_cfg" << EOF 24 | 25 | route: 26 | group_by: [cluster] 27 | group_wait: 30s 28 | group_interval: 5m 29 | repeat_interval: 3h 30 | receiver: email 31 | EOF 32 | 33 | routes='' 34 | receivers='' 35 | for pd_key in $(env | grep -e '^PAGERDUTY_[A-Za-z0-9_]\+_KEY') 36 | do 37 | key=$(echo $pd_key | cut -d = -f 1 | tr A-Z a-z) 38 | value=$(echo $pd_key | cut -d = -f 2-) # BusyBox's ash doesn't know about ${!key} or arrays 39 | key=${key:10}; key=${key%_key}; key=${key//_/-} 40 | if [ -z "$routes" ]; then 41 | routes=" routes:\n" 42 | fi 43 | echo "Adding PagerDuty Service $key" 44 | routes="$routes - match:\n severity: $key\n receiver: pagerduty-$key\n" 45 | receivers="$receivers- name: pagerduty-$key\n pagerduty_configs:\n - service_key: '$value'\n" 46 | done 47 | 48 | if [ -n "$routes" ]; then 49 | echo -ne "$routes" >> "$alertmanager_cfg" 50 | fi 51 | 52 | cat >> "$alertmanager_cfg" << EOF 53 | 54 | receivers: 55 | - name: email 56 | email_configs: 57 | - to: '$SMTP_TO' 58 | EOF 59 | if [ -n "$receivers" ]; then 60 | echo -ne "$receivers" >> "$alertmanager_cfg" 61 | fi 62 | -------------------------------------------------------------------------------- /startup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -o errexit -o nounset -o pipefail 3 | 4 | STORAGE_PATH=/prometheus 5 | [ -d /mnt/mesos/sandbox/prometheus ] && STORAGE_PATH=/mnt/mesos/sandbox/prometheus 6 | mkdir -p $STORAGE_PATH/server $STORAGE_PATH/alertmanager 7 | rm -f $STORAGE_PATH/server/lock 8 | 9 | /bin/mkalertmanagercfg "/etc/prometheus/alertmanager.yml" 10 | 11 | if [ -n "${RULES-}" ]; then 12 | echo "Writing ENV set RULES to /etc/prometheus/prometheus.rules" 13 | echo -e "$RULES" > /etc/prometheus/prometheus.rules 14 | fi 15 | 16 | if [ -n "${SERVER_CONFIG-}" ]; then 17 | echo "Writing Prometheus config to /etc/prometheus/prometheus.yml" 18 | echo -e "$SERVER_CONFIG" > /etc/prometheus/prometheus.yml 19 | fi 20 | 21 | if [ -n "${NODE_EXPORTER_SRV-}" ]; then 22 | /bin/srv2file_sd -srv "$NODE_EXPORTER_SRV" -out "/etc/prometheus/node_exporter.json" -loop -time ${SRV_REFRESH_INTERVAL:-60} & 23 | fi 24 | if [ -n "${CADVISOR_SRV-}" ]; then 25 | /bin/srv2file_sd -srv "$CADVISOR_SRV" -out "/etc/prometheus/cadvisor.json" -loop -time ${SRV_REFRESH_INTERVAL:-60} & 26 | fi 27 | 28 | /bin/alertmanager --config.file "/etc/prometheus/alertmanager.yml" \ 29 | --storage.path "$STORAGE_PATH/alertmanager" & 30 | 31 | /bin/sed -i'' \ 32 | -e "s#@ALERTMANAGER_SCHEME@#${ALERTMANAGER_SCHEME:-http}#" \ 33 | -e "s#@ALERTMANAGER_URL@#${ALERTMANAGER_URL:-localhost:9093}#" \ 34 | /etc/prometheus/prometheus.yml 35 | 36 | /bin/prometheus \ 37 | --config.file=/etc/prometheus/prometheus.yml \ 38 | --storage.tsdb.path=$STORAGE_PATH/server \ 39 | --storage.tsdb.retention="${STORAGE_TSDB_RETENTION:-7d}" \ 40 | --web.console.libraries=/etc/prometheus/console_libraries \ 41 | --web.console.templates=/etc/prometheus/consoles \ 42 | --web.external-url="${EXTERNAL_URI:-http://prometheusserver.marathon.l4lb.thisdcos.directory:9090}" \ 43 | "$@" 44 | -------------------------------------------------------------------------------- /server.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "/prometheus/server", 3 | "instances": 1, 4 | "cpus": 1, 5 | "mem": 4096, 6 | "ports": [0], 7 | "env": { 8 | "EXTERNAL_URI": "https://prometheus-server.example.com/", 9 | "NODE_EXPORTER_SRV": "_node-exporter.prometheus._tcp.marathon.mesos", 10 | "CADVISOR_SRV": "_cadvisor.prometheus._tcp.marathon.mesos", 11 | "PAGERDUTY_HIGH_PRIORITY_KEY": "d230f2398hf293h2304f304j343f0j34", 12 | "PAGERDUTY_LOW_PRIORITY_KEY": "d2302n3f4f4h39230f239f03g30jf24f", 13 | "SMTP_FROM": "noreply@example.com", 14 | "SMTP_TO": "ops@example.com", 15 | "SMTP_SMARTHOST": "smtp.example.com", 16 | "SMTP_LOGIN": "someuser", 17 | "SMTP_PASSWORD": "somepassword" 18 | }, 19 | "container": { 20 | "type": "DOCKER", 21 | "volumes": [ 22 | { 23 | "containerPath": "prometheus", 24 | "persistent": { 25 | "size": 10240 26 | }, 27 | "mode": "RW" 28 | } 29 | ], 30 | "docker": { 31 | "image": "lloesche/prometheus-dcos", 32 | "forcePullImage": true, 33 | "network": "BRIDGE", 34 | "portMappings": [ 35 | { 36 | "containerPort": 9090, 37 | "protocol": "tcp", 38 | "labels": { 39 | "VIP_0": "/prometheus/server:9090" 40 | } 41 | }, 42 | { 43 | "containerPort": 9093, 44 | "protocol": "tcp", 45 | "labels": { 46 | "VIP_0": "/prometheus/server:9093" 47 | } 48 | } 49 | ] 50 | } 51 | }, 52 | "residency": { 53 | "taskLostBehavior": "WAIT_FOREVER" 54 | }, 55 | "labels": { 56 | "HAPROXY_0_VHOST": "prometheus-server.example.com", 57 | "HAPROXY_1_VHOST": "prometheus-alertmanager.example.com", 58 | "HAPROXY_GROUP": "external" 59 | }, 60 | "healthChecks": [ 61 | { 62 | "path": "/api/v1/query?query=prometheus_build_info", 63 | "portIndex": 0, 64 | "protocol": "HTTP" 65 | } 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /srv2file_sd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "log" 7 | "os" 8 | "net" 9 | "strconv" 10 | "encoding/json" 11 | "io/ioutil" 12 | "time" 13 | ) 14 | 15 | func main() { 16 | hostname := flag.String("srv", "", "Hostname that points to a srv record") 17 | outfile := flag.String("out", "", "Path to JSON file to write") 18 | loop := flag.Bool("loop", false, "Loop forever") 19 | looptime := flag.Int("time", 300, "Time to wait between hostname resolution refresh cycles") 20 | flag.Parse() 21 | 22 | if *hostname == "" || *outfile == "" { 23 | flag.PrintDefaults() 24 | os.Exit(1) 25 | } 26 | if *loop { 27 | for { 28 | generate(*hostname, *outfile) 29 | time.Sleep(time.Duration(*looptime) * time.Second) 30 | } 31 | } else { 32 | generate(*hostname, *outfile) 33 | } 34 | 35 | } 36 | 37 | func generate(hostname string, outfile string) { 38 | targets := []string{} 39 | log.Println(fmt.Sprintf("Looking up hostname %s", hostname)) 40 | 41 | _, addrs, err := net.LookupSRV("", "", hostname) 42 | if err != nil { 43 | log.Println(fmt.Sprintf("Error: %s", err)) 44 | return 45 | } else { 46 | for i := 0; i < len(addrs); i++ { 47 | srvaddrs, err := net.LookupHost(addrs[i].Target) 48 | log.Println(fmt.Sprintf("%d Target: %s", i, addrs[i].Target)) 49 | log.Println(fmt.Sprintf("%d Port: %d", i, addrs[i].Port)) 50 | if err == nil { 51 | for n := 0; n < len(srvaddrs); n++ { 52 | log.Println(fmt.Sprintf("%d IP: %s", i, srvaddrs[n])) 53 | targets = append(targets, srvaddrs[n]+":"+strconv.Itoa(int(addrs[i].Port))) 54 | } 55 | } 56 | } 57 | } 58 | file_sd := [1]map[string][]string{} 59 | file_sd[0] = map[string][]string{"targets": targets} 60 | file_sd_str, _ := json.Marshal(file_sd) 61 | 62 | file, err := ioutil.TempFile("", "file-sd") 63 | if err != nil { 64 | log.Println(err) 65 | return 66 | } 67 | if _, err = file.Write([]byte(file_sd_str)); err != nil { 68 | log.Println(err) 69 | return 70 | } 71 | 72 | if err = file.Close(); err != nil { 73 | log.Println(err) 74 | return 75 | } 76 | 77 | if err = os.Chmod(file.Name(), 0644); err != nil { 78 | log.Println(err) 79 | return 80 | } 81 | 82 | if err = os.Rename(file.Name(), outfile); err != nil { 83 | log.Println(err) 84 | return 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Prometheus](https://prometheus.io/) on [Mesosphere DC/OS](https://dcos.io/) 2 | 3 | ## Intro 4 | This runs Prometheus on DC/OS (1.8+). `server.json` contains the service definition for Prometheus itself. `node_exporter.json` contains the service definition for node_exporter. I'm running node_exporter inside a Mesos (cgroups) container so that it sees all of the hosts filesystems without any need for priviliges or translation. 5 | 6 | To make life easier I also created a `group.json` that includes the Prometheus Server, Node Exporter, [cAdvisor](https://github.com/google/cadvisor), [Grafana Dashboard](https://github.com/lloesche/prometheus-grafana-dcos) and an [authentication proxy](https://github.com/lloesche/auth-proxy-dcos) which will add Basic Auth to the Server's WebUI. The group assumes you're running [Marathon-LB](https://github.com/mesosphere/marathon-lb) on your DC/OS and exports Marathon-LB labels. 7 | 8 | To get started just install the group as shown below. 9 | 10 | ## Usage 11 | Install using 12 | ``` 13 | $ dcos marathon group add https://raw.githubusercontent.com/lloesche/prometheus-dcos/master/group.json 14 | $ dcos marathon app update /prometheus/node-exporter instances=7000 # however many agents you have in your cluster 15 | ``` 16 | 17 | *Important:* Once the apps are deployed make sure to update all Environment Variables with something useful. Alternatively download group.json and modify them directly before deploying to DC/OS. 18 | 19 | When working with the `group.json` you'll want to adjust the following variables and labels: 20 | 21 | | App | Variable | Value | 22 | |----------|----------|-------| 23 | |`/prometheus/server` | `EXTERNAL_URI` | The complete URL your Prometheus Server will be reachable under (http(s)://...)| 24 | |`/prometheus/server` | `PAGERDUTY_HIGH_PRIORITY_KEY` | A PagerDuty API Key for High Priority Alerts| 25 | |`/prometheus/server` | `PAGERDUTY_LOW_PRIORITY_KEY` | A PagerDuty API Key for Low Priority Alerts| 26 | |`/prometheus/server` | `SMTP_FROM` | Sender Address Alert Emails are send from| 27 | |`/prometheus/server` | `SMTP_TO` | Recipient Address Alert Emails get send to| 28 | |`/prometheus/server` | `SMTP_SMARTHOST` | SMTP Server Alert Emails are send via| 29 | |`/prometheus/server` | `SMTP_LOGIN` | SMTP Server Login| 30 | |`/prometheus/server` | `SMTP_PASSWORD` | SMTP Server Password| 31 | |`/prometheus/auth-proxy` | `LOGIN` | Login Users have to provide when accessing Prometheus Server| 32 | |`/prometheus/auth-proxy` | `PASSWORD` | Password Users have to provide when accessing Prometheus Server ([following this scheme](http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html#auth_basic_user_file))| 33 | |`/prometheus/grafana` | `GF_SERVER_ROOT_URL` | The complete URL Grafana will be reachable under | 34 | |`/prometheus/grafana` | `GF_SECURITY_ADMIN_USER` | Grafana Admin Login| 35 | |`/prometheus/grafana` | `GF_SECURITY_ADMIN_PASSWORD` | Grafana Admin Password| 36 | 37 | | App | Label | Value | 38 | |----------|----------|-------| 39 | |`/prometheus/auth-proxy` | `HAPROXY_0_VHOST` | Hostname Prometheus Server should be reachable under. This is what's contained in `EXTERNAL_URI`| 40 | |`/prometheus/grafana` | `HAPROXY_0_VHOST` | Hostname Grafana should be reachable under. This is what's contained in `GF_SERVER_ROOT_URL` | 41 | 42 | ## Connections 43 | ![Connections](https://raw.githubusercontent.com/lloesche/prometheus-dcos/master/misc/prometheus-dcos.png "Connections") 44 | 45 | ## Why file_sd based discovery? 46 | Prometheus supports DNS based service discovery. Given a Mesos-DNS SRV record like `_node-exporter.prometheus._tcp.marathon.mesos` it will find the list of node_exporter nodes and poll them. However it'll result in instance names like 47 | ``` 48 | node-exporter.prometheus-6ms1y-s1.marathon.mesos:14181 49 | node-exporter.prometheus-54eio-s0.marathon.mesos:12227 50 | node-exporter.prometheus-1e1ow-s2.marathon.mesos:31798 51 | ``` 52 | which is not very useful. Also the Mesos scheduler will assign a random port resource. 53 | 54 | So after a [discussion on the mailing list](https://groups.google.com/forum/#!topic/prometheus-developers/ydww-vzG0IE) it turned out that Prometheus can't relabel the instance with the node's IP address since name resolution happens after relabeling. It was suggested to use the file_sd based discovery method instead. This is what the `srv2file_sd` helper is for. It performs the same SRV and A record lookup and instead of the hostname writes the node's IP addres into the targets file. There's also relabeling taking place to replace the random port number with the node_exporter standard port 9100 so that when a node_exporter is restarted on a different port it's data is still associated with the same node. 55 | 56 | ## Environment Variables 57 | | Variable | Function | Example | 58 | |----------|----------|-------| 59 | |`NODE_EXPORTER_SRV` | Mesos-DNS SRV record of the node_exporter | `NODE_EXPORTER_SRV=_node-exporter.prometheus._tcp.marathon.mesos`| 60 | |`CADVISOR_SRV` | Mesos-DNS SRV record of cadvisor | `CADVISOR_SRV=_cadvisor.prometheus._tcp.marathon.mesos`| 61 | |`SRV_REFRESH_INTERVAL` (optional) | How often should we update the targets JSON | `SRV_REFRESH_INTERVAL=60`| 62 | |`ALERTMANAGER_URL` (optional) | AlertManager URL - uses buildin AlertManager if not defined | `ALERTMANAGER_URL=prometheusalertmanager.marathon.l4lb.thisdcos.directory:9093`| 63 | |`ALERTMANAGER_SCHEME` (optional) | AlertManager Scheme - uses http if not defined | `ALERTMANAGER_SCHEME=https`| 64 | |`PAGERDUTY_*_KEY` (optional) | Pagerduty API Key for Alertmanager. Name in * will be made into the severity | `PAGERDUTY_HIGH_PRIORITY_KEY=93dsqkj23gfTD_nFbdwqk` | 65 | |`RULES` (optional) | prometheus.rules, replaces the version that ships with the container image | `RULES=... Entire prometheus.rules file content`| 66 | |`EXTERNAL_URI` (optional) | External WebUI URL | `EXTERNAL_URI=http://prometheusserver.marathon.l4lb.thisdcos.directory:9090`| 67 | |`STORAGE_TSDB_RETENTION` (optional) | Storage TSDB Retention \ `STORAGE_TSDB_RETENTION=7d`| 68 | |`SMTP_FROM` | How often should we update the targets JSON | `SMTP_FROM=alertmanager@example.com`| 69 | |`SMTP_TO` | How often should we update the targets JSON | `SMTP_TO=ops@example.com`| 70 | |`SMTP_SMARTHOST` | How often should we update the targets JSON | `SMTP_SMARTHOST=mail.example.com`| 71 | |`SMTP_LOGIN` | How often should we update the targets JSON | `SMTP_LOGIN=prometheus`| 72 | |`SMTP_PASSWORD` | How often should we update the targets JSON | `SMTP_PASSWORD=23iuhf23few`| 73 | 74 | To produce the $RULES env variable it can be handy to use something like 75 | ``` 76 | $ cat prometheus.rules | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g' 77 | ``` 78 | 79 | ## Building the SRV lookup helper 80 | To run the `srv2file_sd` helper tool inside the minimal prom/prometheus Docker container I statically linked it. To do so yourself install [musl libc](http://www.musl-libc.org/) and compile using: 81 | ``` 82 | $ CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' srv2file_sd.go 83 | ``` 84 | 85 | ## Bugs 86 | All this was hacked up in an afternoon. Surely there's bugs. If you find any submit a PR or open an issue. 87 | 88 | ## TODO 89 | - perform A lookups in parallel instead of looping over all hosts sequentially 90 | -------------------------------------------------------------------------------- /group.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "/prometheus", 3 | "apps": [ 4 | { 5 | "id": "/prometheus/server", 6 | "instances": 1, 7 | "cpus": 1, 8 | "mem": 4096, 9 | "ports": [ 10 | 0 11 | ], 12 | "env": { 13 | "EXTERNAL_URI": "https://prometheus-server.example.com/", 14 | "NODE_EXPORTER_SRV": "_node-exporter.prometheus._tcp.marathon.mesos", 15 | "CADVISOR_SRV": "_cadvisor.prometheus._tcp.marathon.mesos", 16 | "PAGERDUTY_HIGH_PRIORITY_KEY": "d230f2398hf293h2304f304j343f0j34", 17 | "PAGERDUTY_LOW_PRIORITY_KEY": "d2302n3f4f4h39230f239f03g30jf24f", 18 | "SMTP_FROM": "noreply@example.com", 19 | "SMTP_TO": "ops@example.com", 20 | "SMTP_SMARTHOST": "smtp.example.com", 21 | "SMTP_LOGIN": "someuser", 22 | "SMTP_PASSWORD": "somepassword" 23 | }, 24 | "labels": { 25 | "HAPROXY_0_VHOST": "prometheus-server.example.com", 26 | "HAPROXY_0_REDIRECT_TO_HTTPS": "true", 27 | "HAPROXY_0_AUTH": "Prometheus:monitoring:$1$/YEoV5dv$1j3BbCu7j4D29RpBCUXmM/", 28 | "HAPROXY_1_VHOST": "prometheus-alertmanager.example.com", 29 | "HAPROXY_1_REDIRECT_TO_HTTPS": "true", 30 | "HAPROXY_1_AUTH": "Prometheus:monitoring:$1$/YEoV5dv$1j3BbCu7j4D29RpBCUXmM/", 31 | "HAPROXY_GROUP": "external" 32 | }, 33 | "container": { 34 | "type": "DOCKER", 35 | "volumes": [ 36 | { 37 | "containerPath": "prometheus", 38 | "persistent": { 39 | "size": 10240 40 | }, 41 | "mode": "RW" 42 | } 43 | ], 44 | "docker": { 45 | "image": "lloesche/prometheus-dcos", 46 | "forcePullImage": true, 47 | "network": "BRIDGE", 48 | "portMappings": [ 49 | { 50 | "containerPort": 9090, 51 | "protocol": "tcp", 52 | "labels": { 53 | "VIP_0": "/prometheus/server:9090" 54 | } 55 | }, 56 | { 57 | "containerPort": 9093, 58 | "protocol": "tcp", 59 | "labels": { 60 | "VIP_0": "/prometheus/server:9093" 61 | } 62 | } 63 | ] 64 | } 65 | }, 66 | "residency": { 67 | "taskLostBehavior": "WAIT_FOREVER" 68 | }, 69 | "healthChecks": [ 70 | { 71 | "path": "/api/v1/query?query=prometheus_build_info", 72 | "portIndex": 0, 73 | "protocol": "HTTP" 74 | } 75 | ] 76 | }, 77 | { 78 | "id": "/prometheus/node-exporter", 79 | "instances": 1, 80 | "cpus": 0.01, 81 | "mem": 256, 82 | "ports": [ 83 | 0 84 | ], 85 | "fetch": [ 86 | { 87 | "uri": "https://github.com/prometheus/node_exporter/releases/download/v0.15.1/node_exporter-0.15.1.linux-amd64.tar.gz" 88 | } 89 | ], 90 | "cmd": "node_exporter-0.15.1.linux-amd64/node_exporter --collector.systemd --collector.interrupts --collector.nfs --web.listen-address :$PORT", 91 | "constraints": [ 92 | [ 93 | "hostname", 94 | "UNIQUE" 95 | ] 96 | ], 97 | "healthChecks": [ 98 | { 99 | "path": "/metrics", 100 | "portIndex": 0, 101 | "protocol": "HTTP" 102 | } 103 | ], 104 | "upgradeStrategy": { 105 | "minimumHealthCapacity": 0.5, 106 | "maximumOverCapacity": 0 107 | }, 108 | "acceptedResourceRoles": [ 109 | "*", 110 | "slave_public" 111 | ] 112 | }, 113 | { 114 | "id": "/prometheus/cadvisor", 115 | "instances": 1, 116 | "cpus": 0.04, 117 | "mem": 128, 118 | "constraints": [ 119 | [ 120 | "hostname", 121 | "UNIQUE" 122 | ] 123 | ], 124 | "container": { 125 | "docker": { 126 | "image": "google/cadvisor", 127 | "portMappings": [ 128 | { 129 | "containerPort": 8080, 130 | "protocol": "tcp" 131 | } 132 | ], 133 | "network": "BRIDGE" 134 | }, 135 | "type": "DOCKER", 136 | "volumes": [ 137 | { 138 | "containerPath": "/rootfs", 139 | "hostPath": "/", 140 | "mode": "RO" 141 | }, 142 | { 143 | "containerPath": "/var/run", 144 | "hostPath": "/var/run", 145 | "mode": "RW" 146 | }, 147 | { 148 | "containerPath": "/sys", 149 | "hostPath": "/sys", 150 | "mode": "RO" 151 | }, 152 | { 153 | "containerPath": "/var/lib/docker", 154 | "hostPath": "/var/lib/docker", 155 | "mode": "RO" 156 | } 157 | ] 158 | }, 159 | "healthChecks": [ 160 | { 161 | "protocol": "HTTP", 162 | "path": "/metrics", 163 | "gracePeriodSeconds": 300, 164 | "intervalSeconds": 60, 165 | "timeoutSeconds": 20, 166 | "maxConsecutiveFailures": 3, 167 | "ignoreHttp1xx": false 168 | } 169 | ], 170 | "upgradeStrategy": { 171 | "minimumHealthCapacity": 0.5, 172 | "maximumOverCapacity": 0 173 | }, 174 | "acceptedResourceRoles": [ 175 | "*", 176 | "slave_public" 177 | ] 178 | }, 179 | { 180 | "id": "/prometheus/grafana", 181 | "instances": 1, 182 | "cpus": 0.5, 183 | "mem": 1024, 184 | "ports": [ 185 | 0 186 | ], 187 | "env": { 188 | "GF_PATHS_DATA": "/mnt/mesos/sandbox/grafana", 189 | "GF_SERVER_ROOT_URL": "https://prometheus-dashboard.example.com", 190 | "GF_SECURITY_ADMIN_USER": "someadmin", 191 | "GF_SECURITY_ADMIN_PASSWORD": "somepassword", 192 | "PROMETHEUS_URI": "http://prometheusserver.marathon.l4lb.thisdcos.directory:9090/" 193 | }, 194 | "labels": { 195 | "HAPROXY_0_VHOST": "prometheus-dashboard.example.com", 196 | "HAPROXY_0_REDIRECT_TO_HTTPS": "true", 197 | "HAPROXY_GROUP": "external" 198 | }, 199 | "container": { 200 | "type": "DOCKER", 201 | "volumes": [ 202 | { 203 | "containerPath": "grafana", 204 | "persistent": { 205 | "size": 4096 206 | }, 207 | "mode": "RW" 208 | } 209 | ], 210 | "docker": { 211 | "image": "lloesche/prometheus-grafana-dcos", 212 | "forcePullImage": true, 213 | "network": "BRIDGE", 214 | "portMappings": [ 215 | { 216 | "containerPort": 3000, 217 | "protocol": "tcp" 218 | } 219 | ] 220 | } 221 | }, 222 | "residency": { 223 | "taskLostBehavior": "WAIT_FOREVER" 224 | }, 225 | "healthChecks": [ 226 | { 227 | "path": "/", 228 | "portIndex": 0, 229 | "protocol": "HTTP" 230 | } 231 | ] 232 | } 233 | ] 234 | } 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------