Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit 0ef5b69

Browse files
committed
Merge pull request #3 from kpacha/mesos-dns
Mesos dns
2 parents fba11e7 + f4677ec commit 0ef5b69

28 files changed

+878
-331
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ go:
99
- 1.4
1010

1111
install:
12-
- go get ./...
13-
- go fmt
12+
- make
1413
- go vet

Dockerfile

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
FROM golang:1.5.1-onbuild
1+
FROM golang:1.5.1
22
MAINTAINER kpacha
33

4-
ENV MESOS_MASTER_HOST=leader.mesos
5-
ENV MESOS_MASTER_PORT=5050
6-
ENV MESOS_SLAVE_HOST=slave.mesos
7-
ENV MESOS_SLAVE_PORT=5051
8-
9-
ENV MARATHON_HOST=marathon.mesos
10-
ENV MARATHON_PORT=8080
11-
12-
ENV INFLUXDB_HOST=influxdb
13-
ENV INFLUXDB_PORT=8086
14-
ENV INFLUXDB_DB=mesos
154
ENV INFLUXDB_USER=root
165
ENV INFLUXDB_PWD=root
176

18-
ENV COLLECTOR_LAPSE=1
19-
ENV COLLECTOR_LIFETIME=1800
7+
RUN mkdir -p /go/src/github.com/kpacha/mesos-influxdb-collector
8+
COPY . /go/src/github.com/kpacha/mesos-influxdb-collector
9+
10+
WORKDIR /go/src/github.com/kpacha/mesos-influxdb-collector
11+
RUN make install
12+
13+
ENTRYPOINT ["/go/bin/mesos-influxdb-collector"]
14+
15+
CMD ["-c", "conf.hcl"]

Dockerfile-min

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM busybox:1.24.1
2+
MAINTAINER kpacha
3+
4+
ENV INFLUXDB_USER=root
5+
ENV INFLUXDB_PWD=root
6+
7+
COPY ./mesos-influxdb-collector /mesos-influxdb-collector
8+
COPY ./conf.hcl /conf.hcl
9+
10+
ENTRYPOINT ["/./mesos-influxdb-collector"]
11+
12+
CMD ["-c", "/conf.hcl"]

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
all: deps build test
2+
3+
deps:
4+
go get github.com/hashicorp/hcl
5+
go get github.com/influxdb/influxdb/client
6+
7+
gen:
8+
go fmt ./...
9+
10+
build:
11+
sh -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o mesos-influxdb-collector'
12+
13+
install: all do_install
14+
15+
do_install:
16+
go install
17+
18+
test:
19+
go test -cover ./...
20+
21+
docker:
22+
docker run --rm -it -e "GOPATH=/go" -v "${PWD}:/go/src/github.com/kpacha/mesos-influxdb-collector" -w /go/src/github.com/kpacha/mesos-influxdb-collector golang:1.5.1 make
23+
docker build -f Dockerfile-min -t kpacha/mesos-influxdb-collector:mesos-dns-min .

README.md

Lines changed: 100 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ mesos-influxdb-collector
33

44
Lightweight mesos stats collector for influxdb
55

