Added monitoring support

This commit is contained in:
2024-10-03 23:03:41 +02:00
parent 6c1d7f59b3
commit 325c105fe3
24 changed files with 10306 additions and 1 deletions
@@ -39,3 +39,4 @@ jobs:
sectool exec ansible-playbook -u $ANSIBLE_USER playbook_nextcloud.yml
sectool exec ansible-playbook -u $ANSIBLE_USER playbook_wordpress.yml
sectool exec ansible-playbook -u $ANSIBLE_USER playbook_m3uproxy.yml
sectool exec ansible-playbook -u $ANSIBLE_USER playbook_monitoring.yml
+3
View File
@@ -24,3 +24,6 @@ contabo01.a13labs.pt
[iac]
contabo01.a13labs.pt
[monitoring]
contabo01.a13labs.pt
+33
View File
@@ -0,0 +1,33 @@
---
- name: Monitoring Playbook (K8s)
hosts: monitoring
gather_facts: true
# Specific tasks for this playbook
tasks:
- name: Set required facts
ansible.builtin.set_fact:
monitoring_home: "/var/lib/monitoring"
influxdb_home: "/var/lib/monitoring/influxdb.data"
kapacitor_home: "/var/lib/monitoring/kapacitor.data"
cronograf_home: "{{ persistent_data | default('/var/lib') }}/chronograf.data"
monitoring_user_id: 1000
monitoring_group_id: 1000
tags: always
- name: Create required monitoring data folder
become: true
ansible.builtin.file:
state: directory
path: "{{ item }}"
mode: "0750"
owner: "{{ monitoring_user_id }}"
group: "{{ monitoring_group_id }}"
with_items:
- "{{ monitoring_home }}"
- "{{ influxdb_home }}"
- "{{ kapacitor_home }}"
- "{{ cronograf_home }}"
tags:
- tasks
- tasks::folders
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
POD_NAME=$(kubectl get pods -n monitoring -l app=chronograf -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward --address 127.0.0.1 --request-timeout=0 -n monitoring $POD_NAME 8888:8888 1>/dev/null 2>&1 &
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
POD_NAME=$(kubectl get pods -n m3uproxy -l app=proxy-pt -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward --address 127.0.0.1 --request-timeout=0 -n m3uproxy $POD_NAME 3128:3128 1>/dev/null 2>&1 &
+165
View File
@@ -0,0 +1,165 @@
locals {
dashboards = { for file in fileset("./resources/chronograf/dashboards", "*.dashboard") : file => file("./resources/chronograf/dashboards/${file}") }
}
resource "kubernetes_cluster_role" "chronograf" {
metadata {
name = "chronograf-role"
}
rule {
api_groups = [""]
resources = ["configmaps", "secrets"]
verbs = ["get", "watch", "list"]
}
}
resource "kubernetes_cluster_role_binding" "chronograf" {
metadata {
name = "chronograf-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.chronograf.metadata.0.name
}
subject {
kind = "ServiceAccount"
name = kubernetes_service_account.chronograf.metadata.0.name
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
}
resource "kubernetes_service_account" "chronograf" {
metadata {
name = "chronograf-sa"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
automount_service_account_token = false
}
resource "kubernetes_config_map" "chronograf" {
metadata {
name = "chronograf-resources"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
data = merge({
"default.org" = file("./resources/chronograf/default.org")
"internal.src" = file("./resources/chronograf/internal.src")
"internal.kap" = file("./resources/chronograf/internal.kap")
}, local.dashboards)
}
resource "kubernetes_deployment" "chronograf" {
depends_on = [
kubernetes_stateful_set.influxdb
]
metadata {
name = "chronograf"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
selector {
match_labels = {
app = "chronograf"
}
}
strategy {
type = "Recreate"
}
template {
metadata {
labels = {
app = "chronograf"
}
}
spec {
service_account_name = kubernetes_service_account.chronograf.metadata.0.name
automount_service_account_token = true
container {
name = "chronograf"
image = "chronograf:${local.chronograf_version}"
image_pull_policy = "IfNotPresent"
resources {
requests = {
memory = "100Mi"
}
}
liveness_probe {
tcp_socket {
port = "http"
}
initial_delay_seconds = 10
timeout_seconds = 5
period_seconds = 10
failure_threshold = 6
success_threshold = 1
}
readiness_probe {
tcp_socket {
port = "http"
}
initial_delay_seconds = 10
timeout_seconds = 5
period_seconds = 10
failure_threshold = 6
success_threshold = 1
}
security_context {
run_as_user = 1000
run_as_group = 1000
allow_privilege_escalation = false
}
env {
name = "RESOURCES_PATH"
value = "/usr/share/chronograf/resources"
}
port {
container_port = 8888
name = "http"
}
volume_mount {
mount_path = "/var/lib/chronograf"
name = "persistent-storage"
}
volume_mount {
mount_path = "/usr/share/chronograf/resources"
name = "config"
}
}
volume {
name = "persistent-storage"
host_path {
path = "/mnt/microk8s_persistent/chronograf.data"
}
}
volume {
name = "config"
config_map {
name = kubernetes_config_map.chronograf.metadata.0.name
}
}
}
}
}
lifecycle {
replace_triggered_by = [
kubernetes_config_map.chronograf
]
}
}
+7 -1
View File
@@ -16,8 +16,14 @@ locals {
nextcloud_sql_backup_cron_schedule = "40 2 * * *"
nextcloud_files_backup_cron_schedule = "50 2 * * *"
# monitoring
influxdb_version = "1.8-alpine"
kapacitor_version = "1.6-alpine"
fluent_bit_version = "3.1"
telegraf_version = "1.32-alpine"
chronograf_version = "1.9-alpine"
# tvheadend
# m3uproxy
m3uproxy_version = "latest"
wireguard_version = "latest"
m3uproxy_fqdn = "tv.alexpires.me"
+150
View File
@@ -0,0 +1,150 @@
resource "kubernetes_cluster_role" "fluent_bit" {
metadata {
name = "fluent-bit-role"
}
rule {
api_groups = [""]
resources = ["pods"]
verbs = ["get", "use"]
}
}
resource "kubernetes_cluster_role_binding" "fluent_bit" {
metadata {
name = "fluent-bit-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.fluent_bit.metadata.0.name
}
subject {
kind = "ServiceAccount"
name = kubernetes_service_account_v1.fluent_bit.metadata.0.name
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
}
resource "kubernetes_service_account_v1" "fluent_bit" {
metadata {
name = "fluent-bit-sa"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
automount_service_account_token = false
}
resource "kubernetes_config_map" "fluent_bit" {
metadata {
name = "fluent-bit"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
data = {
"fluent-bit.conf" = file("./resources/fluent-bit/fluent-bit.conf")
"parsers.conf" = file("./resources/fluent-bit/parsers.conf")
}
}
resource "kubernetes_daemonset" "fluent_bit" {
depends_on = [
kubernetes_stateful_set.influxdb
]
metadata {
name = "fluent-bit"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
selector {
match_labels = {
app = "fluent-bit"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
labels = {
app = "fluent-bit"
}
}
spec {
service_account_name = kubernetes_service_account_v1.fluent_bit.metadata.0.name
automount_service_account_token = true
container {
name = "fluent-bit"
image = "fluent/fluent-bit:${local.fluent_bit_version}"
image_pull_policy = "IfNotPresent"
resources {
requests = {
memory = "100Mi"
}
}
volume_mount {
name = "varlog"
mount_path = "/var/log"
}
volume_mount {
name = "varlibdockercontainers"
mount_path = "/var/lib/docker/containers"
read_only = true
}
volume_mount {
name = "config"
mount_path = "/fluent-bit/etc/fluent-bit.conf"
sub_path = "fluent-bit.conf"
}
volume_mount {
name = "config"
mount_path = "/fluent-bit/etc/parsers.conf"
sub_path = "parsers.conf"
}
volume_mount {
name = "geoip"
mount_path = "/fluent-bit/etc/GeoLite2-City.mmdb"
read_only = true
}
}
volume {
name = "varlog"
host_path {
path = "/var/log"
}
}
volume {
name = "varlibdockercontainers"
host_path {
path = "/var/lib/docker/containers"
}
}
volume {
name = "config"
config_map {
name = kubernetes_config_map.fluent_bit.metadata.0.name
}
}
volume {
name = "geoip"
host_path {
path = "/var/lib/GeoIP/GeoLite2-City.mmdb"
}
}
}
}
}
lifecycle {
replace_triggered_by = [
kubernetes_config_map.fluent_bit
]
}
}
+149
View File
@@ -0,0 +1,149 @@
resource "kubernetes_service_account" "influxdb_service_account" {
metadata {
name = "influxdb-sa"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
automount_service_account_token = false
}
resource "kubernetes_config_map" "influxdb_init" {
metadata {
name = "influxdb-init"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
data = {
"init.iql" = file("./resources/influxdb/init.iql")
}
}
resource "kubernetes_service" "influxdb" {
metadata {
name = "influxdb"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
port {
port = 8086
name = "api"
target_port = "api"
}
port {
port = 8088
name = "rpc"
target_port = "rpc"
}
selector = {
app = "influxdb"
}
cluster_ip = "None"
}
}
resource "kubernetes_stateful_set" "influxdb" {
metadata {
name = "influxdb"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
selector {
match_labels = {
app = "influxdb"
}
}
replicas = 1
service_name = "influxdb"
template {
metadata {
labels = {
app = "influxdb"
}
}
spec {
service_account_name = kubernetes_service_account.influxdb_service_account.metadata.0.name
security_context {
fs_group = 1000
}
container {
name = "influxdb"
image = "influxdb:${local.influxdb_version}"
image_pull_policy = "IfNotPresent"
resources {
requests = {
memory = "100Mi"
}
}
port {
name = "api"
container_port = "8086"
}
port {
name = "rpc"
container_port = "8088"
}
liveness_probe {
http_get {
path = "/ping"
port = "api"
scheme = "HTTP"
}
initial_delay_seconds = 30
timeout_seconds = 5
}
readiness_probe {
http_get {
path = "/ping"
port = "api"
scheme = "HTTP"
}
initial_delay_seconds = 30
timeout_seconds = 5
}
security_context {
run_as_user = 1000
run_as_group = 1000
allow_privilege_escalation = false
}
volume_mount {
name = "persistent-storage"
mount_path = "/var/lib/influxdb"
}
volume_mount {
name = "init-db"
mount_path = "/docker-entrypoint-initdb.d"
}
}
volume {
name = "persistent-storage"
host_path {
path = "/var/lib/monitoring/influxdb.data"
}
}
volume {
name = "init-db"
config_map {
name = kubernetes_config_map.influxdb_init.metadata.0.name
}
}
}
}
}
lifecycle {
replace_triggered_by = [
kubernetes_config_map.influxdb_init
]
}
}
+154
View File
@@ -0,0 +1,154 @@
resource "kubernetes_cluster_role" "kapacitor" {
metadata {
name = "kapacitor-role"
}
rule {
api_groups = [""]
resources = ["configmaps", "secrets"]
verbs = ["get", "watch", "list"]
}
}
resource "kubernetes_cluster_role_binding" "kapacitor" {
metadata {
name = "kapacitor-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.kapacitor.metadata.0.name
}
subject {
kind = "ServiceAccount"
name = kubernetes_service_account.kapacitor.metadata.0.name
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
}
resource "kubernetes_service_account" "kapacitor" {
metadata {
name = "kapacitor-sa"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
automount_service_account_token = false
}
resource "kubernetes_service" "kapacitor" {
metadata {
name = "kapacitor"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
port {
port = 9092
name = "api"
target_port = "api"
}
selector = {
app = "kapacitor"
}
cluster_ip = "None"
}
}
resource "kubernetes_deployment" "kapacitor" {
depends_on = [
kubernetes_stateful_set.influxdb
]
metadata {
name = "kapacitor"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
selector {
match_labels = {
app = "kapacitor"
}
}
strategy {
type = "Recreate"
}
template {
metadata {
labels = {
app = "kapacitor"
}
}
spec {
service_account_name = kubernetes_service_account.kapacitor.metadata.0.name
automount_service_account_token = false
container {
name = "kapacitor"
image = "kapacitor:${local.kapacitor_version}"
image_pull_policy = "IfNotPresent"
resources {
requests = {
memory = "100Mi"
}
}
liveness_probe {
tcp_socket {
port = "api"
}
initial_delay_seconds = 10
timeout_seconds = 5
period_seconds = 10
failure_threshold = 6
success_threshold = 1
}
readiness_probe {
tcp_socket {
port = "api"
}
initial_delay_seconds = 10
timeout_seconds = 5
period_seconds = 10
failure_threshold = 6
success_threshold = 1
}
security_context {
run_as_user = 1000
run_as_group = 1000
allow_privilege_escalation = false
}
env {
name = "KAPACITOR_HOSTNAME"
value = "kapacitor"
}
env {
name = "KAPACITOR_INFLUXDB_0_URLS_0"
value = "http://influxdb:8086/"
}
port {
container_port = 9092
name = "api"
}
volume_mount {
mount_path = "/var/lib/kapacitor"
name = "persistent-storage"
}
}
volume {
name = "persistent-storage"
host_path {
path = "/var/lib/monitoring/kapacitor.data"
}
}
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
resource "kubernetes_namespace" "monitoring" {
metadata {
annotations = {
name = "monitoring"
}
labels = {
name = "monitoring"
}
name = "monitoring"
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,894 @@
{
"meta": {
"chronografVersion": "1.10.1",
"sources": {
"5000": {
"name": "internal",
"link": "/chronograf/v1/sources/5000"
}
}
},
"dashboard": {
"id": "5",
"cells": [
{
"i": "0b416a7f-bb94-48e7-9877-bb95a896fd6c",
"x": 9,
"y": 0,
"w": 3,
"h": 1,
"name": "Total Errors (packets) - :host: - :interface:",
"queries": [
{
"query": "SELECT (last(\"err_in\") - first(\"err_in\")) + (last(\"err_out\") - first(\"err_out\")) AS \"Total Errors\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT (last(\"err_in\") - first(\"err_in\")) + (last(\"err_out\") - first(\"err_out\")) AS \"Total Errors\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "bits",
"prefix": "",
"suffix": "",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "single-stat",
"colors": [
{
"id": "base",
"type": "text",
"hex": "#00C9FF",
"name": "laser",
"value": "-1000000000000000000"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 0
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/0b416a7f-bb94-48e7-9877-bb95a896fd6c"
}
},
{
"i": "b9acc5e0-7cb8-4901-8602-b5f9342ea386",
"x": 6,
"y": 0,
"w": 3,
"h": 1,
"name": "Total Discards (packets) - :host: - :interface:",
"queries": [
{
"query": "SELECT (last(\"drop_in\") - first(\"drop_in\")) + (last(\"drop_out\") - first(\"drop_out\")) AS \"Total Discards\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT (last(\"drop_in\") - first(\"drop_in\")) + (last(\"drop_out\") - first(\"drop_out\")) AS \"Total Discards\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "bits",
"prefix": "",
"suffix": "",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "single-stat",
"colors": [
{
"id": "base",
"type": "text",
"hex": "#00C9FF",
"name": "laser",
"value": "-1000000000000000000"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 0
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/b9acc5e0-7cb8-4901-8602-b5f9342ea386"
}
},
{
"i": "221e4ac0-af96-4535-baf1-64112fe65c62",
"x": 3,
"y": 0,
"w": 3,
"h": 1,
"name": "Total Traffic (packets) - :host: - :interface:",
"queries": [
{
"query": "SELECT ((last(\"packets_recv\") - first(\"packets_recv\")) + (last(\"packets_sent\") - first(\"packets_sent\"))) / 1000 AS \"Total Packets\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT ((last(\"packets_recv\") - first(\"packets_recv\")) + (last(\"packets_sent\") - first(\"packets_sent\"))) / 1000 AS \"Total Packets\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "bits",
"prefix": "",
"suffix": " K",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "single-stat",
"colors": [
{
"id": "base",
"type": "text",
"hex": "#00C9FF",
"name": "laser",
"value": "-1000000000000000000"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 0
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/221e4ac0-af96-4535-baf1-64112fe65c62"
}
},
{
"i": "bf42bf7c-3c5b-46e0-a419-b320c3d95faa",
"x": 0,
"y": 0,
"w": 3,
"h": 1,
"name": "Total Traffic (bytes) - :host: - :interface:",
"queries": [
{
"query": "SELECT ((last(\"bytes_recv\") - first(\"bytes_recv\")) + (last(\"bytes_sent\") - first(\"bytes_sent\"))) / 1000000 AS \"Total Bytes\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT ((last(\"bytes_recv\") - first(\"bytes_recv\")) + (last(\"bytes_sent\") - first(\"bytes_sent\"))) / 1000000 AS \"Total Bytes\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "bits",
"prefix": "",
"suffix": " MB",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "single-stat",
"colors": [
{
"id": "base",
"type": "text",
"hex": "#00C9FF",
"name": "laser",
"value": "-1000000000000000000"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 2
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/bf42bf7c-3c5b-46e0-a419-b320c3d95faa"
}
},
{
"i": "e9a055f5-7a22-4fc8-8848-9faea022fa93",
"x": 0,
"y": 7,
"w": 12,
"h": 3,
"name": "Dropped Packets - :host: - :interface:",
"queries": [
{
"query": "SELECT non_negative_difference(last(\"drop_in\")) AS \"Ingress Discards\", (non_negative_difference(last(\"err_in\"))) AS \"Ingress Errors\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_difference(last(\"drop_in\")) AS \"Ingress Discards\", (non_negative_difference(last(\"err_in\"))) AS \"Ingress Errors\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
},
{
"query": "SELECT non_negative_derivative(last(\"drop_out\"),1s) * -1 AS \"Egress Dropped Packet Rate\", (non_negative_derivative(last(\"err_out\"),1s)) * -1 AS \"Egress Errored Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_derivative(last(\"drop_out\"),1s) * -1 AS \"Egress Dropped Packet Rate\", (non_negative_derivative(last(\"err_out\"),1s)) * -1 AS \"Egress Errored Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "packets",
"prefix": "",
"suffix": "/s",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "line-stacked",
"colors": [
{
"id": "d0d6afdf-e43a-4f84-bfb8-bce962799cdc",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "51af7221-74a0-450e-8be0-91b40cffbdb7",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "c125b7e0-a2a2-42bf-9cc6-228eb6ced525",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": "0"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 2
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/e9a055f5-7a22-4fc8-8848-9faea022fa93"
}
},
{
"i": "63895134-f930-49ae-b1ac-3294142ef142",
"x": 0,
"y": 4,
"w": 12,
"h": 3,
"name": "Traffic Rate (pkts/s) - :host: - :interface:",
"queries": [
{
"query": "SELECT non_negative_derivative(last(\"packets_recv\"),1s) AS \"Ingress Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_derivative(last(\"packets_recv\"),1s) AS \"Ingress Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
},
{
"query": "SELECT non_negative_derivative(last(\"packets_sent\"),1s) * -1 AS \"Egress Unicast Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_derivative(last(\"packets_sent\"),1s) * -1 AS \"Egress Unicast Packet Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "packets",
"prefix": "",
"suffix": "/s",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "line",
"colors": [
{
"id": "d0d6afdf-e43a-4f84-bfb8-bce962799cdc",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "51af7221-74a0-450e-8be0-91b40cffbdb7",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "c125b7e0-a2a2-42bf-9cc6-228eb6ced525",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": "0"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 2
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/63895134-f930-49ae-b1ac-3294142ef142"
}
},
{
"i": "a47e7219-bc4f-47c5-883f-11a80a24ba6a",
"x": 0,
"y": 1,
"w": 12,
"h": 3,
"name": "Traffic Rate (bits/s) - :host: - :interface:",
"queries": [
{
"query": "SELECT non_negative_derivative(last(\"bytes_recv\"),1s) * 8 AS \"Ingress Bit Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_derivative(last(\"bytes_recv\"),1s) * 8 AS \"Ingress Bit Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
},
{
"query": "SELECT non_negative_derivative(last(\"bytes_sent\"),1s) * -8 AS \"Egress Traffic Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"queryConfig": {
"database": "",
"measurement": "",
"retentionPolicy": "",
"fields": [],
"tags": {},
"groupBy": {
"time": "",
"tags": []
},
"areTagsAccepted": false,
"rawText": "SELECT non_negative_derivative(last(\"bytes_sent\"),1s) * -8 AS \"Egress Traffic Rate\" FROM \"telegraf\".\"autogen\".\"net\" WHERE time > :dashboardTime: AND \"host\"=':host:' AND \"interface\"=':interface:' GROUP BY time(:interval:) FILL(null)",
"range": null,
"shifts": null
},
"source": "",
"type": "influxql"
}
],
"axes": {
"x": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
},
"y": {
"bounds": [
"",
""
],
"label": "bandwidth",
"prefix": "",
"suffix": "b/s",
"base": "2",
"scale": "linear"
},
"y2": {
"bounds": [
"",
""
],
"label": "",
"prefix": "",
"suffix": "",
"base": "10",
"scale": "linear"
}
},
"type": "line",
"colors": [
{
"id": "d0d6afdf-e43a-4f84-bfb8-bce962799cdc",
"type": "scale",
"hex": "#31C0F6",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "51af7221-74a0-450e-8be0-91b40cffbdb7",
"type": "scale",
"hex": "#A500A5",
"name": "Nineteen Eighty Four",
"value": "0"
},
{
"id": "c125b7e0-a2a2-42bf-9cc6-228eb6ced525",
"type": "scale",
"hex": "#FF7E27",
"name": "Nineteen Eighty Four",
"value": "0"
}
],
"legend": {},
"tableOptions": {
"verticalTimeAxis": true,
"sortBy": {
"internalName": "time",
"displayName": "",
"visible": true
},
"wrapping": "truncate",
"fixFirstColumn": true
},
"fieldOptions": [
{
"internalName": "time",
"displayName": "",
"visible": true
}
],
"timeFormat": "MM/DD/YYYY HH:mm:ss",
"decimalPlaces": {
"isEnforced": true,
"digits": 2
},
"note": "",
"noteVisibility": "default",
"links": {
"self": "/chronograf/v1/dashboards/5/cells/a47e7219-bc4f-47c5-883f-11a80a24ba6a"
}
}
],
"templates": [
{
"tempVar": ":host:",
"values": [
{
"value": "k8s",
"type": "influxql",
"selected": true
}
],
"id": "2f052195-a0cb-414c-9a4f-ee542a362ae4",
"type": "influxql",
"label": "",
"query": {
"influxql": "SHOW TAG VALUES ON \"telegraf\" FROM \"net\" WITH KEY=\"host\"",
"measurement": "",
"tagKey": "",
"fieldKey": ""
},
"sourceID": "5000",
"links": {
"self": "/chronograf/v1/dashboards/5/templates/2f052195-a0cb-414c-9a4f-ee542a362ae4"
}
},
{
"tempVar": ":interface:",
"values": [
{
"value": "eth0",
"type": "influxql",
"selected": true
}
],
"id": "a56477ab-cfa7-46a5-b4b6-49ec464169a7",
"type": "influxql",
"label": "",
"query": {
"influxql": "SHOW TAG VALUES ON \"telegraf\" FROM \"net\" WITH KEY=\"interface\" WHERE \"host\"=':host:'",
"measurement": "",
"tagKey": "",
"fieldKey": ""
},
"sourceID": "5000",
"links": {
"self": "/chronograf/v1/dashboards/5/templates/a56477ab-cfa7-46a5-b4b6-49ec464169a7"
}
}
],
"name": "Net: Interface Performance",
"organization": "default",
"links": {
"self": "/chronograf/v1/dashboards/5",
"cells": "/chronograf/v1/dashboards/5/cells",
"templates": "/chronograf/v1/dashboards/5/templates"
}
}
}
@@ -0,0 +1,5 @@
{
"id": "default",
"name": "alexpires.me",
"defaultRole": "member"
}
@@ -0,0 +1,9 @@
{
"id": "5000",
"srcID": "5000",
"name": "Internal",
"url": "http://kapacitor:9092",
"insecureSkipVerify": false,
"active": true,
"organization": "default"
}
@@ -0,0 +1,10 @@
{
"id": "5000",
"name": "internal",
"url": "http://influxdb:8086",
"type": "influx",
"insecureSkipVerify": false,
"default": true,
"telegraf": "telegraf",
"organization": "default"
}
@@ -0,0 +1,273 @@
[SERVICE]
Flush 1
Daemon Off
Log_Level info
Parsers_File parsers.conf
[INPUT]
Name tail
Tag ingress.*
Path /var/log/containers/nginx-ingress-microk8s-controller-*.log
Parser cri
Refresh_Interval 5
Mem_Buf_Limit 5MB
Skip_Long_Lines On
[INPUT]
Name tail
Tag nextcloud.*
Path /var/log/containers/nextcloud-app-*.log
Parser cri
Refresh_Interval 5
Mem_Buf_Limit 5MB
Skip_Long_Lines On
[INPUT]
Name tail
Tag wordpress.*
Path /var/log/containers/wordpress-app-*.log
Parser cri
Refresh_Interval 5
Mem_Buf_Limit 5MB
Skip_Long_Lines On
[INPUT]
Name tail
Tag gitea.*
Path /var/log/containers/gitea-app-*.log
Parser cri
Refresh_Interval 5
Mem_Buf_Limit 5MB
Skip_Long_Lines On
[INPUT]
Name tail
Tag kube.*
Path /var/log/containers/*.log
Parser cri
Refresh_Interval 5
Mem_Buf_Limit 5MB
Skip_Long_Lines On
[FILTER]
Name kubernetes
Match ingress.*
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Kube_Tag_Prefix ingress.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
Labels On
K8S-Logging.Parser Off
K8S-Logging.Exclude Off
[FILTER]
Name kubernetes
Match nextcloud.*
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Kube_Tag_Prefix nextcloud.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
Labels On
K8S-Logging.Parser Off
K8S-Logging.Exclude Off
[FILTER]
Name kubernetes
Match wordpress.*
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Kube_Tag_Prefix wordpress.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
Labels On
K8S-Logging.Parser Off
K8S-Logging.Exclude Off
[FILTER]
Name kubernetes
Match gitea.*
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Kube_Tag_Prefix gitea.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
Labels On
K8S-Logging.Parser Off
K8S-Logging.Exclude Off
[FILTER]
Name kubernetes
Match kube.*
Kube_URL https://kubernetes.default.svc:443
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
Merge_Log On
Merge_Log_Key log_processed
Labels On
K8S-Logging.Parser On
K8S-Logging.Exclude On
[FILTER]
Name nest
Match *
Wildcard pod_name
Operation lift
Nested_under kubernetes
Add_prefix kubernetes_
[FILTER]
Name rewrite_tag
Match ingress.*
Rule $kubernetes_pod_name ^.*$ ingress_logs false
[FILTER]
Name rewrite_tag
Match nextcloud.*
Rule $kubernetes_pod_name ^.*$ nextcloud_logs false
[FILTER]
Name rewrite_tag
Match wordpress.*
Rule $kubernetes_pod_name ^.*$ wordpress_logs false
[FILTER]
Name rewrite_tag
Match gitea.*
Rule $kubernetes_pod_name ^.*$ gitea_logs false
[FILTER]
Name rewrite_tag
Match kube.*
Rule $kubernetes_pod_name ^.*$ kubernetes_logs false
[FILTER]
Name parser
Match ingress_logs
Key_Name log
Parser nginx-ingress
[FILTER]
Name parser
Match nextcloud_logs
Key_Name log
Parser apache2
[FILTER]
Name parser
Match wordpress_logs
Key_Name log
Parser apache2
[FILTER]
Name parser
Match gitea_logs
Key_Name log
Parser gitea
[FILTER]
Name geoip2
Match ingress_logs
Database /fluent-bit/etc/GeoLite2-City.mmdb
Lookup_key host
Record country_name host %{country.names.en}
Record country_code host %{country.iso_code}
Record city host %{city.names.en}
Record coord.lat host %{location.latitude}
Record coord.lon host %{location.longitude}
[FILTER]
Name geoip2
Match nextcloud_logs
Database /fluent-bit/etc/GeoLite2-City.mmdb
Lookup_key host
Record country_name host %{country.names.en}
Record country_code host %{country.iso_code}
Record city host %{city.names.en}
Record coord.lat host %{location.latitude}
Record coord.lon host %{location.longitude}
[FILTER]
Name geoip2
Match wordpress_logs
Database /fluent-bit/etc/GeoLite2-City.mmdb
Lookup_key host
Record country_name host %{country.names.en}
Record country_code host %{country.iso_code}
Record city host %{city.names.en}
Record coord.lat host %{location.latitude}
Record coord.lon host %{location.longitude}
[FILTER]
Name nest
Match ingress_logs
Operation nest
Wildcard coord.*
Nested_under coordinates
Remove_prefix coord.
[FILTER]
Name nest
Match nextcloud_logs
Operation nest
Wildcard coord.*
Nested_under coordinates
Remove_prefix coord.
[FILTER]
Name nest
Match wordpress_logs
Operation nest
Wildcard coord.*
Nested_under coordinates
Remove_prefix coord.
[OUTPUT]
Name influxdb
Match ingress_logs
Host influxdb
Port 8086
Database ingress
Sequence_Tag off
Tag_Keys proxy_upstream_name code
[OUTPUT]
Name influxdb
Match nextcloud_logs
Host influxdb
Port 8086
Database nextcloud
Sequence_Tag off
Tag_Keys code
[OUTPUT]
Name influxdb
Match wordpress_logs
Host influxdb
Port 8086
Database wordpress
Sequence_Tag off
Tag_Keys code
[OUTPUT]
Name influxdb
Match gitea_logs
Host influxdb
Port 8086
Database gitea
Sequence_Tag off
Tag_Keys status_code
[OUTPUT]
Name influxdb
Match kubernetes_logs
Host influxdb
Port 8086
Database kubernetes
Sequence_Tag off
Tag_Keys kubernetes_namespace_name kubernetes_container_name
@@ -0,0 +1,68 @@
[PARSER]
Name apache
Format regex
Regex ^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name apache2
Format regex
Regex ^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name apache_error
Format regex
Regex ^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\](?: \[pid (?<pid>[^\]]*)\])?( \[client (?<client>[^\]]*)\])? (?<message>.*)$
[PARSER]
Name nginx
Format regex
Regex ^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name json
Format json
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name docker
Format json
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%L
Time_Keep On
[PARSER]
# https://rubular.com/r/V3W1DWyv5uFCfh
Name nginx-ingress
Format regex
Regex ^(?<host>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*) "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<request_length>[^ ]*) (?<request_time>[^ ]*) \[(?<proxy_upstream_name>[^ ]*)\] (\[(?<proxy_alternative_upstream_name>[^ ]*)\] )?(?<upstream_addr>[^ ]*) (?<upstream_response_length>[^ ]*) (?<upstream_response_time>[^ ]*) (?<upstream_status>[^ ]*) (?<reg_id>[^ ]*).*$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name gitea
Format regex
Regex ^(?<time>[^ ]\d+\/\d+\/\d+ \d+:\d+:\d+) (((?<model_func>.*) \[I\])? \[[0-9a-z-]+\] (\[SQL\] (?<query>.*) - (?<query_time>[0-9.]+)µs|(?<message>.*))|\[[0-9a-z-]+\] router: (?<state>\w+) (?<method>\S+) (?<path>.*?) for (?<src>[^ ]*):(?<src_port>[^ ]*), (?<status_code>[^ ]*) (?<status_msg>[^ ]*) in (?<exec_time>[0-9.]+)ms @ (?<func>.*).*)
Time_Key time
Time_Format %Y/%m/%d %H:%M:%S
[PARSER]
Name cri
Format regex
# XXX: modified from upstream: s/message/log/
Regex ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>[^ ]*) (?<log>.*)$
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%L%z
[PARSER]
Name catchall
Format regex
Regex ^(?<message>.*)$
@@ -0,0 +1,6 @@
CREATE DATABASE telegraf WITH DURATION 7d
CREATE DATABASE kubernetes WITH DURATION 7d
CREATE DATABASE ingress WITH DURATION 7d
CREATE DATABASE nextcloud WITH DURATION 7d
CREATE DATABASE wordpress WITH DURATION 7d
CREATE DATABASE gitea WITH DURATION 7d
@@ -0,0 +1,171 @@
# Telegraf Configuration
#
# Telegraf is entirely plugin driven. All metrics are gathered from the
# declared inputs, and sent to the declared outputs.
#
# Plugins must be declared in here to be active.
# To deactivate a plugin, comment out the name and any variables.
#
# Use 'telegraf -config telegraf.conf -test' to see what metrics a config
# file would generate.
#
# Environment variables can be used anywhere in this config file, simply prepend
# them with $. For strings the variable must be within quotes (ie, "$STR_VAR"),
# for numbers and booleans they should be plain (ie, $INT_VAR, $BOOL_VAR)
# Global tags can be specified here in key="value" format.
[global_tags]
host="k8s"
# Configuration for telegraf agent
[agent]
## Default data collection interval for all inputs
interval = "10s"
## Rounds collection interval to 'interval'
## ie, if interval="10s" then always collect on :00, :10, :20, etc.
round_interval = true
## Telegraf will send metrics to outputs in batches of at most
## metric_batch_size metrics.
## This controls the size of writes that Telegraf sends to output plugins.
metric_batch_size = 1000
## For failed writes, telegraf will cache metric_buffer_limit metrics for each
## output, and will flush this buffer on a successful write. Oldest metrics
## are dropped first when this buffer fills.
## This buffer only fills when writes fail to output plugin(s).
metric_buffer_limit = 10000
## Collection jitter is used to jitter the collection by a random amount.
## Each plugin will sleep for a random time within jitter before collecting.
## This can be used to avoid many plugins querying things like sysfs at the
## same time, which can have a measurable effect on the system.
collection_jitter = "0s"
## Default flushing interval for all outputs. Maximum flush_interval will be
## flush_interval + flush_jitter
flush_interval = "10s"
## Jitter the flush interval by a random amount. This is primarily to avoid
## large write spikes for users running a large number of telegraf instances.
## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
flush_jitter = "0s"
## By default or when set to "0s", precision will be set to the same
## timestamp order as the collection interval, with the maximum being 1s.
## ie, when interval = "10s", precision will be "1s"
## when interval = "250ms", precision will be "1ms"
## Precision will NOT be used for service inputs. It is up to each individual
## service input to set the timestamp at the appropriate precision.
## Valid time units are "ns", "us" (or "µs"), "ms", "s".
precision = ""
## Logging configuration:
## Run telegraf with debug log messages.
debug = false
## Run telegraf in quiet mode (error log messages only).
quiet = false
## Specify the log file name. The empty string means to log to stderr.
logfile = ""
## Override default hostname, if empty use os.Hostname()
hostname = ""
omit_hostname = true
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
urls = ["http://influxdb:8086"]
database = "telegraf"
# Read metrics about cpu usage
[[inputs.cpu]]
## Whether to report per-cpu stats or not
percpu = true
## Whether to report total system cpu stats or not
totalcpu = true
## If true, collect raw CPU time metrics.
collect_cpu_time = false
## If true, compute and report the sum of all non-idle CPU states.
report_active = false
# Read metrics about disk usage by mount point
[[inputs.disk]]
## By default stats will be gathered for all mount points.
## Set mount_points will restrict the stats to only the specified mount points.
# mount_points = ["/"]
## Ignore mount points by filesystem type.
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs"]
# Read metrics about disk IO by device
[[inputs.diskio]]
## By default, telegraf will gather stats for all devices including
## disk partitions.
## Setting devices will restrict the stats to the specified devices.
# devices = ["sda", "sdb", "vd*"]
## Uncomment the following line if you need disk serial numbers.
# skip_serial_number = false
#
## On systems which support it, device metadata can be added in the form of
## tags.
## Currently only Linux is supported via udev properties. You can view
## available properties for a device by running:
## 'udevadm info -q property -n /dev/sda'
# device_tags = ["ID_FS_TYPE", "ID_FS_USAGE"]
#
## Using the same metadata source as device_tags, you can also customize the
## name of the device via templates.
## The 'name_templates' parameter is a list of templates to try and apply to
## the device. The template may contain variables in the form of '$PROPERTY' or
## '${PROPERTY}'. The first template which does not contain any variables not
## present for the device is used as the device name tag.
## The typical use case is for LVM volumes, to get the VG/LV name instead of
## the near-meaningless DM-0 name.
# name_templates = ["$ID_FS_LABEL","$DM_VG_NAME/$DM_LV_NAME"]
# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# no configuration
# Read metrics about memory usage
[[inputs.mem]]
# no configuration
# Get the number of processes and group them by status
[[inputs.processes]]
# no configuration
# Read metrics about swap memory usage
[[inputs.swap]]
# no configuration
# Collect TCP connections state and UDP socket counts
[[inputs.netstat]]
# no configuration
# Gather metrics about network interfaces
[[inputs.net]]
## By default, telegraf gathers stats from any up interface (excluding loopback)
## Setting interfaces will tell it to gather these explicit interfaces,
## regardless of status. When specifying an interface, glob-style
## patterns are also supported.
##
interfaces = ["eth*", "enp0s[0-1]", "lo"]
##
## On linux systems telegraf also collects protocol stats.
## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
##
# ignore_protocol_stats = false
##
[[inputs.kube_inventory]]
namespace = ""
url = "https://kubernetes.default.svc:443"
bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
tls_ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
+163
View File
@@ -0,0 +1,163 @@
resource "kubernetes_cluster_role" "telegraf" {
metadata {
name = "telegraf-role"
labels = {
"rbac.authorization.k8s.io/aggregate-view-telegraf-stats" = "true"
}
}
rule {
api_groups = ["metrics.k8s.io"]
resources = ["pods"]
verbs = ["get", "watch", "list"]
}
rule {
api_groups = [""]
resources = [
"nodes/log",
"nodes/metrics",
"nodes/proxy",
"nodes/spec",
"nodes/stats",
]
verbs = ["*"]
}
rule {
api_groups = ["", "apps"]
resources = ["pods", "endpoints", "deployments", "statefulsets", "daemonsets", "persistentvolumeclaims", "services", "persistentvolumes", "nodes"]
verbs = ["get", "watch", "list"]
}
rule {
api_groups = ["networking.k8s.io"]
resources = ["ingresses"]
verbs = ["get", "watch", "list"]
}
}
resource "kubernetes_cluster_role_binding" "telegraf" {
metadata {
name = "telegraf-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.telegraf.metadata.0.name
}
subject {
kind = "ServiceAccount"
name = kubernetes_service_account.telegraf.metadata.0.name
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
}
resource "kubernetes_service_account" "telegraf" {
metadata {
name = "telegraf-sa"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
automount_service_account_token = false
}
resource "kubernetes_config_map" "telegraf" {
metadata {
name = "telegraf-config"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
data = {
"telegraf.conf" = file("./resources/telegraf/telegraf.conf")
}
}
resource "kubernetes_daemonset" "telegraf" {
depends_on = [
kubernetes_stateful_set.influxdb
]
metadata {
name = "telegraf"
namespace = kubernetes_namespace.monitoring.metadata.0.name
}
spec {
selector {
match_labels = {
app = "telegraf"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
labels = {
app = "telegraf"
}
}
spec {
service_account_name = kubernetes_service_account.telegraf.metadata.0.name
automount_service_account_token = true
container {
name = "telegraf"
image = "telegraf:${local.telegraf_version}"
image_pull_policy = "IfNotPresent"
resources {
requests = {
memory = "100Mi"
}
}
env {
name = "HOST_PROC"
value = "/hostfs/proc"
}
env {
name = "HOST_SYS"
value = "/hostfs/sys"
}
env {
name = "HOST_MOUNT_PREFIX"
value = "/hostfs"
}
volume_mount {
name = "hostfsro"
mount_path = "/hostfs"
read_only = true
}
volume_mount {
mount_path = "/etc/telegraf"
name = "config"
read_only = true
}
}
volume {
name = "hostfsro"
host_path {
path = "/"
}
}
volume {
name = "config"
config_map {
name = kubernetes_config_map.telegraf.metadata.0.name
}
}
}
}
}
lifecycle {
replace_triggered_by = [
kubernetes_config_map.telegraf
]
}
}