From dade19d8e11e52bd255ad62f8b2219cd2b5f7ec7 Mon Sep 17 00:00:00 2001 From: liushaobo Date: Thu, 22 Jul 2021 17:04:57 +0800 Subject: [PATCH] =?UTF-8?q?windows=E5=85=BC=E5=AE=B9=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml.rej | 57 ++ Dockerfile_win | 39 ++ Makefile | 13 + config/load.go | 2 +- man/manuals/jvm.md.rej | 11 + man/manuals/kube-state-metrics.md | 504 --------------- man/manuals/kubernetes-prom.md | 4 +- man/manuals/kubernetes.md | 591 +++++++++++++++++- man/manuals/mysql.md.rej | 55 ++ man/summary.md | 3 +- plugins/inputs/all/all.go | 1 + .../kube_state_metric/kube_state_metric.go | 173 +++++ plugins/inputs/kubernetes/cfg_win.conf | 20 + plugins/inputs/kubernetes/conf.go | 25 +- plugins/inputs/kubernetes/input.go | 9 +- plugins/inputs/kubernetes/input_test.go | 16 + plugins/inputs/mysql/user.go | 1 - 17 files changed, 1006 insertions(+), 518 deletions(-) create mode 100644 .gitlab-ci.yml.rej create mode 100644 Dockerfile_win create mode 100644 man/manuals/jvm.md.rej delete mode 100644 man/manuals/kube-state-metrics.md create mode 100644 man/manuals/mysql.md.rej create mode 100644 plugins/inputs/kube_state_metric/kube_state_metric.go create mode 100644 plugins/inputs/kubernetes/cfg_win.conf diff --git a/.gitlab-ci.yml.rej b/.gitlab-ci.yml.rej new file mode 100644 index 0000000000..e49a7c2761 --- /dev/null +++ b/.gitlab-ci.yml.rej @@ -0,0 +1,57 @@ +diff a/.gitlab-ci.yml b/.gitlab-ci.yml (rejected hunks) +@@ -23,29 +23,29 @@ stages: + # tags: + # - cloudcare-ft + +-build-testing: +- stage: deploy +- only: +- - testing +- script: +- # building && publish testing +- - make ci_notify +- - make testing +- - make pub_testing +- - make pub_testing_img +- - make test_notify +- tags: +- - cloudcare-ft +- +-build-release: +- stage: deploy +- only: +- - master +- script: +- - make ci_notify +- - make release +- - make pub_release +- - make pub_release_img +- - make release_notify +- tags: +- - cloudcare-ft ++#build-testing: ++# stage: deploy ++# only: ++# - testing ++# script: ++# # building && publish testing ++# - make ci_notify ++# - make testing ++# - make pub_testing ++# - make pub_testing_img ++# - make test_notify ++# tags: ++# - cloudcare-ft ++# ++#build-release: ++# stage: deploy ++# only: ++# - master ++# script: ++# - make ci_notify ++# - make release ++# - make pub_release ++# - make pub_release_img ++# - make release_notify ++# tags: ++# - cloudcare-ft diff --git a/Dockerfile_win b/Dockerfile_win new file mode 100644 index 0000000000..2a3f614109 --- /dev/null +++ b/Dockerfile_win @@ -0,0 +1,39 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +ARG exe="dist/datakit-windows-amd64" +ARG target="C:/Program Files/datakit/" + +RUN mkdir ${target} + +COPY ${exe} ${target} + +# download data files required by datakit +ADD https://zhuyun-static-files-production.oss-cn-hangzhou.aliyuncs.com/datakit/data.tar.gz data.tar.gz +RUN tar -zxvf data.tar.gz -C ${target} +RUN del "data.tar.gz" + +ARG dataway="" +ARG loglevel="" +ARG global_tags="" +ARG hostname="" +ARG name="" +ARG http_listen="" +ARG rum_origin_ip_header="" +ARG enable_pprof="" +ARG disable_protect_mode="" +ARG default_enabled_inputs="" +ARG enable_election="" + +ENV ENV_DATAWAY=$dataway \ + ENV_LOG_LEVEL=$loglevel \ + ENV_GLOBAL_TAGS=$global_tags \ + ENV_NAME=$name \ + ENV_HTTP_LISTEN=$http_listen \ + ENV_RUM_ORIGIN_IP_HEADER=$rum_origin_ip_header \ + ENV_ENABLE_PPROF=$enable_pprof \ + ENV_DISABLE_PROTECT_MODE=$=$disable_protect_mode \ + ENV_DEFAULT_ENABLED_INPUTS=$default_enabled_inputs \ + ENV_ENABLE_ELECTION=$enable_election \ + ENV_HOSTNAME=$hostname + +CMD ["C:\\Program Files\\datakit\\datakit", "--docker"] \ No newline at end of file diff --git a/Makefile b/Makefile index 7a88768882..d2e8513236 100644 --- a/Makefile +++ b/Makefile @@ -105,12 +105,25 @@ pub_testing: pub_testing_mac: $(call pub,test,$(TEST_DOWNLOAD_ADDR),$(MAC_ARCHS)) +pub_testing_win_img: + @mkdir -p embed/windows-amd64 + @wget --quiet -O - "https://$(TEST_DOWNLOAD_ADDR)/iploc/iploc.tar.gz" | tar -xz -C . + @sudo docker build -t registry.jiagouyun.com/datakit/datakit-win:$(GIT_VERSION) -f ./Dockerfile_win . + @sudo docker push registry.jiagouyun.com/datakit/datakit-win:$(GIT_VERSION) + pub_testing_img: @mkdir -p embed/linux-amd64 @wget --quiet -O - "https://$(TEST_DOWNLOAD_ADDR)/iploc/iploc.tar.gz" | tar -xz -C . @sudo docker build -t registry.jiagouyun.com/datakit/datakit:$(GIT_VERSION) . @sudo docker push registry.jiagouyun.com/datakit/datakit:$(GIT_VERSION) +pub_release_win_img: + # release to pub hub + @mkdir -p embed/windows-amd64 + @wget --quiet -O - "https://$(RELEASE_DOWNLOAD_ADDR)/iploc/iploc.tar.gz" | tar -xz -C . + @sudo docker build -t pubrepo.jiagouyun.com/datakit/datakit-win:$(GIT_VERSION) -f ./Dockerfile_win . + @sudo docker push pubrepo.jiagouyun.com/datakit/datakit-win:$(GIT_VERSION) + pub_release_img: # release to pub hub @mkdir -p embed/linux-amd64 diff --git a/config/load.go b/config/load.go index d8a0081b18..81cb7088ed 100644 --- a/config/load.go +++ b/config/load.go @@ -31,7 +31,7 @@ func LoadCfg(c *Config, mcp string) error { if datakit.Docker { // only accept configs from ENV under docker(or daemon-set) mode - if runtime.GOOS != "linux" { + if runtime.GOOS != "linux" && runtime.GOOS != "windows" { return fmt.Errorf("docker mode not supported under %s", runtime.GOOS) } diff --git a/man/manuals/jvm.md.rej b/man/manuals/jvm.md.rej new file mode 100644 index 0000000000..8144782aef --- /dev/null +++ b/man/manuals/jvm.md.rej @@ -0,0 +1,11 @@ +diff a/man/manuals/jvm.md b/man/manuals/jvm.md (rejected hunks) +@@ -97,9 +97,6 @@ java -javaagent:dd-java-agent.jar \ + -Ddd.jmxfetch.check-period=1000 \ + -Ddd.jmxfetch.statsd.host=127.0.0.1 \ + -Ddd.jmxfetch.statsd.port=8125 \ +- -Ddd.trace.health.metrics.enabled=true \ +- -Ddd.trace.health.metrics.statsd.host=127.0.0.1 \ +- -Ddd.trace.health.metrics.statsd.port=8125 \ + -Ddd.version=1.0 \ + -jar your-app.jar + ``` diff --git a/man/manuals/kube-state-metrics.md b/man/manuals/kube-state-metrics.md deleted file mode 100644 index 06133355e8..0000000000 --- a/man/manuals/kube-state-metrics.md +++ /dev/null @@ -1,504 +0,0 @@ -{{.CSS}} - -- 版本:{{.Version}} -- 发布日期:{{.ReleaseDate}} -- 操作系统支持:Linux - -# Kubernetes 集群监控指标数据 - -该方案扩展了 Datakit 集群部署,内置 [kube-state-metrics](https://github.com/kubernetes/kube-state-metrics) 服务,用来采集 kubernetes 集群监控指标数据。 - -> 具体指标,参考 [kubernetes](kubernetes) 中的列表 - -### 修改配置 - -修改 `datakit-default.yaml` 中的 dataway 配置 - -```yaml - - name: ENV_DATAWAY - value: https://openway.dataflux.cn?token= # 此处填上具体 token -``` - -### 应用 yaml 配置 - -下载下文 yaml, 直接应用即可: - -```shell -kubectl apply path/to/your.yaml -``` - -### yaml 配置 - -```yaml -apiVersion: v1 -kind: Namespace -metadata: - name: datakit ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: datakit -rules: -- apiGroups: - - "" - resources: - - nodes - - nodes/proxy - - namespaces - - pods - - services - - endpoints - - persistentvolumes - - persistentvolumeclaims - - ingresses - verbs: - - get - - list - - watch -- apiGroups: - - apps - resources: - - deployments - - daemonsets - - statefulsets - - replicasets - verbs: - - get - - list - - watch -- apiGroups: - - extensions - resources: - - ingresses - verbs: - - get - - list - - watch -- apiGroups: - - batch - resources: - - jobs - - cronjobs - verbs: - - get - - list - - watch -- nonResourceURLs: ["/metrics"] - verbs: ["get"] - ---- - -apiVersion: v1 -kind: ServiceAccount -metadata: - name: datakit - namespace: datakit - ---- - -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: datakit -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: datakit -subjects: -- kind: ServiceAccount - name: datakit - namespace: datakit - ---- - -apiVersion: apps/v1 -kind: DaemonSet -metadata: - labels: - app: daemonset-datakit - name: datakit - namespace: datakit -spec: - revisionHistoryLimit: 10 - selector: - matchLabels: - app: daemonset-datakit - template: - metadata: - labels: - app: daemonset-datakit - spec: - hostNetwork: true - dnsPolicy: ClusterFirstWithHostNet - containers: - - env: - - name: HOST_IP - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: status.hostIP - - name: NODE_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: spec.nodeName - - name: ENV_DATAWAY - value: https://openway.dataflux.cn?token= - - name: ENV_GLOBAL_TAGS - value: host=__datakit_hostname,host_ip=__datakit_ip - - name: ENV_ENABLE_INPUTS - value: cpu,disk,diskio,mem,swap,system,hostobject,net,host_processes,kubernetes,container - - name: ENV_ENABLE_ELECTION - value: enable - - name: ENV_HTTP_LISTEN - value: 0.0.0.0:9529 - image: pubrepo.jiagouyun.com/datakit/datakit:{{.Version}} - imagePullPolicy: Always - name: datakit - ports: - - containerPort: 9529 - hostPort: 9529 - name: port - protocol: TCP - securityContext: - privileged: true - volumeMounts: - - mountPath: /var/run/docker.sock - name: docker-socket - readOnly: true - - mountPath: /usr/local/datakit/conf.d/container/container.conf - name: datakit-conf - subPath: container.conf - - mountPath: /usr/local/datakit/conf.d/kubernetes/kubernetes.conf - name: datakit-conf - subPath: kubernetes.conf - - mountPath: /usr/local/datakit/conf.d/kubernetes/kube-state-metric.conf - name: datakit-conf - subPath: kube-state-metric.conf - - mountPath: /host/proc - name: proc - readOnly: true - - mountPath: /host/dev - name: dev - readOnly: true - - mountPath: /host/sys - name: sys - readOnly: true - - mountPath: /rootfs - name: rootfs - workingDir: /usr/local/datakit - hostIPC: true - hostNetwork: true - hostPID: true - restartPolicy: Always - serviceAccount: datakit - serviceAccountName: datakit - volumes: - - configMap: - name: datakit-conf - name: datakit-conf - - hostPath: - path: /var/run/docker.sock - name: docker-socket - - hostPath: - path: /proc - type: "" - name: proc - - hostPath: - path: /dev - type: "" - name: dev - - hostPath: - path: /sys - type: "" - name: sys - - hostPath: - path: / - type: "" - name: rootfs - updateStrategy: - rollingUpdate: - maxUnavailable: 1 - type: RollingUpdate ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.1.0 - name: kube-state-metrics - namespace: datakit -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/name: kube-state-metrics - template: - metadata: - labels: - app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.1.0 - spec: - containers: - - image: pubrepo.jiagouyun.com/metrics-server/kube-state-metrics:v2.1.0 - livenessProbe: - httpGet: - path: /healthz - port: 8080 - initialDelaySeconds: 5 - timeoutSeconds: 5 - name: kube-state-metrics - ports: - - containerPort: 8080 - name: http-metrics - - containerPort: 8081 - name: telemetry - readinessProbe: - httpGet: - path: / - port: 8081 - initialDelaySeconds: 5 - timeoutSeconds: 5 - securityContext: - runAsUser: 65534 - nodeSelector: - kubernetes.io/os: linux - serviceAccountName: datakit ---- -apiVersion: v1 -kind: Service -metadata: - labels: - app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.1.0 - name: kube-state-metrics - namespace: datakit -spec: - type: NodePort - ports: - - name: http-metrics - port: 8080 - targetPort: http-metrics - nodePort: 30022 - - name: telemetry - port: 8081 - targetPort: telemetry - selector: - app.kubernetes.io/name: kube-state-metrics ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: datakit-conf - namespace: datakit -data: - #### container - container.conf: |- - [inputs.container] - endpoint = "unix:///var/run/docker.sock" - - enable_metric = false - enable_object = true - enable_logging = true - - metric_interval = "10s" - - ## TLS Config - # tls_ca = "/path/to/ca.pem" - # tls_cert = "/path/to/cert.pem" - # tls_key = "/path/to/key.pem" - ## Use TLS but skip chain & host verification - # insecure_skip_verify = false - - [inputs.container.kubelet] - kubelet_url = "http://127.0.0.1:10255" - - ## Use bearer token for authorization. ('bearer_token' takes priority) - ## If both of these are empty, we'll use the default serviceaccount: - ## at: /run/secrets/kubernetes.io/serviceaccount/token - # bearer_token = "/path/to/bearer/token" - ## OR - # bearer_token_string = "abc_123" - - ## Optional TLS Config - # tls_ca = /path/to/ca.pem - # tls_cert = /path/to/cert.pem - # tls_key = /path/to/key.pem - ## Use TLS but skip chain & host verification - # insecure_skip_verify = false - - #[[inputs.container.logfilter]] - # filter_message = [ - # ''' 具体指标,参考 [kubernetes](kubernetes) 中的列表 + +### 修改配置 + +修改 `datakit-default.yaml` 中的 dataway 配置 + +```yaml + - name: ENV_DATAWAY + value: https://openway.dataflux.cn?token= # 此处填上具体 token +``` + +### 应用 yaml 配置 + +下载下文 yaml, 直接应用即可: + +```shell +kubectl apply path/to/your.yaml +``` + +### linux work node yaml 配置 + +```yaml +apiVersion: v1 +kind: Namespace +metadata: + name: datakit +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: datakit +rules: +- apiGroups: + - "" + resources: + - nodes + - nodes/proxy + - namespaces + - pods + - services + - endpoints + - persistentvolumes + - persistentvolumeclaims + - ingresses + verbs: + - get + - list + - watch +- apiGroups: + - apps + resources: + - deployments + - daemonsets + - statefulsets + - replicasets + verbs: + - get + - list + - watch +- apiGroups: + - extensions + resources: + - ingresses + verbs: + - get + - list + - watch +- apiGroups: + - batch + resources: + - jobs + - cronjobs + verbs: + - get + - list + - watch +- nonResourceURLs: ["/metrics"] + verbs: ["get"] + +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: datakit + namespace: datakit + +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: datakit +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: datakit +subjects: +- kind: ServiceAccount + name: datakit + namespace: datakit + +--- + +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: daemonset-datakit + name: datakit + namespace: datakit +spec: + revisionHistoryLimit: 10 + selector: + matchLabels: + app: daemonset-datakit + template: + metadata: + labels: + app: daemonset-datakit + spec: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + containers: + - env: + - name: HOST_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.hostIP + - name: NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: ENV_DATAWAY + value: https://openway.dataflux.cn?token= + - name: ENV_GLOBAL_TAGS + value: host=__datakit_hostname,host_ip=__datakit_ip + - name: ENV_ENABLE_INPUTS + value: cpu,disk,diskio,mem,swap,system,hostobject,net,host_processes,kubernetes,container,kube_state_metric + - name: ENV_ENABLE_ELECTION + value: enable + - name: ENV_HTTP_LISTEN + value: 0.0.0.0:9529 + image: pubrepo.jiagouyun.com/datakit/datakit:{{.Version}} + imagePullPolicy: Always + name: datakit + ports: + - containerPort: 9529 + hostPort: 9529 + name: port + protocol: TCP + securityContext: + privileged: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-socket + readOnly: true + - mountPath: /usr/local/datakit/conf.d/container/container.conf + name: datakit-conf + subPath: container.conf + - mountPath: /usr/local/datakit/conf.d/kubernetes/kubernetes.conf + name: datakit-conf + subPath: kubernetes.conf + - mountPath: /host/proc + name: proc + readOnly: true + - mountPath: /host/dev + name: dev + readOnly: true + - mountPath: /host/sys + name: sys + readOnly: true + - mountPath: /rootfs + name: rootfs + workingDir: /usr/local/datakit + hostIPC: true + hostNetwork: true + hostPID: true + restartPolicy: Always + serviceAccount: datakit + serviceAccountName: datakit + volumes: + - configMap: + name: datakit-conf + name: datakit-conf + - hostPath: + path: /var/run/docker.sock + name: docker-socket + - hostPath: + path: /proc + type: "" + name: proc + - hostPath: + path: /dev + type: "" + name: dev + - hostPath: + path: /sys + type: "" + name: sys + - hostPath: + path: / + type: "" + name: rootfs + updateStrategy: + rollingUpdate: + maxUnavailable: 1 + type: RollingUpdate +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + name: kube-state-metrics + namespace: datakit +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: kube-state-metrics + template: + metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + spec: + containers: + - image: pubrepo.jiagouyun.com/metrics-server/kube-state-metrics:v2.1.0 + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + name: kube-state-metrics + ports: + - containerPort: 8080 + name: http-metrics + - containerPort: 8081 + name: telemetry + readinessProbe: + httpGet: + path: / + port: 8081 + initialDelaySeconds: 5 + timeoutSeconds: 5 + securityContext: + runAsUser: 65534 + nodeSelector: + kubernetes.io/os: linux + serviceAccountName: datakit +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + name: kube-state-metrics + namespace: datakit +spec: + type: NodePort + ports: + - name: http-metrics + port: 8080 + targetPort: http-metrics + nodePort: 30022 + - name: telemetry + port: 8081 + targetPort: telemetry + selector: + app.kubernetes.io/name: kube-state-metrics +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: datakit-conf + namespace: datakit +data: + #### container + container.conf: |- + [inputs.container] + endpoint = "unix:///var/run/docker.sock" + + enable_metric = false + enable_object = true + enable_logging = true + + metric_interval = "10s" + + ## TLS Config + # tls_ca = "/path/to/ca.pem" + # tls_cert = "/path/to/cert.pem" + # tls_key = "/path/to/key.pem" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false + + [inputs.container.kubelet] + kubelet_url = "http://127.0.0.1:10255" + + ## Use bearer token for authorization. ('bearer_token' takes priority) + ## If both of these are empty, we'll use the default serviceaccount: + ## at: /run/secrets/kubernetes.io/serviceaccount/token + # bearer_token = "/path/to/bearer/token" + ## OR + # bearer_token_string = "abc_123" + + ## Optional TLS Config + # tls_ca = /path/to/ca.pem + # tls_cert = /path/to/cert.pem + # tls_key = /path/to/key.pem + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false + + #[[inputs.container.logfilter]] + # filter_message = [ + # '''" + - name: ENV_GLOBAL_TAGS + value: host=__datakit_hostname,host_ip=__datakit_ip + - name: ENV_ENABLE_INPUTS + value: kubernetes,kube_state_metric + - name: ENV_ENABLE_ELECTION + value: enable + - name: ENV_HTTP_LISTEN + value: 0.0.0.0:9529 + image: pubrepo.jiagouyun.com/demo/datakit-win:{{.Version}} + imagePullPolicy: Always + name: datakit-win + ports: + - containerPort: 9529 + hostPort: 9529 + name: port + protocol: TCP + securityContext: + privileged: true + hostIPC: true + hostPID: true + restartPolicy: Always + serviceAccount: datakit + serviceAccountName: datakit + updateStrategy: + rollingUpdate: + maxUnavailable: 1 + type: RollingUpdate +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + name: kube-state-metrics + namespace: datakit +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: kube-state-metrics + template: + metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + spec: + containers: + - image: pubrepo.jiagouyun.com/metrics-server/kube-state-metrics:v2.1.0 + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + name: kube-state-metrics + ports: + - containerPort: 8080 + name: http-metrics + - containerPort: 8081 + name: telemetry + readinessProbe: + httpGet: + path: / + port: 8081 + initialDelaySeconds: 5 + timeoutSeconds: 5 + securityContext: + runAsUser: 65534 + nodeSelector: + kubernetes.io/os: linux + serviceAccountName: datakit +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/name: kube-state-metrics + app.kubernetes.io/version: 2.1.0 + name: kube-state-metrics + namespace: datakit +spec: + type: NodePort + ports: + - name: http-metrics + port: 8080 + targetPort: http-metrics + nodePort: 30022 + - name: telemetry + port: 8081 + targetPort: telemetry + selector: + app.kubernetes.io/name: kube-state-metrics +``` ## 指标集 diff --git a/man/manuals/mysql.md.rej b/man/manuals/mysql.md.rej new file mode 100644 index 0000000000..645cef0b56 --- /dev/null +++ b/man/manuals/mysql.md.rej @@ -0,0 +1,55 @@ +diff a/man/manuals/mysql.md b/man/manuals/mysql.md (rejected hunks) +@@ -8,39 +8,35 @@ + + MySQL 指标采集,收集以下数据: + +-- mysql global status 基础数据采集 +-- scheam 相关数据 +-- innodb 相关指标 +-- 主从模式 ++- MySQL global status 基础数据采集 ++- Scheam 相关数据 ++- InnoDB 相关指标 + - 支持自定义查询数据采集 + +-> 主从模式相关的 MySQL 指标采集尚未支持(Comming Soon...) +- + ## 前置条件 + + - MySQL 版本 5.7+ +- + - 创建监控账号(一般情况,需用 MySQL `root` 账号登陆才能创建 MySQL 用户) + + ```sql +- CREATE USER 'datakitMonitor'@'localhost' IDENTIFIED BY ''; +- +- -- MySQL 8.0+ create the datakitMonitor user with the native password hashing method +- CREATE USER 'datakitMonitor'@'localhost' IDENTIFIED WITH mysql_native_password by ''; +-``` ++CREATE USER 'datakit'@'localhost' IDENTIFIED BY ''; + +-备注:`localhost` 是本地连接,具体参考[这里](https://dev.mysql.com/doc/refman/8.0/en/creating-accounts.html) ++-- MySQL 8.0+ create the datakit user with the native password hashing method ++CREATE USER 'datakit'@'localhost' IDENTIFIED WITH mysql_native_password by ''; ++``` + + - 授权 + + ```sql +- GRANT PROCESS ON *.* TO 'datakitMonitor'@'localhost'; +- show databases like 'performance_schema'; +- GRANT SELECT ON performance_schema.* TO 'datakitMonitor'@'localhost'; +- GRANT SELECT ON mysql.user TO 'datakitMonitor'@'%'; +- GRANT replication client on *.* to 'datakitMonitor'@'localhost'; ++GRANT PROCESS ON *.* TO 'datakit'@'localhost'; ++show databases like 'performance_schema'; ++GRANT SELECT ON performance_schema.* TO 'datakit'@'localhost'; ++GRANT SELECT ON mysql.user TO 'datakit'@'localhost'; ++GRANT replication client on *.* to 'datakit'@'localhost'; + ``` + ++>注意:以上创建、授权操作,均限定了 `datakit` 这个用户的只能在 MySQL 主机上(`localhost`)访问 MySQL,如果对 MySQL 进行远程采集,建议将 `localhost` 替换成 `%`(表示 DataKit 可以在任意机器上访问 MySQL),也可用特定的 DataKit 安装机器地址。 ++ + ## 配置 + + 进入 DataKit 安装目录下的 `conf.d/{{.Catalog}}` 目录,复制 `{{.InputName}}.conf.sample` 并命名为 `{{.InputName}}.conf`。示例如下: diff --git a/man/summary.md b/man/summary.md index 52d78d8901..ffd78162dc 100644 --- a/man/summary.md +++ b/man/summary.md @@ -49,8 +49,7 @@ - [Kubernetes]() - [Kubernetes](kubernetes) - - [Kubernetes kube-state-metrics 服务指标采集](kube-state-metrics) - - [Kubernetes 集群中 Exporter 指标采集](kubernetes-prom) + - [Kubernetes 集群中自定义 Exporter 指标采集](kubernetes-prom) - [Java]() - [JVM](jvm) diff --git a/plugins/inputs/all/all.go b/plugins/inputs/all/all.go index 6d33205451..6e6034dcd7 100644 --- a/plugins/inputs/all/all.go +++ b/plugins/inputs/all/all.go @@ -21,6 +21,7 @@ import ( _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/jenkins" _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/jvm" _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/kafka" + _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/kube_state_metric" _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/kubernetes" _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/logging" _ "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs/mem" diff --git a/plugins/inputs/kube_state_metric/kube_state_metric.go b/plugins/inputs/kube_state_metric/kube_state_metric.go new file mode 100644 index 0000000000..257f998476 --- /dev/null +++ b/plugins/inputs/kube_state_metric/kube_state_metric.go @@ -0,0 +1,173 @@ +package kube_state_metric + +import ( + "gitlab.jiagouyun.com/cloudcare-tools/datakit" + "gitlab.jiagouyun.com/cloudcare-tools/datakit/plugins/inputs" +) + +const ( + configSample = ` +[[inputs.prom]] + ## kube-state-metrics Exporter 地址(该ip为任意节点ip地址) + url = "http://kube-state-metrics.datakit.svc.cluster.local:8080/metrics" + + ## 采集器别名 + #input_alias = "kube-state-metric" + + # 只采集 counter 和 gauge 类型的指标 + metric_types = ["counter", "gauge"] + + ## 指标名称过滤 + metric_name_filter = [ + "kube_daemonset_status_current_number_scheduled", + "kube_daemonset_status_desired_number_scheduled", + "kube_daemonset_status_number_available", + "kube_daemonset_status_number_misscheduled", + "kube_daemonset_status_number_ready", + "kube_daemonset_status_number_unavailable", + "kube_daemonset_updated_number_scheduled", + + "kube_deployment_spec_paused", + "kube_deployment_spec_strategy_rollingupdate_max_unavailable", + "kube_deployment_spec_strategy_rollingupdate_max_surge", + "kube_deployment_status_replicas", + "kube_deployment_status_replicas_available", + "kube_deployment_status_replicas_unavailable", + "kube_deployment_status_replicas_updated", + "kube_deployment_status_condition", + "kube_deployment_spec_replicas", + + "kube_endpoint_address_available", + "kube_endpoint_address_not_ready", + + "kube_persistentvolumeclaim_status_phase", + "kube_persistentvolumeclaim_resource_requests_storage_bytes", + "kube_persistentvolumeclaim_access_mode", + + "kube_persistentvolume_status_phase", + "kube_persistentvolume_capacity_bytes", + + "kube_secret_type", + + "kube_replicaset_status_replicas", + "kube_replicaset_status_fully_labeled_replicas", + "kube_replicaset_status_ready_replicas", + "kube_replicaset_status_observed_generation", + + "kube_statefulset_status_replicas", + "kube_statefulset_status_replicas_current", + "kube_statefulset_status_replicas_ready", + "kube_statefulset_status_replicas_updated", + "kube_statefulset_status_observed_generation", + "kube_statefulset_replicas", + + "kube_hpa_spec_max_replicas", + "kube_hpa_spec_min_replicas", + "kube_hpa_spec_target_metric", + "kube_hpa_status_current_replicas", + "kube_hpa_status_desired_replicas", + "kube_hpa_status_condition", + + "kube_cronjob_status_active", + "kube_cronjob_spec_suspend", + "kube_cronjob_status_last_schedule_time", + + "kube_job_status_succeeded", + "kube_job_status_failed", + "kube_job_status_active", + "kube_job_complete", + ] + + interval = "10s" + + ## 自定义指标集名称 + [[inputs.prom.measurements]] + ## daemonset + prefix = "kube_daemonset_" + name = "kube_daemonset" + + [[inputs.prom.measurements]] + ## daemonset + prefix = "kube_deployment_" + name = "kube_deployment" + + [[inputs.prom.measurements]] + ## endpoint + prefix = "kube_endpoint_" + name = "kube_endpoint" + + [[inputs.prom.measurements]] + ## persistentvolumeclaim + prefix = "kube_persistentvolumeclaim_" + name = "kube_persistentvolumeclaim" + + [[inputs.prom.measurements]] + ## persistentvolumeclaim + prefix = "kube_persistentvolume_" + name = "kube_persistentvolume" + + [[inputs.prom.measurements]] + ## secret + prefix = "kube_secret_" + name = "kube_secret" + + [[inputs.prom.measurements]] + ## replicaset + prefix = "kube_replicaset_" + name = "kube_replicaset" + + [[inputs.prom.measurements]] + ## statefulset + prefix = "kube_statefulset_" + name = "kube_statefulset" + + [[inputs.prom.measurements]] + ## hpa + prefix = "kube_hpa_" + name = "kube_hpa" + + [[inputs.prom.measurements]] + ## cronjob + prefix = "kube_cronjob_" + name = "kube_cronjob" + + [[inputs.prom.measurements]] + ## job + prefix = "kube_job_" + name = "kube_job" + + ## 自定义Tags + [inputs.prom.tags] + #tag1 = "value1" + #tag2 = "value2" +` +) + +var ( + inputName = "kube_state_metric" + catalogName = "prom" +) + +type Input struct { +} + +func (i *Input) Run() { +} + +func (i *Input) Catalog() string { return catalogName } + +func (i *Input) SampleConfig() string { return configSample } + +func (i *Input) SampleMeasurement() []inputs.Measurement { + return []inputs.Measurement{} +} + +func (i *Input) AvailableArchs() []string { + return []string{datakit.OSArchLinuxAmd64} +} + +func init() { + inputs.Add(inputName, func() inputs.Input { + return &Input{} + }) +} diff --git a/plugins/inputs/kubernetes/cfg_win.conf b/plugins/inputs/kubernetes/cfg_win.conf new file mode 100644 index 0000000000..1a2c9f1c9c --- /dev/null +++ b/plugins/inputs/kubernetes/cfg_win.conf @@ -0,0 +1,20 @@ +[[inputs.kubernetes]] + # required + interval = "10s" + ## URL for the Kubernetes API + url = "https://kubernetes.default:443" + ## Use bearer token for authorization. ('bearer_token' takes priority) + bearer_token = '''C:\var\run\secrets\kubernetes.io\serviceaccount\token''' + + ## Set http timeout (default 5 seconds) + timeout = "5s" + + ## Optional TLS Config + tls_ca = '''C:\var\run\secrets\kubernetes.io\serviceaccount\ca.crt''' + + ## Use TLS but skip chain & host verification + insecure_skip_verify = false + + [inputs.kubernetes.tags] + # tag1 = "val1" + # tag2 = "val2" \ No newline at end of file diff --git a/plugins/inputs/kubernetes/conf.go b/plugins/inputs/kubernetes/conf.go index 394c481a1c..d27117d26c 100644 --- a/plugins/inputs/kubernetes/conf.go +++ b/plugins/inputs/kubernetes/conf.go @@ -1,7 +1,7 @@ package kubernetes const ( - configSample = ` + configSampleLinux = ` [[inputs.kubernetes]] # required interval = "10s" @@ -20,6 +20,29 @@ const ( ## Use TLS but skip chain & host verification insecure_skip_verify = false + [inputs.kubernetes.tags] + # tag1 = "val1" + # tag2 = "val2" +` + + configSampleWin = ` +[[inputs.kubernetes]] + # required + interval = "10s" + ## URL for the Kubernetes API + url = "https://kubernetes.default.svc.cluster.local:443" + ## Use bearer token for authorization. ('bearer_token' takes priority) + bearer_token = '''C:\var\run\secrets\kubernetes.io\serviceaccount\token''' + + ## Set http timeout (default 5 seconds) + timeout = "5s" + + ## Optional TLS Config + tls_ca = '''C:\var\run\secrets\kubernetes.io\serviceaccount\ca.crt''' + + ## Use TLS but skip chain & host verification + insecure_skip_verify = false + [inputs.kubernetes.tags] # tag1 = "val1" # tag2 = "val2" diff --git a/plugins/inputs/kubernetes/input.go b/plugins/inputs/kubernetes/input.go index 9edcc96513..6d38678512 100644 --- a/plugins/inputs/kubernetes/input.go +++ b/plugins/inputs/kubernetes/input.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "sync" "time" @@ -261,7 +262,13 @@ func (i *Input) clear() { func (i *Input) Catalog() string { return catalogName } -func (i *Input) SampleConfig() string { return configSample } +func (i *Input) SampleConfig() string { + if runtime.GOOS == "windows" { + return configSampleWin + } + + return configSampleLinux +} func (i *Input) AvailableArchs() []string { return datakit.AllArch diff --git a/plugins/inputs/kubernetes/input_test.go b/plugins/inputs/kubernetes/input_test.go index 6fe757ef82..632f0a38c7 100644 --- a/plugins/inputs/kubernetes/input_test.go +++ b/plugins/inputs/kubernetes/input_test.go @@ -59,6 +59,22 @@ func TestInitCfgErr(t *testing.T) { t.Log("version ==>", versionInfo.String()) } +func TestLoadWinCfg(t *testing.T) { + arr, err := config.LoadInputConfigFile("./cfg_win.conf", func() inputs.Input { + return &Input{} + }) + + if err != nil { + t.Fatalf("%s", err) + } + + kube := arr[0].(*Input) + + t.Log("url ---->", kube.URL) + t.Log("token ---->", kube.BearerToken) + t.Log("ca ---->", kube.TLSCA) +} + func TestLoadCfg(t *testing.T) { arr, err := config.LoadInputConfigFile("./cfg.conf", func() inputs.Input { return &Input{} diff --git a/plugins/inputs/mysql/user.go b/plugins/inputs/mysql/user.go index 24c4b07d69..393551dcc4 100644 --- a/plugins/inputs/mysql/user.go +++ b/plugins/inputs/mysql/user.go @@ -135,7 +135,6 @@ func (i *Input) getUserData() ([]inputs.Measurement, error) { } // run query - l.Info("sql query", userSql) rows, err := i.db.Query(userSql) if err != nil { l.Errorf("query %v error %v", userSql, err)