diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81c4143..75877bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: - id: check-symlinks - id: check-yaml exclude: kubernetes/yaml/network-dashboard.yaml|kubernetes/ISP-Checker-deploy.yaml + args: ["--allow-multiple-documents"] - id: detect-aws-credentials - id: detect-private-key - id: double-quote-string-fixer diff --git a/kubernetes/ISP-Checker-deploy.yaml b/kubernetes/ISP-Checker-deploy.yaml index f8cd31e..9912acb 100644 --- a/kubernetes/ISP-Checker-deploy.yaml +++ b/kubernetes/ISP-Checker-deploy.yaml @@ -33,6 +33,48 @@ spec: storage: 1Gi --- apiVersion: v1 +kind: Secret +metadata: + namespace: monitoring + name: isp-checker-secrets-rw +type: Opaque +stringData: + INFLUXDB_DB: telegraf + INFLUXDB_ADMIN_USER: admin + INFLUXDB_ADMIN_PASSWORD: VerySecurePassword + +--- +apiVersion: v1 +kind: Secret +metadata: + namespace: monitoring + name: isp-checker-secrets-ro +type: Opaque +stringData: + INFLUXDB_DB: telegraf + INFLUXDB_READ_USER: grafana + INFLUXDB_READ_PASSWORD: VerySecurePassword + +--- +apiVersion: v1 +kind: Secret +metadata: + namespace: monitoring + name: grafana-datasource +stringData: + datasource.yaml: |- + datasources: + - name: InfluxDB + type: influxdb + access: proxy + orgId: 1 + url: http://influxdb-svc.monitoring.svc.cluster.local:8086/ + user: grafana + database: telegraf + isDefault: true + editable: true +--- +apiVersion: v1 kind: ConfigMap metadata: namespace: monitoring @@ -74,7 +116,7 @@ data: telegraf.conf: |+ [global_tags] [agent] - interval = "10s" + interval = "60s" round_interval = true metric_batch_size = 1000 metric_buffer_limit = 10000 @@ -82,9 +124,10 @@ data: flush_interval = "10s" flush_jitter = "0s" precision = "" - hostname = "" + hostname = "$HOSTNAME" omit_hostname = false debug = false + quiet = true [[outputs.influxdb]] urls = ["http://influxdb-svc.monitoring.svc.cluster.local:8086/"] @@ -95,6 +138,15 @@ data: user_agent = "telegraf" skip_database_creation = false + [[inputs.net]] + [[inputs.netstat]] + [[inputs.diskio]] + [[inputs.linux_sysctl_fs]] + [[inputs.mem]] + [[inputs.processes]] + [[inputs.swap]] + [[inputs.system]] + [[inputs.cpu]] percpu = true totalcpu = true @@ -102,23 +154,22 @@ data: report_active = false [[inputs.disk]] - ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"] - - [[inputs.diskio]] - - [[inputs.kernel]] - - [[inputs.mem]] - - [[inputs.processes]] - - [[inputs.swap]] - - [[inputs.system]] + ignore_fs = ["tmpfs", + "devtmpfs", + "devfs", + "iso9660", + "overlay", + "aufs", + "squashfs" + ] [[inputs.dns_query]] servers = ["4.2.2.1", "8.8.8.8"] - domains = ["www.google.com", "www.twitter.com", "www.amazon.com", "www.wikipedia.org"] + domains = ["www.google.com", + "www.twitter.com", + "www.amazon.com", + "www.wikipedia.org" + ] record_type = "A" port = 53 timeout = 3 @@ -137,12 +188,6 @@ data: [[inputs.internal]] collect_memstats = true - [[inputs.linux_sysctl_fs]] - - [[inputs.net]] - - [[inputs.netstat]] - [[inputs.ping]] urls = [ "google.com", @@ -174,51 +219,22 @@ data: timeout = "3m" interval = "15m" data_format = "csv" - csv_column_names = ['Server ID','Sponsor','Server Name','Timestamp','Distance','Ping','Download','Upload','Share','IP Address'] + csv_column_names = ['Server ID', + 'Sponsor', + 'Server Name', + 'Timestamp', + 'Distance', + 'Ping', + 'Download', + 'Upload', + 'Share', + 'IP Address' + ] csv_timestamp_column = "Timestamp" csv_timestamp_format = "2006-01-02T15:04:05Z07:00" ---- -apiVersion: v1 -kind: Secret -metadata: - namespace: monitoring - name: isp-checker-secrets-rw -type: Opaque -stringData: - INFLUXDB_DB: telegraf - INFLUXDB_ADMIN_USER: admin - INFLUXDB_ADMIN_PASSWORD: VerySecurePassword - ---- -apiVersion: v1 -kind: Secret -metadata: - namespace: monitoring - name: isp-checker-secrets-ro -type: Opaque -stringData: - INFLUXDB_DB: telegraf - INFLUXDB_READ_USER: grafana - INFLUXDB_READ_PASSWORD: VerySecurePassword ---- -apiVersion: v1 -kind: Secret -metadata: - namespace: monitoring - name: grafana-datasource -stringData: - datasource.yaml: |- - datasources: - - name: InfluxDB - type: influxdb - access: proxy - orgId: 1 - url: http://influxdb-svc.monitoring.svc.cluster.local:8086/ - user: grafana - database: telegraf - isDefault: true - editable: true + [[inputs.docker]] + endpoint = "unix:///var/run/docker.sock" --- apiVersion: v1 kind: ConfigMap @@ -3983,33 +3999,55 @@ spec: secretName: grafana-datasource --- apiVersion: apps/v1 -kind: Deployment +kind: DaemonSet metadata: namespace: monitoring name: telegraf labels: app: telegraf spec: - replicas: 1 selector: matchLabels: app: telegraf template: metadata: labels: + name: telegraf app: telegraf spec: containers: - name: telegraf image: tty0/isp_telegraf:1.15.3 + imagePullPolicy: IfNotPresent envFrom: - secretRef: name: isp-checker-secrets-rw - imagePullPolicy: IfNotPresent + env: + - name: "KUBE_API" + value: "https://node2:6443/" + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: "HOST_PROC" + value: "/rootfs/proc" + - name: "HOST_SYS" + value: "/rootfs/sys" volumeMounts: - name: telegraf-config-volume mountPath: /etc/telegraf/ readOnly: true + - name: sys + mountPath: /sys/ + readOnly: true + - name: proc + mountPath: /proc/ + readOnly: true + - name: docker-socket + mountPath: /var/run/docker.sock + - name: utmp + mountPath: /var/run/utmp + readOnly: true resources: requests: memory: "100Mi" @@ -4021,7 +4059,20 @@ spec: - name: wait-for-influxdb image: curlimages/curl:7.72.0 command: ['sh', '-c', "until curl -XGET http://influxdb-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local:8086/; do echo Waiting\ for\ InfluxDB; sleep 2; done"] + terminationGracePeriodSeconds: 30 volumes: - name: telegraf-config-volume configMap: name: telegraf-config + - name: sys + hostPath: + path: /sys + - name: docker-socket + hostPath: + path: /var/run/docker.sock + - name: proc + hostPath: + path: /proc + - name: utmp + hostPath: + path: /var/run/utmp diff --git a/kubernetes/yaml/configmap.yaml b/kubernetes/yaml/configmap.yaml index 63f0d20..4bc6b84 100644 --- a/kubernetes/yaml/configmap.yaml +++ b/kubernetes/yaml/configmap.yaml @@ -41,7 +41,7 @@ data: telegraf.conf: |+ [global_tags] [agent] - interval = "10s" + interval = "60s" round_interval = true metric_batch_size = 1000 metric_buffer_limit = 10000 @@ -49,9 +49,10 @@ data: flush_interval = "10s" flush_jitter = "0s" precision = "" - hostname = "" + hostname = "$HOSTNAME" omit_hostname = false debug = false + quiet = true [[outputs.influxdb]] urls = ["http://influxdb-svc.monitoring.svc.cluster.local:8086/"] @@ -62,6 +63,15 @@ data: user_agent = "telegraf" skip_database_creation = false + [[inputs.net]] + [[inputs.netstat]] + [[inputs.diskio]] + [[inputs.linux_sysctl_fs]] + [[inputs.mem]] + [[inputs.processes]] + [[inputs.swap]] + [[inputs.system]] + [[inputs.cpu]] percpu = true totalcpu = true @@ -69,23 +79,22 @@ data: report_active = false [[inputs.disk]] - ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"] - - [[inputs.diskio]] - - [[inputs.kernel]] - - [[inputs.mem]] - - [[inputs.processes]] - - [[inputs.swap]] - - [[inputs.system]] + ignore_fs = ["tmpfs", + "devtmpfs", + "devfs", + "iso9660", + "overlay", + "aufs", + "squashfs" + ] [[inputs.dns_query]] servers = ["4.2.2.1", "8.8.8.8"] - domains = ["www.google.com", "www.twitter.com", "www.amazon.com", "www.wikipedia.org"] + domains = ["www.google.com", + "www.twitter.com", + "www.amazon.com", + "www.wikipedia.org" + ] record_type = "A" port = 53 timeout = 3 @@ -104,12 +113,6 @@ data: [[inputs.internal]] collect_memstats = true - [[inputs.linux_sysctl_fs]] - - [[inputs.net]] - - [[inputs.netstat]] - [[inputs.ping]] urls = [ "google.com", @@ -141,6 +144,19 @@ data: timeout = "3m" interval = "15m" data_format = "csv" - csv_column_names = ['Server ID','Sponsor','Server Name','Timestamp','Distance','Ping','Download','Upload','Share','IP Address'] + csv_column_names = ['Server ID', + 'Sponsor', + 'Server Name', + 'Timestamp', + 'Distance', + 'Ping', + 'Download', + 'Upload', + 'Share', + 'IP Address' + ] csv_timestamp_column = "Timestamp" csv_timestamp_format = "2006-01-02T15:04:05Z07:00" + + [[inputs.docker]] + endpoint = "unix:///var/run/docker.sock" diff --git a/kubernetes/yaml/daemonSet.yaml b/kubernetes/yaml/daemonSet.yaml new file mode 100644 index 0000000..d269d2b --- /dev/null +++ b/kubernetes/yaml/daemonSet.yaml @@ -0,0 +1,79 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + namespace: monitoring + name: telegraf + labels: + app: telegraf +spec: + selector: + matchLabels: + app: telegraf + template: + metadata: + labels: + name: telegraf + app: telegraf + spec: + containers: + - name: telegraf + image: tty0/isp_telegraf:1.15.3 + imagePullPolicy: IfNotPresent + envFrom: + - secretRef: + name: isp-checker-secrets-rw + env: + - name: "KUBE_API" + value: "https://node2:6443/" + - name: HOSTNAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: "HOST_PROC" + value: "/rootfs/proc" + - name: "HOST_SYS" + value: "/rootfs/sys" + volumeMounts: + - name: telegraf-config-volume + mountPath: /etc/telegraf/ + readOnly: true + - name: sys + mountPath: /sys/ + readOnly: true + - name: proc + mountPath: /proc/ + readOnly: true + - name: docker-socket + mountPath: /var/run/docker.sock + - name: utmp + mountPath: /var/run/utmp + readOnly: true + resources: + requests: + memory: "100Mi" + cpu: "0.1" + limits: + memory: "200Mi" + cpu: "0.3" + initContainers: + - name: wait-for-influxdb + image: curlimages/curl:7.72.0 + command: ['sh', '-c', "until curl -XGET http://influxdb-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local:8086/; do echo Waiting\ for\ InfluxDB; sleep 2; done"] + terminationGracePeriodSeconds: 30 + volumes: + - name: telegraf-config-volume + configMap: + name: telegraf-config + - name: sys + hostPath: + path: /sys + - name: docker-socket + hostPath: + path: /var/run/docker.sock + - name: proc + hostPath: + path: /proc + - name: utmp + hostPath: + path: /var/run/utmp diff --git a/kubernetes/yaml/deployment.yaml b/kubernetes/yaml/deployment.yaml index 803d230..ffbcc9b 100644 --- a/kubernetes/yaml/deployment.yaml +++ b/kubernetes/yaml/deployment.yaml @@ -134,47 +134,3 @@ spec: - name: grafana-datasource-provisioner secret: secretName: grafana-datasource ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - namespace: monitoring - name: telegraf - labels: - app: telegraf -spec: - replicas: 1 - selector: - matchLabels: - app: telegraf - template: - metadata: - labels: - app: telegraf - spec: - containers: - - name: telegraf - image: tty0/isp_telegraf:1.15.3 - envFrom: - - secretRef: - name: isp-checker-secrets-rw - imagePullPolicy: IfNotPresent - volumeMounts: - - name: telegraf-config-volume - mountPath: /etc/telegraf/ - readOnly: true - resources: - requests: - memory: "100Mi" - cpu: "0.1" - limits: - memory: "200Mi" - cpu: "0.3" - initContainers: - - name: wait-for-influxdb - image: curlimages/curl:7.72.0 - command: ['sh', '-c', "until curl -XGET http://influxdb-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local:8086/; do echo Waiting\ for\ InfluxDB; sleep 2; done"] - volumes: - - name: telegraf-config-volume - configMap: - name: telegraf-config diff --git a/kubernetes/yaml/network-dashboard.yaml b/kubernetes/yaml/networkDashboard.yaml similarity index 100% rename from kubernetes/yaml/network-dashboard.yaml rename to kubernetes/yaml/networkDashboard.yaml