telegraf + influxdb

This commit is contained in:
2021-05-25 23:43:00 +02:00
parent ddc6c2bb4d
commit 4e7f33338e
11 changed files with 2604 additions and 63 deletions

View File

@@ -0,0 +1,5 @@
influx_admin_user: my-user
influx_admin_pw: my-password
influx_org: my-org
influx_pubport: 28086
influx_bucket: batleth

View File

@@ -11,7 +11,8 @@ RUN git clone $REPOCOBALD /usr/local/src/cobald && \
git clone $REPOTARDIS /usr/local/src/tardis
RUN mkdir /etc/cobald /var/log/cobald && \
useradd -m -d /var/lib/cobald --no-log-init --system cobald
useradd -m -d /var/lib/cobald --no-log-init --system cobald && \
chown cobald:cobald /var/log/cobald
#RUN mkdir /cobald && python3 -m venv /cobald && source /cobald/bin/activate &&\
# pip3 install --upgrade pip && pip3 install cobald
@@ -46,6 +47,9 @@ RUN chmod 755 /usr/local/sbin/docker-entrypoint.sh
ENTRYPOINT /usr/local/sbin/docker-entrypoint.sh
RUN yum -y install iproute &&\
yum clean all && rm -rf /var/cache/yum
USER cobald
CMD "python3 -m cobald.daemon /etc/cobald/config.yaml"

View File

