Skip to content

Commit

Permalink
Send metrics in Splunk way.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gimi Liang committed Mar 23, 2018
1 parent 849b20d commit f2616d6
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 19 deletions.
3 changes: 0 additions & 3 deletions charts/splunk-kubernetes-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@ Component | Description | Template
`Daemonset` | deploys one pod that runs fluentd on each node to collect logs. | [daemonset.yaml](templates/daemonset.yaml)
`ConfigMap` | contains configuration files for fluentd. | [configmap.yaml](templates/configmap.yaml)
`Secret` | stores credentials like the Splunk HEC token, and SSL certs and keys for HTTPS connection, etc. | [secret.yaml](templates/secret.yaml)
`ServiceAccount` | a service account for the daemonset. | [serviceAccount.yaml](templates/serviceAccount.yaml)
`ClusterRole` | defines permissions needed by the service account. | [clusterrole.yaml](templates/clusterrole.yaml)
`ClusterRoleBinding` | binds the cluster role to the service account. | [clusterrolebinding.yaml](templates/clusterrolebinding.yaml)
5 changes: 3 additions & 2 deletions charts/splunk-kubernetes-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ Component | Description | Template
`ConfigMap` | contains configuration files for fluentd. | [configmap.yaml](templates/configmap.yaml)
`Secret` | stores credentials like the Splunk HEC token, and SSL certs and keys for HTTPS connection, etc. | [secret.yaml](templates/secret.yaml)
`ServiceAccount` | a service account for the daemonset. | [serviceaccount.yaml](templates/serviceaccount.yaml)
`ClusterRole` | defines permissions needed by the service account. | [clusterrole.yaml](templates/clusterrole.yaml)
`ClusterRoleBinding` | binds the cluster role to the service account. | [clusterrolebinding.yaml](templates/clusterrolebinding.yaml)
`ClusterRoleBinding` | binds the system:heapster cluster role to the service account. | [clusterrolebinding.yaml](templates/clusterrolebinding.yaml)

