Merge pull request #56 from kongfei605/prom_support_env

sidecar demo
This commit is contained in:
kongfei605 2022-06-28 15:52:47 +08:00 committed by GitHub
commit 8e2a88389c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 244 additions and 2 deletions

View File

@ -52,11 +52,13 @@ nohup ./categraf &> stdout.log &
## Deploy categraf as daemonset
edit k8s/categraf.yaml, replace NSERVER_SERVICE_WITH_PORT with service ip:port of nserver in your cluster, replace CATEGRAF_NAMESPACE with namespace value, then run:
edit k8s/daemonset.yaml, replace NSERVER_SERVICE_WITH_PORT with service ip:port of nserver in your cluster, replace CATEGRAF_NAMESPACE with namespace value, then run:
```shell
kubectl apply -n monitoring -f ks8/categraf.yaml
kubectl apply -n monitoring -f ks8/daemonset.yaml
kubectl apply -n monitoring -f ks8/sidecar.yaml
```
notice: k8s/sidecar.yaml is a demo, replace mock with your own image.
## Plugin

240
k8s/sidecar.yaml Normal file
View File

@ -0,0 +1,240 @@
---
kind: ConfigMap
metadata:
name: categraf-config
apiVersion: v1
data:
config.toml: |
[global]
# whether print configs
print_configs = false
# add label(agent_hostname) to series
# "" -> auto detect hostname
# "xx" -> use specified string xx
# "$hostname" -> auto detect hostname
# "$ip" -> auto detect ip
# "$hostname-$ip" -> auto detect hostname and ip to replace the vars
hostname = "$HOSTNAME"
# will not add label(agent_hostname) if true
omit_hostname = false
# s | ms
precision = "ms"
# global collect interval
interval = 15
# [global.labels]
# region = "shanghai"
# env = "localhost"
[writer_opt]
# default: 2000
batch = 2000
# channel(as queue) size
chan_size = 10000
[[writers]]
url = "http://${NSERVER_SERVICE_WITH_PORT}/prometheus/v1/write"
# Basic auth username
basic_auth_user = ""
# Basic auth password
basic_auth_pass = ""
# timeout settings, unit: ms
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100
logs.toml: |
[logs]
## key 占位符
api_key = "ef4ahfbwzwwtlwfpbertgq1i6mq0ab1q"
## 是否开启日志采集
enable = false
## 接受日志的server地址
send_to = "127.0.0.1:17878"
## 发送日志的协议 http/tcp
send_type = "http"
## 是否压缩发送
use_compress = false
## 是否采用ssl
send_with_tls = false
##
batch_wait = 5
## 日志offset信息保存目录
run_path = "/opt/categraf/run"
## 最多同时采集多少个日志文件
open_files_limit = 100
## 定期扫描目录下是否有新增日志
scan_period = 10
## udp 读buffer的大小
frame_size = 9000
##
collect_container_all = true
## 全局的处理规则
[[logs.Processing_rules]]
## 单个日志采集配置
[[logs.items]]
## file/journald/tcp/udp
type = "file"
## type=file时 path必填type=journald/tcp/udp时 port必填
path = "/opt/tomcat/logs/*.txt"
source = "tomcat"
service = "my_service"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: input-prometheus
data:
prometheus.toml: |
# # collect interval
# interval = 15
[[instances]]
urls = ["http://127.0.0.1:8080/metrics"]
name_prefix = "k8s"
#bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
url_label_key = "instance"
url_label_value = "{{.Host}}"
## Scrape Services available in Consul Catalog
[instances.consul]
enabled = false
agent = "http://localhost:8500"
query_interval = "5m"
[[instances.consul.query]]
name = "a service name"
tag = "a service tag"
url = 'http://{{if ne .ServiceAddress ""}}{{.ServiceAddress}}{{else}}{{.Address}}{{end}}:{{.ServicePort}}/{{with .ServiceMeta.metrics_path}}{{.}}{{else}}metrics{{end}}'
[instances.consul.query.tags]
host = "{{.Node}}"
# bearer_token_string = ""
# e.g. /run/secrets/kubernetes.io/serviceaccount/token
# # basic auth
# username = ""
# password = ""
# headers = ["X-From", "categraf"]
# # interval = global.interval * interval_times
# interval_times = 1
labels = {source="categraf123"}
# support glob
# ignore_metrics = [ "go_*" ]
# support glob
# ignore_label_keys = []
# timeout for every url
# timeout = "3s"
## Optional TLS Config
#use_tls = false
# tls_min_version = "1.2"
# tls_ca = "/etc/categraf/ca.pem"
# tls_cert = "/etc/categraf/cert.pem"
# tls_key = "/etc/categraf/key.pem"
## Use TLS but skip chain & host verification
#insecure_skip_verify = true
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "2"
labels:
app: mock
name: mock
spec:
replicas: 1
selector:
matchLabels:
app: mock
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: mock
spec:
containers:
- name: mock
image: flashcatcloud/mock:0.0.1
imagePullPolicy: IfNotPresent
command: ["./mock"]
resources: {}
env:
- name: TZ
value: Asia/Shanghai
- name: HOSTNAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: HOSTIP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: categraf
image: flashcatcloud/categraf:v0.1.10
command: ["/usr/bin/categraf"]
args: ["-configs", "/opt/categraf/conf"]
imagePullPolicy: IfNotPresent
resources: {}
env:
- name: TZ
value: Asia/Shanghai
- name: HOSTNAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: HOSTIP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
volumeMounts:
- mountPath: /opt/categraf/conf/config.toml
name: categraf-config
subPath: config.toml
- mountPath: /opt/categraf/conf/logs.toml
name: categraf-config
subPath: logs.toml
- mountPath: /opt/categraf/conf/input.prometheus
name: input-prometheus
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
volumes:
- configMap:
defaultMode: 420
items:
- key: config.toml
path: config.toml
- key: logs.toml
path: logs.toml
name: categraf-config
name: categraf-config
- configMap:
defaultMode: 420
name: input-prometheus
name: input-prometheus