6-
Since this collector is intended to be deployed as a [marathon](https://mesosphere.github.io/marathon) app, it comes with a *lifetime* param. This defines how long the collector will run until it dies, so marathon will re-launch it, allowing easy allocation optimizations. Check the [marathon/](https://github.com/kpacha/mesos-influxdb-collector/tree/master/marathon) folder for more details on how to launch it.
6+
Since this collector is intended to be deployed as a [marathon](https://mesosphere.github.io/marathon) app, it comes with a *lifetime* param. This defines how long the collector will run until it dies, so marathon will re-launch it, allowing easy allocation optimizations. Check the [fixtures/marathon/](https://github.com/kpacha/mesos-influxdb-collector/tree/master/fixtures/marathon) folder for more details on how to launch it.
7+
8+
# Goals
9+
10+
+ Discover the mesos cluster through `mesos-dns`
11+
+ Collect the mesos leader stats
12+
+ Collect the mesos master stats
13+
+ Collect the mesos slave stats
14+
+ Collect the marathon master stats
15+
+ Collect the chronos task stats (TODO)
716

817
# Installing
918

@@ -19,27 +28,93 @@ Alternatively, if you have Go installed:
1928
$ go get github.com/kpacha/mesos-influxdb-collector
2029
```
2130

22-
# Running
31+
# Integration with `mesos-dns`
32+
33+
The `mesos-influxdb-collector` is able to discover all your mesos nodes (masters and slaves) and the marathon master using the REST API exposed by the [mesos-dns](http://mesosphere.github.io/mesos-dns/) service. Check the next section for details.
34+
35+
# Configuration
2336

2437
The collector use these environmental vars:
2538

26-
+ `INFLUXDB_DB`
27-
+ `INFLUXDB_HOST`
28-
+ `INFLUXDB_PORT`
2939
+ `INFLUXDB_USER`
3040
+ `INFLUXDB_PWD`
31-
+ `MESOS_MASTER_HOST`
32-
+ `MESOS_MASTER_PORT`
33-
+ `MESOS_SLAVE_HOST`
34-
+ `MESOS_SLAVE_PORT`
35-
+ `MARATHON_HOST`
36-
+ `MARATHON_PORT`
37-
+ `COLLECTOR_LAPSE`
38-
+ `COLLECTOR_LIFETIME`
41+
42+
It also requires a config file with the list of nodes to monitor or the details about the `mesos-dns` service among these other params:
43+
44+
+ *Lapse*: time between consecutive collections. Default: 30 seconds
45+
+ *DieAfter*: duration of the running instance. Default: 1 hour
46+
47+
### MesosDNS
48+
49+
Optional. Add it if you have a `mesos-dns` service running in your mesos cluster.
50+
51+
```
52+
mesosDNS {
53+
domain = "mesos" // the domain used by the mesos-dns service
54+
marathon = true // resolve marathon master
55+
host = "master.mesos" // host of the mesos-dns service
56+
port = 8123 // port of the REST API
57+
}
58+
```
59+
60+
### InfluxDB
61+
62+
Required.
63+
64+
```
65+
influxdb {
66+
host = "influxdb.marathon.mesos" // host of the influxdb instance
67+
port = 8086 // port of the REST API
68+
db = "mesos" // name of the database to use
69+
checkLapse = 30 // ping frequency
70+
}
71+
```
72+
73+
### Mesos masters
74+
75+
For manual definition of some (or all) mesos masters, use the `Master` struct:
76+
77+
```
78+
Master {
79+
host = "localhost"
80+
port = 5051
81+
leader = true // optional
82+
}
83+
Master {
84+
host = "localhost"
85+
port = 5052
86+
}
87+
```
88+
89+
### Mesos slaves
90+
91+
For manual definition of some (or all) mesos slave, use the `Slave` struct:
92+
93+
```
94+
Slave {
95+
host = "localhost"
96+
port = 5051
97+
}
98+
```
99+
100+
### Marathon instances
101+
102+
For manual definition of some (or all) marathon instances, use the `Marathon` struct:
103+
104+
```
105+
Marathon {
106+
host = "localhost"
107+
port = 5052
108+
}
109+
```
110+
111+
Check [`config/configuration_test.go`](https://github.com/kpacha/mesos-influxdb-collector/blob/master/config/configuration_test.go) and [`conf.hcl`](https://github.com/kpacha/mesos-influxdb-collector/blob/master/conf.hcl) for examples.
112+
113+
# Running
39114

40115
## Dockerized version
41116

42-
Run the container with the default params (check the Dockerfile and overwrite whatever you need):
117+
Run the container with the default params:
43118

44119
```
45120
$ docker pull --name mesos-influxdb-collector \
@@ -48,77 +123,27 @@ $ docker pull --name mesos-influxdb-collector \
48123
-it --rm kpacha/mesos-influxdb-collector
49124
```
50125

51-
Since the default value for `INFLUXDB_HOST` is `ìnfluxb`, you can link the collector to the influxdb container, dependeing on your environment.
126+
If you need to customize something, copy the `conf.hcl`, make your changes and link it as a volume:
52127

53128
```
54-
$ docker run --name mesos-influxdb-collector \
55-
--link influxdb \
56-
-it --rm kpacha/mesos-influxdb-collector
129+
$ docker pull --name mesos-influxdb-collector \
130+
-v /path/to/my/custom/conf.hcl:/tmp/conf.hcl \
131+
-it --rm kpacha/mesos-influxdb-collector -c /tmp/conf.hcl
57132
```
58133

134+
Tip: if you link your config file to `/go/src/github.com/kpacha/mesos-influxdb-collector/conf.hcl` you don't need to worry about that flag!
135+
59136
## Binary version
60137

61138
```
62139
$ ./mesos-influxdb-collector -h
63140
Usage of ./mesos-influxdb-collector:
64-
-Id string
65-
influxdb database (default "mesos")
66-
-Ih string
67-
influxdb host (default "localhost")
68-
-Ip int
69-
influxdb port (default 8086)
70-
-Mmh string
71-
mesos master host (default "localhost")
72-
-Mmp int
73-
mesos master port (default 5050)
74-
-Msh string
75-
mesos slave host (default "localhost")
76-
-Msp int
77-
mesos slave port (default 5051)
78-
-d int
79-
die after N seconds (default 300)
80-
-l int
81-
sleep time between collections in seconds (default 1)
82-
-mh string
83-
marathon host (default "localhost")
84-
-mp int
85-
marathon port (default 8080)
86-
```
87-
88-
This is the relation between those params and the environmnetal variables listed above.
89-
90-
Flag | EnvVar
91-
---- | ------
92-
`Id` | `INFLUXDB_DB`
93-
`Ih` | `INFLUXDB_HOST`
94-
`Ip` | `INFLUXDB_PORT`
95-
`Mmh` | `MESOS_MASTER_HOST`
96-
`Mmp` | `MESOS_MASTER_PORT`
97-
`Msh` | `MESOS_SLAVE_HOST`
98-
`Msp` | `MESOS_SLAVE_PORT`
99-
`mh` | `MARATHON_HOST`
100-
`mp` | `MARATHON_PORT`
101-
`d` | `COLLECTOR_LAPSE`
102-
`l` | `COLLECTOR_LIFETIME`
141+
-c string
142+
path to the config file (default "conf.hcl")
143+
```
103144

104145
The credentials for the influxdb database are accepted just as env_var (`INFLUXDB_USER` & `INFLUXDB_PWD`)
105146

106-
## Testing environment
107-
108-
In order to do a quick test of the collector, you can use one of the available mesos test environments: [playa-mesos](https://github.com/mesosphere/playa-mesos) & [mesoscope](https://github.com/schibsted/mesoscope). The other components can be deployed with public containers. Replace the `$DOCKER_IP` and `$MESOS_HOST` with the correct values. If you are running the mesoscope env, `MESOS_HOST=$DOCKER_IP`. For the playa-mesos option, `MESOS_HOST=10.141.141.10`.
109-
110-
```
111-
$ docker run --name influxdb -p 8083:8083 -p 8086:8086 \
112-
--expose 8090 --expose 8099 \
113-
-d tutum/influxdb
114-
$ docker run --name grafana -p 3000:3000 \
115-
-e GF_SERVER_ROOT_URL="http://$DOCKER_IP" \
116-
-e GF_SECURITY_ADMIN_PASSWORD=secret \
117-
-d grafana/grafana
118-
$ docker run --name mesos-influxdb-collector \
119-
--link influxdb \
120-
-e MESOS_HOST=$MESOS_HOST \
121-
-it --rm kpacha/mesos-influxdb-collector
122-
```
147+
# Grafana dashboards
123148

124-
The `grafana` folder contains several grafana dashboard definitions. Go to the grafana website (`http://$DOCKER_IP:3000/) and, after configuring the influxdb datasource, import them and start monitoring your mesos cluster.
149+
The `fixtures/grafana` folder contains several grafana dashboard definitions. Go to the grafana website and, after configuring the influxdb datasource, import them and start monitoring your mesos cluster.

collector.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

collector/collector.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ type MultiCollector struct {
1515
Collectors []Collector
1616
}
1717

18-
func NewMultiCollector(collectors []Collector) Collector {
19-
return MultiCollector{collectors}
20-
}
21-
2218
func (mc MultiCollector) Collect() ([]store.Point, error) {
2319
var data []store.Point
2420
for _, c := range mc.Collectors {

collector/factory.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package collector
2+
3+
import (
4+
"fmt"
5+
"github.com/kpacha/mesos-influxdb-collector/config"
6+
"github.com/kpacha/mesos-influxdb-collector/parser/marathon"
7+
"github.com/kpacha/mesos-influxdb-collector/parser/mesos"
8+
"log"
9+
"net/url"
10+
)
11+
12+
func NewCollectorFromConfig(configuration *config.Config) Collector {
13+
var collectors []Collector
14+
15+
for _, master := range configuration.Master {
16+
collectors = append(collectors, NewMesosMasterCollector(master.Host, master.Port, master.Leader))
17+
}
18+
for _, slave := range configuration.Slave {
19+
collectors = append(collectors, NewMesosSlaveCollector(slave.Host, slave.Port))
20+
}
21+
for _, marathonInstance := range configuration.Marathon {
22+
collectors = append(collectors, NewMarathonCollector(marathonInstance.Host, marathonInstance.Port))
23+
}
24+
25+
log.Println("Total collectors created:", len(collectors))
26+
27+
return NewMultiCollector(collectors)
28+
}
29+
30+
func NewMultiCollector(collectors []Collector) Collector {
31+
return MultiCollector{collectors}
32+
}
33+
34+
func NewMesosLeaderCollector(host string, port int) Collector {
35+
return NewMesosMasterCollector(host, port, true)
36+
}
37+
38+
func NewMesosMasterCollector(host string, port int, leader bool) Collector {
39+
u, err := url.Parse(fmt.Sprintf("http://%s:%d/metrics/snapshot", host, port))
40+
if err != nil {
41+
log.Fatal("Error building the mesos master collector:", err)
42+
}
43+
return UrlCollector{Url: u.String(), Parser: mesos.MasterParser{Node: host, Leader: leader}}
44+
}
45+
46+
func NewMesosSlaveCollector(host string, port int) Collector {
47+
u, err := url.Parse(fmt.Sprintf("http://%s:%d/metrics/snapshot", host, port))
48+
if err != nil {
49+
log.Fatal("Error building the mesos slave collector:", err)
50+
}
51+
return UrlCollector{Url: u.String(), Parser: mesos.SlaveParser{Node: host}}
52+
}
53+
54+
func NewMarathonCollector(host string, port int) Collector {
55+
u, err := url.Parse(fmt.Sprintf("http://%s:%d/metrics", host, port))
56+
if err != nil {
57+
log.Fatal("Error building the marathon collector:", err)
58+
}
59+
return UrlCollector{Url: u.String(), Parser: marathon.MarathonParser{Node: host}}
60+
}

0 commit comments

Comments
 (0)