Note: when `disableRBAC` is set to `true` (it should be when RBAC is not enabled in the kubernetes cluster), `ServiceAccount`, `ClusterRole`, and `ClusterRoleBinding` won't be created.
52 changes: 52 additions & 0 deletions charts/splunk-kubernetes-metrics/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,55 @@ Create chart name and version as used by the chart label.
{{- define "splunk-kubernetes-metrics.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}


{{/*
The jq filter used to transform Heapster metrics which are formatted in statd format.
Define it as a template here so there we don't need to escape the double quotes `` " ''.
*/}}
{{- define "splunk-kubernetes-metrics.jq_filter" -}}
def extract_labels:
. as $labels | reduce range(length) as $n ({}; if $n % 2 == 0 then .["label." + $labels[$n]] = $labels[$n + 1] else . end);
def extract_metric:
if length % 2 == 0
then (.[:-2] | extract_labels) + {metric: (.[-2] | gsub("/"; ".")), resource_id: .[-1]}
else (.[:-1] | extract_labels) + {metric: (.[-1] | gsub("/"; "."))}
end;
def extract_container:
split(".") | {container_type: "pod", node: .[1], namespace: .[3], pod: .[5], container: .[7]} + (.[8:] | extract_metric) | .metric = "container." + .metric | . ;
def extract_syscontainer:
split(".") | {container_type: "sys", node: .[1], container: .[3]} + (.[4:] | extract_metric) | .metric = "container." + .metric | . ;
def extract_pod:
split(".") | {node: .[1], namespace: .[3], pod: .[5]} + (.[6:] | extract_metric) | .metric = "pod." + .metric | . ;
def extract_namespace:
split(".") | {namespace: .[1]} + (.[2:] | extract_metric) | .metric = "namespace." + .metric | . ;
def extract_node:
split(".") | {node: .[1]} + (.[2:] | extract_metric) | .metric = "node." + .metric | . ;
def extract_cluster:
split(".") | .[1:] | extract_metric | .metric = "cluster." + .metric | . ;
def extract:
if contains(".container.")
then extract_container
elif contains(".sys-container.")
then extract_syscontainer
elif contains(".pod.")
then extract_pod
elif startswith("namespace.")
then extract_namespace
elif startswith("node.")
then extract_node
elif startswith("cluster.")
then extract_cluster
else {}
end;
"heapster/namespace:\(env.MY_NAMESPACE)/pod:\(env.MY_POD_NAME)" as $source | .record | to_entries | map({value, source: $source} + (.key | extract)) | .
{{- end -}}
10 changes: 9 additions & 1 deletion charts/splunk-kubernetes-metrics/templates/configMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data:
<source>
@type udp
tag metrics.udp
tag raw.metrics.udp
port 9001
message_length_limit 100m
<parse>
Expand All @@ -25,9 +25,17 @@ data:
</parse>
</source>
<match raw.metrics.udp>
@type jq
jq {{ include "splunk-kubernetes-metrics.jq_filter" . | quote }}
remove_tag_prefix raw
</match>
<match metrics.udp>
@type splunk_hec
data_type metric
metric_name_key metric
metric_value_key value
protocol {{ or .Values.splunk.hec.protocol .Values.global.splunk.hec.protocol | default "https" }}
hec_host {{ required "splunk.hec.host is required." (or .Values.splunk.hec.host .Values.global.splunk.hec.host) }}
{{- with $hecPort := or .Values.splunk.hec.port .Values.global.splunk.hec.port }}
Expand Down
10 changes: 9 additions & 1 deletion charts/splunk-kubernetes-metrics/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
timeoutSeconds: 5
resources:
{{ toYaml .Values.resources | indent 12 }}
- image: gimil/k8s-l:0.0.9
- image: gimil/k8s-l:0.0.10
name: splunk-fluentd-heapster
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
Expand All @@ -69,6 +69,14 @@ spec:
- -c
- /fluentd/etc/fluent.conf
env:
- name: MY_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: SPLUNK_HEC_HOST
valueFrom:
fieldRef:
Expand Down
38 changes: 26 additions & 12 deletions charts/splunk-kubernetes-metrics/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,32 @@ disableRBAC: false

# = Splunk UDP Connection =
splunk:
# configurations for Splunk UDP input. [REQUIRED]
udp:
# hostname / IP of the Splunk instance which has the UDP input enabled.
# Configurations for HEC (HTTP Event Collector)
hec:
# host is required and should be provided by user
host:
# port of the UDP input
# port to HEC, optional, default 8088
port:
# token is required and should be provided by user
token:
# protocol has two options: "http" and "https", default is "https"
protocol:
# indexName tells which index to use, this is optional. If it's not present, will use the default one configured in HEC.
indexName:
# insecureSSL is a boolean, it indecates should it allow inscure SSL connection (when protocol is "https"). Default is false.
insecureSSL:
# The PEM-format CA certificate for this client.
# NOTE: The content of the certificate itself should be used here, not the file path.
# The certificate will be stored as a secret in kubernetes.
clientCert:
# The private key for this client.
# NOTE: The content of the key itself should be used here, not the file path.
# The key will be stored as a secret in kubernetes.
clientKey:
# The PEM-format CA certificate file.
# NOTE: The content of the file itself should be used here, not the file path.
# The file will be stored as a secret in kubernetes.
caFile:


# = Global Configs =
Expand All @@ -36,7 +56,6 @@ global:
logLevel:
splunk:
hec: {}
udp: {}


image:
Expand All @@ -48,10 +67,10 @@ resources:
# keep request = limit to keep this container in guaranteed class
limits:
cpu: 100m
memory: 200Mi
memory: 300Mi
requests:
cpu: 100m
memory: 200Mi
memory: 300Mi


nodeSelector: {}
Expand All @@ -65,8 +84,3 @@ tolerations: []


affinity: {}


service:
port: 80
targetPort: 8082
2 changes: 2 additions & 0 deletions charts/splunk-kubernetes-objects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ Component | Description | Template
`ServiceAccount` | a service account for the daemonset. | [serviceaccount.yaml](templates/serviceaccount.yaml)
`ClusterRole` | defines permissions needed by the service account. | [clusterrole.yaml](templates/clusterrole.yaml)
`ClusterRoleBinding` | binds the cluster role to the service account. | [clusterrolebinding.yaml](templates/clusterrolebinding.yaml)

Note: when `disableRBAC` is set to `true` (it should be when RBAC is not enabled in the kubernetes cluster), `ServiceAccount`, `ClusterRole`, and `ClusterRoleBinding` won't be created.

0 comments on commit f2616d6

Please sign in to comment.