diff --git a/README.md b/README.md index 95dd604..fa6704d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ # Quick Start + +Clone this repo first. You'll need local files: ```sh git clone https://github.com/lomik/graphite-clickhouse-tldr cd graphite-clickhouse-tldr +``` + +## Docker-Compose +```sh +cd compose docker-compose up ``` Open http://127.0.0.1/ in browser @@ -13,4 +20,30 @@ Host | Container | Service 80 | 80 | [nginx](https://www.nginx.com/resources/admin-guide/) 2003 | 2003 | [carbon receiver - plaintext](http://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol) 2004 | 2004 | [carbon receiver - pickle](http://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-pickle-protocol) -2006 | 2006 | [carbon receiver - prometheus remote write](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cremote_write%3E) \ No newline at end of file +2006 | 2006 | [carbon receiver - prometheus remote write](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cremote_write%3E) + +# Kubernetes + +This install assumes you can install the clickhouse-operator in the kube-system namespace. +See https://github.com/Altinity/clickhouse-operator/blob/master/docs/quick_start.md#clickhouse-operator-installation + +## Setup + +```sh +cd k8s +./ch-operator-install.sh +sleep 10 #wait for operator +kubectl apply -f stats-conf.yaml #note, you may need to tweak +``` + +## Running + +```sh +kubectl apply -f ch-stats.yaml +sleep 10 #you should watch for clickhouse to finish coming up: +watch kubectl get pods # ctrl-c out when the pods are ready +kubectl apply -f services.yaml +watch kubectl get pods # ctrl-c out when services are online +kubectl port-forward service/stat-web 9000:80 +``` +Open http://127.0.0.1:9000/ in your browser diff --git a/carbon-clickhouse.conf b/compose/carbon-clickhouse.conf similarity index 96% rename from carbon-clickhouse.conf rename to compose/carbon-clickhouse.conf index 5da761e..98daee4 100644 --- a/carbon-clickhouse.conf +++ b/compose/carbon-clickhouse.conf @@ -4,10 +4,13 @@ metric-prefix = "carbon.agents.{host}" # Endpoint for store internal carbon metrics. Valid values: "" or "local", "tcp://host:port", "udp://host:port" metric-endpoint = "local" # Interval of storing internal metrics. Like CARBON_METRIC_INTERVAL -metric-interval = "1m0s" +metric-interval = "5s" # GOMAXPROCS max-cpu = 1 +[convert_to_tagged] +enabled = false + [logging] # "stderr", "stdout" can be used as file name file = "stdout" diff --git a/client.sh b/compose/client.sh similarity index 100% rename from client.sh rename to compose/client.sh diff --git a/docker-compose.yaml b/compose/docker-compose.yaml similarity index 92% rename from docker-compose.yaml rename to compose/docker-compose.yaml index 89cf739..f159398 100644 --- a/docker-compose.yaml +++ b/compose/docker-compose.yaml @@ -24,8 +24,10 @@ graphite-clickhouse: - "./graphite-clickhouse.conf:/etc/graphite-clickhouse/graphite-clickhouse.conf" links: - clickhouse + ports: + - "9090:9090" # http api access graphite-web: - image: graphiteapp/graphite-statsd:1.1.3 + image: graphiteapp/graphite-statsd:1.1.7-3 volumes: - "./graphiteweb_entrypoint.sh:/entrypoint.sh" - "./graphiteweb.conf:/opt/graphite/webapp/graphite/local_settings.py" diff --git a/graphite-clickhouse.conf b/compose/graphite-clickhouse.conf similarity index 100% rename from graphite-clickhouse.conf rename to compose/graphite-clickhouse.conf diff --git a/graphiteweb.conf b/compose/graphiteweb.conf similarity index 100% rename from graphiteweb.conf rename to compose/graphiteweb.conf diff --git a/graphiteweb_entrypoint.sh b/compose/graphiteweb_entrypoint.sh similarity index 100% rename from graphiteweb_entrypoint.sh rename to compose/graphiteweb_entrypoint.sh diff --git a/init.sql b/compose/init.sql similarity index 100% rename from init.sql rename to compose/init.sql diff --git a/rollup.xml b/compose/rollup.xml similarity index 100% rename from rollup.xml rename to compose/rollup.xml diff --git a/k8s/ch-operator-install.sh b/k8s/ch-operator-install.sh new file mode 100755 index 0000000..dccdd73 --- /dev/null +++ b/k8s/ch-operator-install.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e + +OPERATOR_NS=${OPERATOR_NS:-kube-system} +kubectl apply -f https://raw.githubusercontent.com/Altinity/clickhouse-operator/master/deploy/operator/clickhouse-operator-install.yaml -n $OPERATOR_NS \ No newline at end of file diff --git a/k8s/ch-stats.yaml b/k8s/ch-stats.yaml new file mode 100644 index 0000000..bcc6208 --- /dev/null +++ b/k8s/ch-stats.yaml @@ -0,0 +1,96 @@ +apiVersion: "clickhouse.altinity.com/v1" +kind: "ClickHouseInstallation" +metadata: + name: "stats" +spec: + defaults: + templates: + dataVolumeClaimTemplate: volume-template + logVolumeClaimTemplate: log-volume-template + serviceTemplate: chi-service-template + podTemplate: clickhouse:19.6 + configuration: + users: + default/networks/ip: + - "10.0.0.0/8" + - "127.0.0.1/32" + clusters: + - name: "default" + layout: + shardsCount: 1 + replicasCount: 1 + files: + logs.xml: | + + + warning + /var/log/clickhouse-server/clickhouse-server.log + /var/log/clickhouse-server/clickhouse-server.err.log + 1000M + 10 + + + rollup.xml: | + + + Path + Time + Value + Timestamp + + avg + + 0 + 60 + + + 2592000 + 3600 + + + + + templates: + podTemplates: + - name: clickhouse:19.6 + spec: + volumes: + - name: stats-conf + configMap: + name: stats-conf + containers: + - name: clickhouse-pod + image: yandex/clickhouse-server:19.6.2.11 + volumeMounts: + - name: stats-conf + mountPath: /docker-entrypoint-initdb.d/init.sql + subPath: init.sql + serviceTemplates: + - name: chi-service-template + generateName: "ch-stats" + spec: + ports: + - name: http + port: 80 + targetPort: 8123 + - name: client + port: 9440 + targetPort: 9000 + type: ClusterIP + volumeClaimTemplates: + - name: volume-template + spec: + storageClassName: gp2 + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 15Gi + - name: log-volume-template + spec: + storageClassName: gp2 + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi diff --git a/k8s/services.yaml b/k8s/services.yaml new file mode 100644 index 0000000..2a2b3b7 --- /dev/null +++ b/k8s/services.yaml @@ -0,0 +1,195 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: stat-relay + component: carbon + name: stat-relay + namespace: stats +spec: + replicas: 3 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: stat-relay + component: carbon + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app: stat-relay + component: carbon + spec: + containers: + - image: lomik/carbon-clickhouse:v0.10.2 + resources: {} + imagePullPolicy: IfNotPresent + name: stat-relay + ports: + - containerPort: 2003 + name: plaintext + protocol: TCP + - containerPort: 2004 + name: pickle + protocol: TCP + volumeMounts: + - name: stats-conf + mountPath: /etc/carbon-clickhouse/carbon-clickhouse.conf + subPath: carbon.relay.conf + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumes: + - name: stats-conf + configMap: + name: stats-conf + restartPolicy: Always + terminationGracePeriodSeconds: 30 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: stat-api + component: graphite + name: stat-api + namespace: stats +spec: + replicas: 3 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: stat-api + component: graphite + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app: stat-api + component: graphite + spec: + containers: + - image: lomik/graphite-clickhouse:v0.11.1 + imagePullPolicy: IfNotPresent + name: stat-api + ports: + - containerPort: 9090 + name: http + protocol: TCP + resources: + requests: + cpu: 700m + memory: 6Gi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - name: stats-conf + mountPath: /etc/graphite-clickhouse/graphite-clickhouse.conf + subPath: graphite.api.conf + - name: stats-conf + mountPath: /etc/graphite-clickhouse/rollup.xml + subPath: rollup.xml + restartPolicy: Always + volumes: + - name: stats-conf + configMap: + name: stats-conf + terminationGracePeriodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: stat-api + name: stat-api + namespace: stats +spec: + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 9090 + selector: + app: stat-api + sessionAffinity: None + type: ClusterIP +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: stat-web + component: web + name: stat-web + namespace: stats +spec: + progressDeadlineSeconds: 2147483647 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: stat-web + component: web + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app: stat-web + component: web + spec: + containers: + - image: gographite/carbonapi:v0.13.0 + imagePullPolicy: IfNotPresent + name: stat-web + ports: + - containerPort: 80 + name: http + protocol: TCP + resources: + requests: + cpu: 300m + memory: 512Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - name: stats-conf + mountPath: /etc/carbonapi.yml + subPath: carbonapi.yml + restartPolicy: Always + volumes: + - name: stats-conf + configMap: + name: stats-conf + terminationGracePeriodSeconds: 30 +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: stat-web + name: stat-web + namespace: stats +spec: + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 80 + selector: + app: stat-web + sessionAffinity: None + type: ClusterIP \ No newline at end of file diff --git a/k8s/stats-conf.yaml b/k8s/stats-conf.yaml new file mode 100644 index 0000000..eab39a2 --- /dev/null +++ b/k8s/stats-conf.yaml @@ -0,0 +1,163 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: stats-conf + labels: + app: graphite +data: + carbon.relay.conf: | + [common] + # Prefix for store all internal carbon-clickhouse graphs. Supported macroses: {host} + metric-prefix = "carbon.agents.{host}" + # Endpoint for store internal carbon metrics. Valid values: "" or "local", "tcp://host:port", "udp://host:port" + metric-endpoint = "local" + # Interval of storing internal metrics. Like CARBON_METRIC_INTERVAL + metric-interval = "10s" + # GOMAXPROCS + max-cpu = 1 + + [logging] + # "stderr", "stdout" can be used as file name + file = "stdout" + # Logging error level. Valid values: "debug", "info", "warn" "error" + level = "warn" + + [data] + # Folder for buffering received data + path = "/data/carbon-clickhouse/" + # Rotate (and upload) file interval. + # Minimize chunk-interval for minimize lag between point receive and store + chunk-interval = "1s" + # Auto-increase chunk interval if the number of unprocessed files is grown + # Sample, set chunk interval to 10 if unhandled files count >= 5 and set to 60s if unhandled files count >= 20: + # chunk-auto-interval = "5:10s,20:60s" + chunk-auto-interval = "5:5s,10:60s" + + [upload.graphite_reverse] + type = "points-reverse" + table = "graphite_reverse" + threads = 1 + url = "http://ch-stats/" + timeout = "1m0s" + + [upload.graphite_index] + type = "index" + table = "graphite_index" + threads = 1 + url = "http://ch-stats/" + timeout = "1m0s" + cache-ttl = "12h0m0s" + + [upload.graphite_tagged] + type = "tagged" + table = "graphite_tagged" + threads = 1 + url = "http://ch-stats/" + timeout = "1m0s" + cache-ttl = "12h0m0s" + + [udp] + listen = ":2003" + enabled = false + + [tcp] + listen = ":2003" + enabled = true + + [pickle] + listen = ":2004" + enabled = true + + [prometheus] + listen = ":2006" + enabled = false + + # https://github.com/lomik/carbon-clickhouse/blob/master/grpc/carbon.proto + [grpc] + listen = ":2005" + enabled = false + + [pprof] + listen = "localhost:7007" + enabled = false + graphite.api.conf: | + [common] + listen = ":9090" + max-cpu = 8 + + [clickhouse] + url = "http://ch-stats/?max_query_size=268435456&max_ast_elements=1000000" + index-table = "graphite_index" + data-timeout = "1m0s" + index-timeout = "1m0s" + tagged-table = "graphite_tagged" + + [[data-table]] + table = "graphite_reverse" + reverse = true + rollup-conf = "/etc/graphite-clickhouse/rollup.xml" + + [logging] + file = "stdout" + level = "info" + carbonapi.yml: | + listen: 0.0.0.0:80 + upstreams: + backends: + - http://stat-api + logger: + - logger: "" + file: "stdout" + level: "warn" + encoding: "console" + tagdb: + url: "http://stat-api:9090" + init.sql: | + CREATE TABLE IF NOT EXISTS default.graphite_reverse ( + Path String, + Value Float64, + Time UInt32, + Date Date, + Timestamp UInt32 + ) ENGINE = GraphiteMergeTree('graphite_rollup') + PARTITION BY toYYYYMM(Date) + ORDER BY (Path, Time); + + CREATE TABLE IF NOT EXISTS default.graphite_index ( + Date Date, + Level UInt32, + Path String, + Version UInt32 + ) ENGINE = ReplacingMergeTree(Version) + PARTITION BY toYYYYMM(Date) + ORDER BY (Level, Path, Date); + + CREATE TABLE IF NOT EXISTS default.graphite_tagged ( + Date Date, + Tag1 String, + Path String, + Tags Array(String), + Version UInt32 + ) ENGINE = ReplacingMergeTree(Version) + PARTITION BY toYYYYMM(Date) + ORDER BY (Tag1, Path, Date); + rollup.xml: | + + + Path + Time + Value + Timestamp + + avg + + 0 + 60 + + + 2592000 + 3600 + + + + \ No newline at end of file