From 928c1f0995d9c41f46f4279446a70083e3639a90 Mon Sep 17 00:00:00 2001 From: Awin Huang Date: Sat, 17 Feb 2024 15:31:50 +0800 Subject: [PATCH] Update config --- .env | 2 - .gitignore | 2 + clean.sh | 8 ++ data/{ => grafana}/grafana.ini | 0 data/telegraf/telegraf.conf | 143 +++++++++++++++++++++++++++++++++ docker-compose.yml | 50 ++++++++++-- 6 files changed, 197 insertions(+), 8 deletions(-) delete mode 100644 .env create mode 100755 clean.sh rename data/{ => grafana}/grafana.ini (100%) create mode 100644 data/telegraf/telegraf.conf diff --git a/.env b/.env deleted file mode 100644 index b4a2044..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -GF_SECURITY_ADMIN_USER=admin -GF_SECURITY_ADMIN_PASSWORD=adminpass diff --git a/.gitignore b/.gitignore index db7a4dc..cf35129 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ data/* +data/grafana !data/grafana/grafana.ini +data/telegra !data/telegraf/telegraf.conf diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..717bf26 --- /dev/null +++ b/clean.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +sudo rm -rf ./data/grafana/data +sudo rm -rf ./data/grafana/provisioning +mkdir -p ./data/grafana/data +chmod 757 ./data/grafana/data + +sudo rm -rf ./data/influxdb/data diff --git a/data/grafana.ini b/data/grafana/grafana.ini similarity index 100% rename from data/grafana.ini rename to data/grafana/grafana.ini diff --git a/data/telegraf/telegraf.conf b/data/telegraf/telegraf.conf new file mode 100644 index 0000000..d008c40 --- /dev/null +++ b/data/telegraf/telegraf.conf @@ -0,0 +1,143 @@ +# 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 = "" + ## If set to true, do no set the "host" tag in the telegraf agent. + omit_hostname = false + +[[outputs.influxdb_v2]] + ## The URLs of the InfluxDB cluster nodes. + ## + ## Multiple URLs can be specified for a single cluster, only ONE of the + ## urls will be written to each interval. + ## urls exp: http://127.0.0.1:8086 + urls = ["http://influxdb:8086"] + + ## Token for authentication. + token = "2uY3YEm_n1jw1BLnPV0TL-xdF3xYEZwy85bMdry_fOQhOWoVc99jrwEf5N2PkeQec0ELCt8xMpgVc0EyXCCp2A==" + + ## Organization is the name of the organization you wish to write to; must exist. + organization = "awin" + + ## Destination bucket to write into. + bucket = "main" + +# 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 + ## If true and the info is available then add core_id and physical_id tags + core_tags = false + +[[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"] + +[[inputs.diskio]] + +[[inputs.mem]] + +[[inputs.net]] + +[[inputs.processes]] + +[[inputs.swap]] + +[[inputs.system]] + +[[inputs.docker]] + ## Docker Endpoint + ## To use TCP, set endpoint = "tcp://[ip]:[port]" + ## To use environment variables (ie, docker-machine), set endpoint = "ENV" + ## exp: unix:///var/run/docker.sock + endpoint = "unix:///var/run/docker.sock" + + ## Set to true to collect Swarm metrics(desired_replicas, running_replicas) + gather_services = false + + ## Only collect metrics for these containers, collect all if empty + container_names = [] + + ## Containers to include and exclude. Globs accepted. + ## Note that an empty array for both will include all containers + container_name_include = [] + container_name_exclude = [] + + ## Container states to include and exclude. Globs accepted. + ## When empty only containers in the "running" state will be captured. + # container_state_include = [] + # container_state_exclude = [] + + ## Timeout for docker list, info, and stats commands + timeout = "5s" + + ## Whether to report for each container per-device blkio (8:0, 8:1...) and + ## network (eth0, eth1, ...) stats or not + perdevice = true + + ## Whether to report for each container total blkio and network stats or not + total = false + + ## Which environment variables should we use as a tag + ##tag_env = ["JAVA_HOME", "HEAP_SIZE"] + ## docker labels to include and exclude as tags. Globs accepted. + ## Note that an empty array for both will include all labels as tags + docker_label_include = [] + docker_label_exclude = [] diff --git a/docker-compose.yml b/docker-compose.yml index 5371eef..5d2ad2a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,12 +7,50 @@ services: restart: always user: "1000" # needs to be `id -u` // alternatively chown the grafana/data dir to 472:472 ports: - - "3000:3000" # expose for localhost + - "8081:3000" # expose for localhost + links: + - influxdb volumes: - - $HOME/docker/grafana/data:/var/lib/grafana # data path - - $HOME/docker/grafana/grafana.ini:/etc/grafana/grafana.ini - - $HOME/docker/grafana/provisioning:/etc/grafana/provisioning + - ./data/grafana/data:/var/lib/grafana # data path + - ./data/grafana/provisioning:/etc/grafana/provisioning + - ./data/grafana/grafana.ini:/etc/grafana/grafana.ini environment: - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource - - GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER} - - GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD} + # - GF_SECURITY_ADMIN_USER=admin + # - GF_SECURITY_ADMIN_PASSWORD=adminpass + + influxdb: + image: influxdb + ports: + - "8082:8086" + volumes: + - ./data/influxdb/data:/var/lib/influxdb2 + # environment: + # - INFLUXDB_DB=main + # - DOCKER_INFLUXDB_INIT_MODE=setup + # - DOCKER_INFLUXDB_INIT_USERNAME=admin + # - DOCKER_INFLUXDB_INIT_PASSWORD=adminpass + # - DOCKER_INFLUXDB_INIT_ORG=awin + # - DOCKER_INFLUXDB_INIT_BUCKET=main + + telegraf: + image: telegraf + user: telegraf:992 + depends_on: + - influxdb + links: + - influxdb + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - ./data/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro + environment: + - HOST_PROC=/proc + - HOST_SYS=/sys + - HOST_ETC=/etc + # - HOST_ETC=/hostfs/etc + # - HOST_PROC=/hostfs/proc + # - HOST_SYS=/hostfs/sys + # - HOST_VAR=/hostfs/var + # - HOST_RUN=/hostfs/run + # - HOST_MOUNT_PREFIX=/hostfs +