@@ -0,0 +1,540 @@
{
"meta": {
"version": "1",
"type": "dashboard",
"name": "cobald-Template",
"description": "template created from dashboard: cobald"
},
"content": {
"data": {
"type": "dashboard",
"attributes": {
"name": "cobald",
"description": ""
},
"relationships": {
"label": {
"data": []
},
"cell": {
"data": [
{
"type": "cell",
"id": "078ad2e135410000"
},
{
"type": "cell",
"id": "078ba588b6c10000"
},
{
"type": "cell",
"id": "078ba5e53a810000"
},
{
"type": "cell",
"id": "078c36c747010000"
}
]
},
"variable": {
"data": []
}
}
},
"included": [
{
"id": "078ad2e135410000",
"type": "cell",
"attributes": {
"x": 0,
"y": 0,
"w": 4,
"h": 4
},
"relationships": {
"view": {
"data": {
"type": "view",
"id": "078ad2e135410000"
}
}
}
},
{
"id": "078ba588b6c10000",
"type": "cell",
"attributes": {
"x": 0,
"y": 4,
"w": 4,
"h": 4
},
"relationships": {
"view": {
"data": {
"type": "view",
"id": "078ba588b6c10000"
}
}
}
},
{
"id": "078ba5e53a810000",
"type": "cell",
"attributes": {
"x": 4,
"y": 4,
"w": 4,
"h": 4
},
"relationships": {
"view": {
"data": {
"type": "view",
"id": "078ba5e53a810000"
}
}
}
},
{
"id": "078c36c747010000",
"type": "cell",
"attributes": {
"x": 4,
"y": 0,
"w": 4,
"h": 4
},
"relationships": {
"view": {
"data": {
"type": "view",
"id": "078c36c747010000"
}
}
}
},
{
"type": "view",
"id": "078ad2e135410000",
"attributes": {
"name": "Name this Cell",
"properties": {
"shape": "chronograf-v2",
"queries": [
{
"text": "from(bucket: \"batleth\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"tardis_machine_name\"] == \"678162c190d5\")\n |> window(every: 10s)\n |> count()\n |> duplicate(column: \"_stop\", as: \"_time\")\n |> window(every: inf)\n |> yield()",
"editMode": "advanced",
"name": "",
"builderConfig": {
"buckets": [],
"tags": [
{
"key": "_measurement",
"values": [],
"aggregateFunctionType": "filter"
}
],
"functions": [
{
"name": "mean"
}
],
"aggregateWindow": {
"period": "auto",
"fillValues": false
}
}
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "xy",
"legend": {},
"geom": "line",
"colors": [
{
"id": "2566435b-7ee0-4222-8ac0-b7f14ab783d9",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "9263bcff-35a0-4025-bacd-68a1bef54784",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "2f04bd8c-2203-4be6-bc34-c25720d24379",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": 0
}
],
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "_time",
"generateXAxisTicks": [],
"xTotalTicks": 0,
"xTickStart": 0,
"xTickStep": 0,
"yColumn": "_value",
"generateYAxisTicks": [],
"yTotalTicks": 0,
"yTickStart": 0,
"yTickStep": 0,
"shadeBelow": false,
"position": "overlaid",
"timeFormat": "",
"hoverDimension": "auto",
"legendColorizeRows": true,
"legendOpacity": 1,
"legendOrientationThreshold": 100000000
}
}
},
{
"type": "view",
"id": "078ba588b6c10000",
"attributes": {
"name": "states",
"properties": {
"shape": "chronograf-v2",
"queries": [
{
"text": "from(bucket: \"batleth\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r._field == \"state\")\n |> group(columns: [\"_value\"], mode: \"by\")\n |> duplicate(column: \"_value\", as: \"state\")\n |> window(every: 10s)\n |> count(column: \"state\")\n |> rename(columns: {\"_value\": \"_field\", \"state\": \"_value\"})\n |> group(columns: [\"_field\"])\n |> yield()",
"editMode": "advanced",
"name": "",
"builderConfig": {
"buckets": [],
"tags": [
{
"key": "_measurement",
"values": [],
"aggregateFunctionType": "filter"
}
],
"functions": [
{
"name": "mean"
}
],
"aggregateWindow": {
"period": "auto",
"fillValues": false
}
}
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "xy",
"legend": {},
"geom": "line",
"colors": [
{
"id": "9b960932-18d9-4f57-80ba-24998a06613d",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "c1742651-0d5e-4148-b9c0-92beb642417a",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "756fa8cb-9d9c-4e45-9a4f-f2b106b0216a",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": 0
}
],
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "_stop",
"generateXAxisTicks": [],
"xTotalTicks": 0,
"xTickStart": 0,
"xTickStep": 0,
"yColumn": "_value",
"generateYAxisTicks": [],
"yTotalTicks": 0,
"yTickStart": 0,
"yTickStep": 0,
"shadeBelow": false,
"position": "overlaid",
"timeFormat": "",
"hoverDimension": "auto",
"legendColorizeRows": true,
"legendOpacity": 1,
"legendOrientationThreshold": 100000000
}
}
},
{
"type": "view",
"id": "078ba5e53a810000",
"attributes": {
"name": "node fluctuation",
"properties": {
"shape": "chronograf-v2",
"queries": [
{
"text": "f = (r, accumulator) => ({\n _value: accumulator._value + (if r._value == \"AvailableState\" then 1 else if r._value == \"DownState\" then -1 else 0)\n })\n\nfrom(bucket: \"batleth\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r._field == \"state\")\n |> group()\n |> window(every: 10s)\n |> reduce(fn: f, identity: {_value: 0})\n |> duplicate(column: \"_stop\", as: \"_time\")\n |> window(every: inf, timeColumn: \"_time\")\n |> yield()",
"editMode": "advanced",
"name": "",
"builderConfig": {
"buckets": [],
"tags": [
{
"key": "_measurement",
"values": [],
"aggregateFunctionType": "filter"
}
],
"functions": [
{
"name": "mean"
}
],
"aggregateWindow": {
"period": "auto",
"fillValues": false
}
}
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "xy",
"legend": {},
"geom": "line",
"colors": [
{
"id": "9b960932-18d9-4f57-80ba-24998a06613d",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "c1742651-0d5e-4148-b9c0-92beb642417a",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "756fa8cb-9d9c-4e45-9a4f-f2b106b0216a",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": 0
}
],
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "_time",
"generateXAxisTicks": [],
"xTotalTicks": 0,
"xTickStart": 0,
"xTickStep": 0,
"yColumn": "_value",
"generateYAxisTicks": [],
"yTotalTicks": 0,
"yTickStart": 0,
"yTickStep": 0,
"shadeBelow": false,
"position": "overlaid",
"timeFormat": "",
"hoverDimension": "auto",
"legendColorizeRows": true,
"legendOpacity": 1,
"legendOrientationThreshold": 100000000
}
}
},
{
"type": "view",
"id": "078c36c747010000",
"attributes": {
"name": "nodes running",
"properties": {
"shape": "chronograf-v2",
"queries": [
{
"text": "from(bucket: \"batleth\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r._field == \"state\")\n |> group()\n |> window(every: 10s)\n |> reduce(fn: (r, accumulator) => ({\n _value: accumulator._value + (\n if r._value == \"AvailableState\" then 1 \n else if r._value == \"DownState\" then -1 \n else 0)\n }), identity: {_value: 0})\n |> duplicate(column: \"_stop\", as: \"_time\")\n |> window(every: inf) //, timeColumn: \"_time\")\n |> cumulativeSum()\n// |> reduce(fn: (r, accumulator) => ({r with x: r._value * 2}), identity: {x:0})\n// |> map(fn: (r) => ({r with vnew: r._value*2}))\n// |> integral(unit: 10s, timeColumn: \"_stop\")\n// |> window(every: inf) //, timeColumn: \"_stop\")\n |> yield()",
"editMode": "advanced",
"name": "",
"builderConfig": {
"buckets": [],
"tags": [
{
"key": "_measurement",
"values": [],
"aggregateFunctionType": "filter"
}
],
"functions": [
{
"name": "mean"
}
],
"aggregateWindow": {
"period": "auto",
"fillValues": false
}
}
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "xy",
"legend": {},
"geom": "line",
"colors": [
{
"id": "9b960932-18d9-4f57-80ba-24998a06613d",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "c1742651-0d5e-4148-b9c0-92beb642417a",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": 0
},
{
"id": "756fa8cb-9d9c-4e45-9a4f-f2b106b0216a",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": 0
}
],
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "_time",
"generateXAxisTicks": [],
"xTotalTicks": 0,
"xTickStart": 0,
"xTickStep": 0,
"yColumn": "_value",
"generateYAxisTicks": [],
"yTotalTicks": 0,
"yTickStart": 0,
"yTickStep": 0,
"shadeBelow": false,
"position": "overlaid",
"timeFormat": "",
"hoverDimension": "auto",
"legendColorizeRows": true,
"legendOpacity": 1,
"legendOrientationThreshold": 100000000
}
}
}
]
},
"labels": []
}

View File

@@ -0,0 +1,6 @@
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

View File

@@ -0,0 +1,8 @@
FROM centos:7
COPY influxdb.repo /etc/yum.repos.d/influxdb.repo
RUN yum -y install telegraf &&\
yum clean all && rm -rf /var/cache/yum
CMD telegraf

View File

@@ -0,0 +1,3 @@
ANSIBLE_LIBRARY=. ansible -m influx_bucket -a "base='http://192.168.122.140:28086' org='my-org' auth_token='87-fEnSlQldFi1T_CLHsrHxH-T9VKey-qzUbVH6tmR2QzL4oZzbUPwzS1wzOoIkyfmyGbRv75yLjYfztxziivw==' name='bucky' description='test 123'" localhost -vvv
ANSIBLE_LIBRARY=. ansible -m influx_token -a "base='http://192.168.122.140:28086' org='my-org' auth_token='87-fEnSlQldFi1T_CLHsrHxH-T9VKey-qzUbVH6tmR2QzL4oZzbUPwzS1wzOoIkyfmyGbRv75yLjYfztxziivw==' key='foo' description='test 123' permissions=\"{{'[{\\\"action\\\": \\\"write\\\",\\\"resource\\\": {\\\"type\\\": \\\"buckets\\\"} }]'|from_json}}\"" localhost -vvv
ANSIBLE_LIBRARY=. ansible -m influx_dashboard -create -a "base='http://192.168.122.140:28086' org='my-org' token='2Mji-PvTzgn2oie5p36pJ-vxqWCnxczMWGrnYz2nUHj6Q6XvdIGiLPmK4DjX16KGhOjxQ5dWymDusE8qJrhFFg==' data='{{lookup(\"file\", \"../files/influxdb-dashboard-cobald.json\")}}'" localhost -vvv

View File

@@ -1,58 +0,0 @@
- yum:
name: git
state: present
- git:
repo: https://github.com/thoto/cobald
dest: "~{{unpriv_user}}/cobald-src"
version: bugfix/mixed_construction_methods
become: yes
become_user: "{{unpriv_user}}"
register: cobald_git_pull
- git:
repo: https://github.com/MatterMiners/tardis
dest: "~{{unpriv_user}}/tardis-src"
version: master
become: yes
become_user: "{{unpriv_user}}"
register: tardis_git_pull
- name: "get unpriv_user {{unpriv_user}} uid and gid"
getent:
database: passwd
key: "{{unpriv_user}}"
- name: run pip install
docker_container:
image: cobald
name: "cobald-src-{{item.name}}-install"
volumes:
- "~{{unpriv_user}}/{{item.name}}-src:/usr/local/src/{{item.name}}:rw"
state: started
detach: False
cleanup: True
user: "{{getent_passwd[unpriv_user][1]}}:{{getent_passwd[unpriv_user][2]}}"
entrypoint: ""
command: |
bash -c 'HOME=/tmp pip3 install --editable /usr/local/src/{{item.name}}'
with_items:
- name: cobald
run: "{{cobald_git_pull.changed}}"
- name: tardis
run: "{{tardis_git_pull.changed}}"
when: item.run
- docker_container:
name: cobald-dev
image: cobald
volumes:
- "~{{unpriv_user}}/cobald:/etc/cobald"
- "~{{unpriv_user}}/cobald/modules:/usr/local/src/cobaldmodules"
- "~{{unpriv_user}}/cobald-src:/usr/local/src/cobald:ro"
- "~{{unpriv_user}}/tardis-src:/usr/local/src/tardis:ro"
state: started
detach: True
cleanup: True
interactive: True
command: /bin/bash

View File

@@ -0,0 +1,79 @@
#- file:
# path: "/container/volumes/influxdb-backup/"
# state: directory
# owner: "{{unpriv_user}}"
# group: docker
#- copy:
# src: influxdb-dashboard-cobald.json
# dest: /container/volumes/influxdb-backup/dash-cobald.json
# owner: "{{unpriv_user}}"
# group: docker
- docker_container:
name: ed-influxdb-2 # -2 FIXME
image: influxdb
hostname: "{{influx_hostname}}"
domainname: "{{influx_domainname}}"
networks:
- name: "{{ docker_network }}"
published_ports:
- "{{influx_pubport}}:8086"
volumes:
- "ed-influxdb-data-2:/var/lib/influxdb2" # -2 FIXME
- "/container/volumes/influxdb-backup/:/backup"
env:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: "{{influx_admin_user}}"
DOCKER_INFLUXDB_INIT_PASSWORD: "{{influx_admin_pw}}"
DOCKER_INFLUXDB_INIT_ORG: "{{influx_org}}"
DOCKER_INFLUXDB_INIT_BUCKET: my-bucket
state: started
detach: True
cleanup: True
networks_cli_compatible: True
- add_host:
name: ed-influxdb-2
ansible_connection: docker
ansible_docker_extra_args: "-H=ssh://ed-c7-1.virt.magni.thoto.net" # FIXME
changed_when: False
- wait_for: # FIXME: does not work right -> fetch token fails
port: "{{influx_pubport}}"
- name: "fetch auth token"
raw: influx auth list --user my-user --hide-headers --json
register: influx_token_fetch
changed_when: False
delegate_to: ed-influxdb-2
- set_fact:
influx_admin_token:
"{{(influx_token_fetch.stdout | from_json | first).token}}"
- influx_bucket:
base: "http://localhost:{{influx_pubport}}"
org: "my-org"
auth_token: "{{influx_admin_token}}"
name: "{{influx_bucket}}"
- name: "create dashboard"
influx_dashboard:
base: "http://localhost:{{influx_pubport}}"
org: "my-org"
auth_token: "{{influx_admin_token}}"
data: "{{lookup('file', 'influxdb-dashboard-cobald.json')}}"
- influx_token:
base: "http://localhost:{{influx_pubport}}"
org: "my-org"
auth_token: "{{influx_admin_token}}"
description: cobald tardis telegraf monitoring plugin
key: telegraf_cobaldtardis
permissions:
- action: write
resource:
type: buckets
name: "{{influx_bucket}}"
register: influx_telegraf_token

View File

@@ -38,16 +38,79 @@
group: docker
when: False
- set_fact:
docker_network: slurm
- docker_network:
name: "{{docker_network}}"
state: present
# docker run -v $(pwd)/cobald-config-host:/etc/cobald -v $(pwd)/cobald:/cobald --rm -it cobald bash
- yum:
name: git
state: present
- git:
repo: https://github.com/thoto/cobald
dest: "~{{unpriv_user}}/cobald-src"
version: bugfix/mixed_construction_methods
become: yes
become_user: "{{unpriv_user}}"
register: cobald_git_pull
- git:
repo: https://github.com/MatterMiners/tardis
dest: "~{{unpriv_user}}/tardis-src"
version: master
become: yes
become_user: "{{unpriv_user}}"
register: tardis_git_pull
- name: "get unpriv_user {{unpriv_user}} uid and gid"
getent:
database: passwd
key: "{{unpriv_user}}"
- import_tasks: telegraf.yml
vars:
docker_network: cobald
- name: run pip install
docker_container:
image: cobald
name: "cobald-src-{{item.name}}-install"
volumes:
- "~{{unpriv_user}}/{{item.name}}-src:/usr/local/src/{{item.name}}:rw"
state: started
detach: False
cleanup: True
user: "{{getent_passwd[unpriv_user][1]}}:{{getent_passwd[unpriv_user][2]}}"
entrypoint: ""
command: |
bash -c 'HOME=/tmp pip3 install --editable /usr/local/src/{{item.name}}'
with_items:
- name: cobald
run: "{{cobald_git_pull.changed}}"
- name: tardis
run: "{{tardis_git_pull.changed}}"
when: item.run
- docker_container:
name: cobald
image: cobald
hostname: cobald
domainname: cobald.local
volumes:
- /container/volumes/cobald:/etc/cobald:ro
- "~{{unpriv_user}}/cobald:/etc/cobald"
# - /container/volumes/cobald:/etc/cobald:ro
- "~{{unpriv_user}}/cobald/modules:/usr/local/src/cobaldmodules"
- "~{{unpriv_user}}/cobald-src:/usr/local/src/cobald:ro"
- "~{{unpriv_user}}/tardis-src:/usr/local/src/tardis:ro"
networks:
- name: "{{docker_network}}"
state: started
detach: True
cleanup: True
when: False
- include_tasks: dev.yml
interactive: True
command: /bin/bash

View File

@@ -0,0 +1,62 @@
- file:
path: "/container/{{item}}/telegraf/"
state: directory
owner: "{{unpriv_user}}"
group: docker
loop:
- docker-images
- volumes
- copy:
src: telegraf.Dockerfile
dest: /container/docker-images/telegraf/Dockerfile
owner: "{{unpriv_user}}"
group: docker
register: cobald_cp_telegraf_dockerfile
- copy: # telegraf is found in influxdb repo
src: influxdb.repo
dest: /container/docker-images/telegraf/influxdb.repo
owner: "{{unpriv_user}}"
group: docker
- docker_image:
name: "ed-telegraf"
build:
pull: False
path: "/container/docker-images/telegraf/"
source: build
force_source: "{{cobald_cp_telegraf_dockerfile.changed}}"
- block:
- import_tasks: influxdb.yml
tags: influxdb
- template:
src: telegraf.conf.j2
dest: /container/volumes/telegraf/telegraf.conf
owner: "{{unpriv_user}}"
group: docker
vars:
# influx_url: "http://{{influx_hostname}}.{{influx_domainname}}:8086"
influx_url: "http://{{influx_hostname}}:8086"
influx_token: "{{influx_telegraf_token.token}}"
vars:
influx_hostname: "ed-influxdb"
influx_domainname: "cobald.local"
influx_bucket: batleth
- docker_container:
name: ed-telegraf
image: ed-telegraf
hostname: telegraf
domainname: cobald.local
networks:
- name: "{{docker_network | default('bridge') }}"
volumes:
- "/container/volumes/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro"
state: started
detach: True
# cleanup: True
networks_cli_compatible: True

File diff suppressed because it is too large Load Diff