Skip to content

Commit b7d7493

Browse files
committed
add telegraf playground
1 parent c285d4e commit b7d7493

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This repository contains source files to build Docker images used to run interac
99
* [oh-my-zsh](https://rootnroll.com/d/oh-my-zsh/) — An open source, community-driven framework for managing your [zsh](http://www.zsh.org/) configuration.
1010
* [pipenv](https://rootnroll.com/d/pipenv/) — A tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world.
1111
* [poetry](https://rootnroll.com/d/poetry/) — Python dependency management and packaging made easy.
12+
* [telegraf](https://rootnroll.com/d/telegraf/) — A plugin-driven server agent for collecting and reporting metrics.
1213

1314
Base images with pre-installed basic command line tools, configured locales, and beautiful fish shell:
1415
* [`rootnroll/demo-ubuntu:18.04`](https://hub.docker.com/r/rootnroll/demo-ubuntu/) — Ubuntu 18.04

telegraf/Dockerfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#FROM rootnroll/demo-ubuntu:18.04
2+
FROM my-demo-ubuntu
3+
LABEL maintainer "Pavel Sviderski <[email protected]>"
4+
5+
# From https://github.com/influxdata/influxdata-docker/blob/master/telegraf/1.10/Dockerfile
6+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
7+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends iputils-ping snmp procps lm-sensors && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
RUN set -ex && \
11+
for key in \
12+
05CE15085FC09D18E99EFB22684A14CF2582E0C5 ; \
13+
do \
14+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \
15+
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
16+
gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \
17+
done
18+
19+
ENV TELEGRAF_VERSION 1.10.2
20+
RUN wget --no-verbose https://dl.influxdata.com/telegraf/releases/telegraf_${TELEGRAF_VERSION}-1_amd64.deb.asc && \
21+
wget --no-verbose https://dl.influxdata.com/telegraf/releases/telegraf_${TELEGRAF_VERSION}-1_amd64.deb && \
22+
gpg --batch --verify telegraf_${TELEGRAF_VERSION}-1_amd64.deb.asc telegraf_${TELEGRAF_VERSION}-1_amd64.deb && \
23+
dpkg -i telegraf_${TELEGRAF_VERSION}-1_amd64.deb && \
24+
rm -f telegraf_${TELEGRAF_VERSION}-1_amd64.deb* && \
25+
chown -R box:box /etc/telegraf
26+
27+
# From https://github.com/influxdata/influxdata-docker/blob/master/influxdb/1.7/Dockerfile
28+
ENV INFLUXDB_VERSION 1.7.5
29+
RUN wget --no-verbose https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUXDB_VERSION}_amd64.deb.asc && \
30+
wget --no-verbose https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUXDB_VERSION}_amd64.deb && \
31+
gpg --batch --verify influxdb_${INFLUXDB_VERSION}_amd64.deb.asc influxdb_${INFLUXDB_VERSION}_amd64.deb && \
32+
dpkg -i influxdb_${INFLUXDB_VERSION}_amd64.deb && \
33+
rm -f influxdb_${INFLUXDB_VERSION}_amd64.deb*
34+
35+
WORKDIR /home/box
36+
COPY docker-entrypoint.sh /
37+
ENTRYPOINT ["/docker-entrypoint.sh"]
38+
CMD ["/usr/bin/fish", "-l"]

telegraf/README.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!--nologo-->
2+
3+
[Telegraf](https://github.com/influxdata/telegraf) is an agent for collecting metrics and writing them into InfluxDB or other possible outputs.
4+
5+
In this playground, you've got Telegraf and InfluxDB already installed and configured.
6+
7+
## Configuration
8+
9+
The configuration file is located at `/etc/telegraf/telegraf.conf`. It enables several [inputs](https://github.com/influxdata/telegraf/blob/master/README.md#input-plugins) such as `cpu` and `mem` that read metrics about the system’s cpu and memory usage. It also specifies InfluxDB as the desired [output](https://github.com/influxdata/telegraf/blob/master/README.md#output-plugins).
10+
11+
You can view and edit the config using `nano` or `vim`:
12+
```bash
13+
nano /etc/telegraf/telegraf.conf
14+
```
15+
16+
## How to use it
17+
18+
Run a single collection of metrics and print them to stdout:
19+
20+
```
21+
telegraf --test
22+
```
23+
24+
Collect metrics only from `cpu` and `mem` inputs and print them to stdout:
25+
26+
```
27+
telegraf --input-filter cpu:mem --test
28+
```
29+
30+
## Start the Telegraf service
31+
32+
```bash
33+
sudo service telegraf start
34+
```
35+
36+
Once Telegraf is up and running, it will start collecting metrics and writing them to the local InfluxDB every 10 seconds.
37+
38+
You can check Telegraf and InfluxDB logs at `/var/log/telegraf/telegraf.log` and `/var/log/influxdb/influxd.log` respectively.
39+
40+
## Explore metrics in InfluxDB
41+
42+
Enter the interactive InfluxDB shell and connect to the `telegraf` [database](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#database):
43+
44+
```bash
45+
influx -database telegraf
46+
```
47+
48+
Once in the InfluxDB shell, list all [measurements](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#measurement) in the database:
49+
50+
```bash
51+
> SHOW MEASUREMENTS
52+
name: measurements
53+
name
54+
----
55+
cpu
56+
disk
57+
diskio
58+
kernel
59+
mem
60+
processes
61+
swap
62+
system
63+
```
64+
65+
List all [field keys](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#field-key) by measurement:
66+
67+
```bash
68+
> SHOW FIELD KEYS
69+
name: cpu
70+
fieldKey fieldType
71+
-------- ---------
72+
usage_guest float
73+
usage_guest_nice float
74+
usage_idle float
75+
usage_iowait float
76+
usage_irq float
77+
usage_nice float
78+
usage_softirq float
79+
usage_steal float
80+
usage_system float
81+
usage_user float
82+
...
83+
```
84+
85+
Select a data sample in the [field](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#field) `usage_idle` in the measurement `cpu`:
86+
87+
```bash
88+
> SELECT usage_idle FROM cpu WHERE cpu = 'cpu-total' LIMIT 5
89+
name: cpu
90+
time usage_idle
91+
---- ----------
92+
1555419650000000000 99.74840657497393
93+
1555419660000000000 99.83283182882222
94+
1555419670000000000 99.81608426684404
95+
1555419680000000000 99.81602274627767
96+
1555419690000000000 99.71576659421494
97+
```
98+
99+
That’s it! You now have the foundation for using Telegraf to collect metrics and write them to your output of choice.
100+
101+
## What's next?
102+
103+
You can explore the official Telegraf [documentation](https://docs.influxdata.com/telegraf) and check available [input](https://github.com/influxdata/telegraf/blob/master/README.md#input-plugins) and [output](https://github.com/influxdata/telegraf/blob/master/README.md#output-plugins) plugins.
104+
105+
You can also improve this playground or create your own. Please send a PR or open an issue in [github.com/rootnroll/library](https://github.com/rootnroll/library).

telegraf/docker-entrypoint.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Start InfluxDB service in background.
4+
service influxdb start > /dev/null &
5+
6+
# Run a subprocess (not exec) to not kill background processes on CTRL+C
7+
gosu box "$@"

0 commit comments

Comments
 (0)