7,540
edits
Changes
no edit summary
:[[File:ClipCapIt-190807-102633.PNG]]
<br>
=== Http test application ===
The Kubernetes install files can be found at the root of the git repository.
* http://test-app-service-mynamespace.192.168.42.185.nip.io/test/slowresponse/ <delay in millisecundum>
* http://test-app-service-mynamespace.192.168.42.185.nip.io/test/slowresponse/ <delay in milliseconds> / <http response code>
<br>
=Using HAproxy metrika végpont használataMetric Endpoint=A HAproxyhas a built-nak van beépített metrika végpontjain metric endpoint, ahol alapértelmezetten which by default provides Prometheus szabványú metrikákat szolgáltat (tud még CSV-tis)metrics, but most of its metrics are not really usable. Az így nyert metrikák nagy része nem igazán értelmes metrikákThere are two metric types that are worth mentioning. Két olyan metrikát tudunk innen kinyerniOne of them counts the responses with 200 http code, ami mindenképpen figyelendő prometheus-ban, ezek a hibás és 200-as válaszok számlálói backend-ekre lebontvaand the other counts the responses with 500 (bad request).
:[[File:ClipCapIt-190808-094455.PNG|600px]]
<br>
==Metrikák lekérdezéseQuery Metrics ==A metrikák lekérdezésére két lehetőség vanThere are two ways to query metrics. # felhasználó név Basic authentication with username + jelszó használatapassword: Basic authentikácóval a /metrics végpontot meghívva le lehet kérdezni a metrikákat. http endpoint# Authentication with Kubernetes RBAC szabályok definiálása a megfelelő serviceAccount -hozRules: Gépi feldolgozásra For machine processing (e.g. in Prometheus) lehetőség van rá, hogy it is possible to enable RBAC szabályokkal engedélyezzük egy adott rule based authentication for a given service-account-nak hogy lekérdezze a metrikákat.
<br>
===User + jelszó alapú lekérdezés password based authentication ===
<pre>
http://<user>:<password>@<router_IP>:<STATS_PORT>/metrics
<pre>
# kubectl get svc -n default
router ClusterIP 172.30.130.191 <none> 80/TCP,443/TCP,1936/TCP 4d
</pre>
<source lang="C++">
# kubectl get svc router -n default -o yaml
<pre>
# curl admin:4v9a7ucfMi@192.168.42.64:1936/metrics
# HELP apiserver_audit_event_total Counter of audit events generated and sent to the audit backend.
===ServiceAccount alapú lekérdezésbased authentication ===Lehetőség van rá, hogy ne csak It is possible to query the HAproxy metrics not only with basic authentication-el kérdezzük le a HAproxy metrikákat, hanem but also with RBAC szabályokkalrules.
<br>
'''cr-prometheus-server-route.yaml'''
<br>
'''crb-prometheus-server-route.yaml'''
namespace: mynamespace
</source>
<pre>
# kubectl apply -f cr-prometheus-server-route.yaml
<br>
==Prometheus integrációintegration==
<pre>
# kubectl get Endpoints router -n default -o yaml
<br>
<br>
- job_name: 'openshift-router'
scheme: https
action: keep
regex: router;1936-tcp
</presource>
<pre>
# kubectl apply -f cm-prometheus-server-haproxy.yaml
</pre>
<pre>
# kubectl logs -c prometheus-server-configmap-reload prometheus-server-75c9d576c9-gjlcr -n mynamespace
</pre>
<pre>
# kubectl logs -c prometheus-server prometheus-server-75c9d576c9-gjlcr -n mynamespace
...
level=info ts=2019-07-22T20:25:36.016Z caller=main.go:730 msg="Loading configuration file" filename=/etc/config/prometheus.yml
</pre>
<br>
<br>
<br>
===haproxy_server_http_responses_total===Megmutatja backend-enként hogy hángy It is a Prometheus counter, shows how many 200-as és hány and 500-as http státuszú választ adott egy adott replies a given servicegave per backend. Itt nincs pod alapú bontásIt is on service level only. Sajnos a Unfortunately, we do not receive information on http 300 és and 400-as hibákról nem kapunk információterrors. Ezeket is majd az We will also get these from the access log-ból tudjuk kinyerni
<br>
<br>
<pre>
haproxy_server_http_responses_total{code="2xx",jobJob ="openshift-router",namespace="mynamespace",pod="testbody-app",route="testbody-app-service",service="testbody-app-service"} 1
</pre>
<br>
<pre>
haproxy_server_http_responses_total{code="5xx",job="openshift-router",namespace="mynamespace",pod="testbody-app",route="testbody-app-service",service="testbody-app-service"} 1
</pre>
<br>
===haproxy_server_response_errors_total===Counter type
<pre>
haproxy_server_response_errors_total{instance="192.168.122.223:1936",job="openshift-router",namespace="mynamespace",pod="test-app-57574c8466-pvcsg",route="test-app-service",server="172.17.0.17:8080",service="test-app-service"}
<br>
=Metrikák gyűjtése logokbólCollecting metrics from the access logs=
==Overview==
The task is to process the access log of HAproxy with a log interpreter parser and generate Prometheus metrics that must be made are available to for Prometheus at through an HTTP endpoint. We will use the grok-exporter tool, which can do this in one personboth. It can read logs from a file or stdin and generate metrics from itbased on the logs. The grok-exporter will receive the logs from HAproxy via a packaged an rsyslog server. Rsyslog puts will put logs into a file from which grok-exporter will be able to read them. Grok-exporter converts logs into promethues metrics.
Necessary steps: * You need We have to create a docker image from grok-exporter that has rsyslogin the image. (The container must be able to run the rsyslog server as root, which requires extra openShfit configuration.)* The grok-exporter image must configuration will be run on in OpenShfit with both the grok-exporter configuration configured in ConfigMap and the rsyslog workspace with must be an OpenSfhit OpenShift volume.(writing a containers file system in runtime is really inefficient) * For grok-exporter deployment, you need We have to create a ClasterIP-type service that can perform load-balancing between grok-exporter pods.* Routers (The HAproxy) routers should be configured to log write access logs in debug mode and send them to the resulting access log remote rsyslog server running next to port 514 of the grok-exporter service.* The rsyslog server running on in the grok-exporter pod puts will both write the received HAproxy access logs into the file ('' '/ var / log / messages' '(' - emptyDir type volume) and sends it them to' '' stdout ''' as well for central log processing.* Logs written to stdout will be collected picked up by the docdocker-log-driver and forwarded to the centralized log architecture.(log retention) * The grok-exporter program reads '' '/ var / log / messages' '', and generates prometheus Prometheus metrics from its the HAproxy access-logs.* The configuration of promethues should Prometheus scrape config has to be configured to use extended with a '' 'kubernetes_sd_configs' '' to section. Prometheus must collect the metrics directly invoke from the grok proxy -exporter pods to collect the metric, not to go through the Kubernetes service to bypass load-balancing, since everything pod needs to be queried.
<br>
==HAproxy log struktúrastructure==
https://www.haproxy.com/blog/introduction-to-haproxy-logging/
<br>
<pre>
Aug 6 20:53:30 192.168.122.223 haproxy[39]: 192.168.42.1:50708 [06/Aug/2019:20:53:30.267] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.12:8080 1/0/0/321/321 200 135 - - --NI 2/2/0/1/0 0/0 "GET /test/slowresponse/1 HTTP/1.1"
<br>
<br>
<br>
==introduction of grok-exporter bemutatása==A grokGrok-exporter egy olyan eszköz, ami logokat képes reguláris kifejezések alapján feldolgozni, amiből elő tudja állítani is a tool that can process logs based on regular expressions and convert them to one of the 4 alapvető prometheus metrika típustbasic Prometheus metrics:
* gauge
* counter
* kvantilis
https://github.com/fstab/grok_exporter/blob/master/CONFIG.md<br>
<br>
<br>
===Alternatív megoldásokAlternative Solutions ==='''Fluentd''':<br>A '''To achieve the same goal with fluentd'''-vel is megoldható a feladat. Ehhez három , we would need three fluentd plugin-t kell használni (ezt nem probáltam ki)plugins:
* fluent-plugin-rewrite-tag-filter
* fluent-plugin-prometheus
'''mtail''':<br>
https://github.com/google/mtail
<br>
===Config fájlConfiguration file===A The configuration of grok-exporter konfigurációja a can be found in '''/etc/grok_exporter/config.yml''' fájlban van. There are 5 részre osztható sections.
* global:
* input: Megmondja, hogy honnan és hogyan olvassa Tells you where and how to retrieve logs. Can be a logokat. Lehet stdin, file és and webhook. Mi a We will use file inputot fogjuk használniinput. * grok: A Location of the grok patternek helyepatterns. A Docker image-ben ez a Pattern definition are stored in /grok/patterns mappa leszfolder by default. * metrics: Ez a legfontosabb részThis is the most important part. Itt kell egyenként definiálni a metrikákat és a hozzá tartozó reguláris kifejezést (grok patternek formájában)Here you need to define the metrics and the associated regular expression* server: Milyen porton hallgatózzon a szerverContains the port of the http metrics server.
<br>
====Metrics====
** '''HAROXY patterns''': https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/haproxy
* label: A találati csoportoknak lehet nevet adni. A névre lehet hivatkozni a label szekcióban, amiből létre fog hozni egy olyan címkét, aminek az értéke a parsolt adat leszHere we can add Prometheus labels to the metrics.
<br>
====matchdefinition====A Grok assumes that each element is separated by a single space in the source log files. In the match-ben fel kell írni egy reguláris kifejezést grok építő kockákból. Azt feltételezzüksection, hogy az egyes elemeket you have to write a log-ban egy szünet választja elregular expression using grok building blocks. Minden egyes építő kocka Each building block has the format: '''%{PATTERN-NÉVPATTERN_NAME}''' alakú, ahol a PATTERN-NÉV-nek léteznie kell valamelyik where PATTERN_NAME must be an existing predefined grok pattern gyűjteményben. A legáltalánosabb típus a The most common type is '''%{DATA}''', ami egy tetszőleges adatstruktúrára vonatkozik, ami nem tartalmaz szünetetwhich refers to an arbitrary data structure that contains no withe-space. There are several compound patterns that are build up from basic grok patterns. Több olyan pattern is van, ami több elemi pattern-ből van kombinálvaWe can assign the regular expression result groups to named variables that can be used as the value of the Prometheus metric or as label values. Ha azt akarjuk hogy a The variable name must be placed inside the curly bracket of the pattern-el leírt reguláris kifejezésből találati csoport is képződjön, nevet kell adni separated by a patternek, plsemicolon from the patter name:
<pre>
%{DATA:this_is_the_name}
</prePre>Ekkor pattern-el megtalált mező értéke bele fog kerülni a The result of the regular expression will be assigned to the variable '''this_is_the_name''' változóba, amire lehet hivatkozni a metrika értékének a meghatározásánál illetve a címke legyártásnálwhich can be referenced when defining the value of the Prometheus metric or the metrics label.
<br>
====labelsdefinition ====A In the label section we can define labels szekcióban nevesített for the generated Prometheus metric. The labels are defined with a name:value list, where the value can be a string constant or a variable defined for a patternin the match section. The variable must be referenced in go-ekre lehet hivatkozni. Ekkor az adott logsorból parszolt mező értékét fogja adni template style between double curly brackets starting with a definiált címkénekdot. Pl. a For example, if we used the '''%{DATA:this_is_the_name}''' pattern használata esetén felírhatjuk a következő címkétin the match section, we can define the 'mylabel' Prometheus label with the value of the 'this_is_the_name' variable in the following way: <br>
<pre>
mylabel: '{{.this_is_the_name}}'
</prePre>Ekkor, ha a %{DATA} pattern által leírt mező értéke Lets assume that the 'this_is_the_name' variables value is 'myvalue' volt, akkor a metrikára rá fog kerülni egy ilyen címke. Then the metric would receive the following label: '''{mylabel="myvalue"}'''<br>Nézzünk egy példát: We are going to demonstrate a full, metric definition example in the following section <br>Adott a következő The following log sorline is given:
<pre>
7/30.07./2016 142:37:03 PM adam 1.5</prePre>És a következő metrika szabály a And there is given the following metric definition in the grok config-ban:
<source lang="C++">
metrics:
user: '{{.user}}'
</source>
<pre>
# HELP Example counter metric with labels.
<br>
====Metrika értékének meghatározásaValue of the metric ====A For a counter típusú metrikánál nincs szükség a metrika értékét meghatározni-type metric, mert ott azt fogja számolniwe don't need to determine the value of the metric, hogy hány illeszkedő logsort találtas it will just simply count the number of matches of the regular expression. Ezzel ellentétben az összes többi típusnál meg kell adniIn contrast, hogy mit tekintünk az értéknekfor all other types, we have to specify the value. Ezt a It has be defined in the '''value''' szekcióban kell megadnisection of the metric definition. Variables can be referenced in the same way as we saw it in in the label definition chapter, ahol be kell hivatkozni egy nevesített grok patternin go-t a match szekcióból ugyan úgy Go templét formában, ahogy a címkéket template style. Here is definiáltukan example. Pl adott a következő két logsorThe following two log lines are given:
<pre>
7/30.07./2016 142:37:03 PM adam 17/30.07./2016 142:37:03 adam PM Adam 5</prePre>És erre az alábbi And we define the following histogram-ot definiáljuk, ami két vödörből állwhich consists of two buckets, az bucket 1-es és and 2-es vödörből:
<source lang="C++">
metrics:
user: '{{.user}}'
</source>
<pre>
# HELP Example counter metric with labels.
<br>
====FüggvényekFunctions ====A metrika értékekre (value) és a címkékre is lehet függvényeket alkalmazni. A függvények a '''Functions were introduced in grok-exporter version 0.2.7'''-es grok-exporter verzió kell vagy újabb. Lehet használni string manipulációs függvényeket és aritmetikai függvényeket isWe can apply functions to metric value and to the value of its labels. String manipulation functions and arithmetic functions are also available. A következő két argumentumú aritmetikai függvények támogatottakThe following two arguments arithmetic functions are supported:
* add
* subtract
* multiply
* divide
</source>
<pre>
# HELP Example counter metric with labels.
# TYPE grok_example_lines histogram
grok_example_lines_bucket{user="adam", le="1"} 0grok_example_lines_bucket{user="adam", le="2"} 0grok_example_lines_bucket{user="adam", le="+Inf"} 2
...
</prePre> Mivel a két érték Since the two values would change to 1000 ill and 5000-re fog módosulni, ezért mindkettő az both will fall into the infinite kategóriába fog esnibucket.
<br>
<br>
==Creating the grok config fájl elkészítésefile ==Össze kell állítani egy olyan We have to compile a grok patternthat can extract all the attributes that are required for creating the response-t ami illeszkedik a latency-histogram based on the HAproxy access-log sorokra, és képes kigyűjteni az összes számunkra fontos attribútumotlogs. The required attributes are the following:
* válasz kiszolgálásának szumma idejeresponse time
* haproxy instance id
* openshfit service névtérnamespace* pod névname
<br>
<pre>
Aug 6 20:53:30 192.168.122.223 haproxy[39]: 192.168.42.1:50708 [06/Aug/2019:20:53:30.267] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.12:8080 1/0/0/321/321 200 135 - - --NI 2/2/0/1/0 0/0 "GET /test/slowresponse/1 HTTP/1.1"</prePre>
<pre>
[0.1, 0.2, 0.4, 1, 3, 8, 20, 60, 120]
</prePre>A válaszidőket tartalmazó metrikáknak konvenció szerint a következő a neveResponse time histogram metrics by convention are called: '''<name prefix>_http_request_duration_seconds'''
'''config.yml'''
</source>
Explanation:* '''type: file''' -> fájlból olvassuk a logokatread logs from file* '''path: /var/log/messages''' -> Az The rsyslog szerver a server writes logs to /var/log/messages mappába írja a logokat alapértelmezetten by default* '''readall: true''' -> mindig az egész always reads the entire log fájlt beolvassafile. Ezt csak tesztelésre szabad így használniThis should only be used for testing, éles környezetbenin a live environment, ezt mindig this always has to be set to false-ra kell állítani. * '''patterns_dir: ./patterns''' -> A Base directory of the pattern definitions in the docker image-ben itt találhatók a pattern definíciók* <pre>value: "{{divide .Tt 1000}}"</pre> A kiszolgálási idő a The response time in the HAproxy log-ban miliszekundumban van, ezt konvertálni kell szekundumrais in milliseconds so we convert it to seconds. * '''port: 9144''' -> Ezen a porton lesz elérhető a The http port of the /metrics végpont. endpoint
<br>
{{warning|nem szabad éles környezetben elfelejteni a Do not forget to set the value of '''readall''' értékét ''to 'false'''-ra állítani, mert nagyon lerontja in a hatásfokotlive environment as it can significantly degrade performance}}
<br>
<br>
:[[File:ClipCapIt-190808-170333.PNG]]
<br>
==building the docker image elkészítése==A The grok-exporter docker image elérhető a is available on the docker hub-on több változatban in several variants. The only problem with them is. A gond velük csak az, hogy nem tartalmazzák az that they do not include the rsyslog szervert, amire szükségünk vanserver, hogy a what we need for the HAproxy közvetlen el tudja küldeni a logokat a to send logs directly to the grok-exporter podokankpod. <br>
docker-hub link: https://hub.docker.com/r/palobo/grok_exporter <br>
<br>
<br>
<br>
<br>
===Dockerfile===A We will modify the official '''palobo/grok_exporter''' Dockerfile-ból fogunk kiindulni, de ki fogjuk azt egészíteni az we will extend it with the rsyslog installációval és portoljuk installation and port it to centos-re: https://github.com/berkiadam/haproxy-metrics/tree/master/grok- CentOS-exporter-centos
<br>
➲[[File:Grok-exporter-docker-build.zip|Dokcer Download all files required for the build of the Docker image buld-hez szükséges összes fájl letöltése]]
<br>
CMD sh -c "nohup /usr/sbin/rsyslogd -i ${PID_DIR}/pid -n &" && ./grok_exporter -config /grok/config.yml
</source>
{{note|Fontos, hogy a It is important to use grok-exporter-ből legalább a version 0.2.7-es verziót használjukor higher, abban jelent meg először a függvények kezeléseas functions were introduced in this version}}
<br>
<br>
<pre>
$ModLoad omstdout.so
<br>
===Lokális Local build és lokális tesztand local test ===Első körben a lokális docker démonnal fogjuk First, we will build-elni a the docker image-t, hogy tudjuk lokálisan futtatni tesztelés céljábólwith the local docker daemon so that we can run it locally for testing. Később majd ezt a Later we will build it directly on the minishfit VM-en fogjuk build-elni, mert csak onnan fogjuk tudni feltölteni a since we will only be able to upload it to the minishfit docker registry-befrom the VM. Mivel majd egy távoli (nem Since, at the and, as we will upload the image to a lokális) remote docker repository-ba akarjuk majd az image-t felölteni, fontos, hogy betartsuk az elnevezési konvenciókatit is important to follow the naming conventions:
<pre>
<repo URL>:<repo port>/<névtérnamespace>/<image-névname>:<tag>
</pre>
<pre>
# docker build -t 172.30.1.1:5000/default/grok_exporter:1.1.0 .</prePre>
<pre>
Aug 6 20:53:30 192.168.122.223 haproxy[39]: 192.168.42.1:50708 [06/Aug/2019:20:53:30.267] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.12:8080 1/0/0/321/321 200 135 - - --NI 2/2/0/1/0 0/0 "GET /test/slowresponse/1 HTTP/1.1"
<br>
<pre>
# docker run -d -p 9144:9144 -p 514:514 -v $(pwd)/config.yml:/etc/grok_exporter/config.yml -v $(pwd)/haproxy.log:/grok/haproxy.log --name grok 172.30.1.1:5000/default/grok_exporter:1.1.0</prePre>
<br>
<pre>
# docker logs grok
<br>
<pre>
...
<br>
<br>
<pre>
# docker exec -it grok /bin/bash
<br>
<pre>
# logger -n localhost -P 514 -T "this is the message"
</prePre>(T=TCP)
<pre>
Aug 8 16:54:25 dell adam this is the message</prePre>
<br>
<br>
===Távoli Remote build===Fel szeretnénk tölteni az elkészült docker We have to to upload our custom grok Docker image-t a to the minishfit saját registry-ébe. Ehhez az To do so, you need to build the image-t a with the minishfit VM lokális 's local docker démonjával kell build-elnidaemon, mert csak onnan ehet hozzáférni a since you can only access the minishfit registry-hezfrom the VM so uploading images is only possible from the VMs local registry. <br>Részletek ittDetails can be found here: [[Openshift_basics#Minishfit_docker_registry|➲Image push a to minishift docker registriy-be]]
<pre>
# oc login -u system:admin
# oc adm policy add-cluster-role-to-user cluster-admin admin --as=system:admin
cluster role "cluster-admin" added: "admin"
</prePre>{{note|Ha ezt a hibát kapjuk If we get this error '''Error from server (NotFound): the server could not find the requested resource''', ez azt jelenti, hogy az '''it probably means that our oc''' kliens programunk régebbi mint a client is older than OpenShift verzióversion}}
<pre>
# minishift docker-env
# eval $(minishift docker-env)
# oc login
Username: admin
Password: <admin>
# docker login -u admin -p $(oc whoami -t) $(minishift openshift registry)
Login Succeeded
</prePre>
Build-eljük le a the image on the minishfit VM-en isas well:
<pre>
# docker build -t 172.30.1.1:5000/default/grok_exporter:1.1.0 .</prePre>
<pre>
# docker push 172.30.1.1:5000/default/grok_exporter:1.1.0
</prePre>
<br>
==Required Kubernetes objektumokobjects ==
* haproxy-exporter service account
* scc-anyuid.yaml
<br>
<br>
===Create the ServiceAccount létrehozása===A haproxy-exporter-nek szüksége van egy saját serviceAccount-ra, amire engedélyezni fogjuk a privilegizált (root) konténer futtatást. Erre az rsyslog szervernek van szüksége.
<pre>
# kubectl create serviceaccount haproxy-exporter -n default
serviceaccount/haproxy-exporter created</prePre>
<source lang="C++">
apiVersion: v1
kind: ServiceAccount
metadata:
name: haproxy-exporter
namespace: default
secrets:
- name: haproxy-exporter-token-8svkx
===Objektumok definiálásaAddition Kubernetes objects===
<br>
<br>
<br><br>
<pre>
# kubectl get SecurityContextConstraints
<br>
<br>
'''sccScc-anyuid.yaml'''<source lang="C++">
kind: SecurityContextConstraints
metadata:
...
users: - system:serviceaccount:default:haproxy-exporter
...
</source>
<pre>
# oc edit scc anyuid
<br>
===objektumok létrehozásacreate the objects ===
<pre>
# kubectl apply -f cm-haproxy-exporter.yaml
configmap/haproxy-exporter created
</pre>
<pre>
# kubectl apply -f deployment-haproxy-exporter.yaml
deployment.apps/haproxy-exporter created
# kubectl rollout status deployment haproxy-exporter -n default
deployment "haproxy-exporter" successfully rolled out
</pre>
<br>
===TesztelésTesting ===
<pre>
# kubectl logs haproxy-exporter-744d84f5df-9fj9m -n default
</pre>
<pre>
# kubectl exec -it haproxy-exporter-647d7dfcdf-gbgrg /bin/bash -n default
</pre>
<pre>
logger -n localhost -P 514 -T "this is the message"
</pre>
<pre>
# cat messages
Aug 28 19:16:09 localhost root: this is the message
</pre>
<pre>
# kubectl logs haproxy-exporter-647d7dfcdf-gbgrg -n default
Starting server on http://haproxy-exporter-647d7dfcdf-gbgrg:9144/metrics2019-08-28T19:16:09+00:00 localhost root: this is the message
</pre>
<br>
==HAproxy konfigurációConfiguration ==
===Környezeti változók beállításaSetting the environment variables ===A In the HAproxy-nak be fogjuk állítani környezeti változónk keresztül a routers, we will set the address of the rsyslog server running in the haporxy-exporter pod-ban futó rsyslog szerver címétvia environment variables. Ehhez első lépésben listázzuk a Let's check first the haproxy-exporter service-t.
<pre>
# kubectl get svc -n default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEhaproxy-exporter-service ClusterIP 172.30.213.183 <none> 9144/TCP,514/TCP,514/UDP 15s
..
</pre>
<pre>
# oc set env dc/myrouter ROUTER_SYSLOG_ADDRESS=172.30.213.183 -n default
deploymentconfig.apps.openshift.io/myrouter updated
</pre>
{{note|Minishift-en a In minishift, in the router konténerben nem működik a containers the name resolution does not work for Kubernetes service-ek nevére a névfeloldásnames, mivel nem a because it doesn't use the Kubernetes klaszter cluster DNS szerver címe van beállítva, hanem a server but the minishfit VM. Ezért nem tehetünk mástTherefore, mint hogy a all you have to do is enter the service 's IP címét adjuk meg a neve helyettaddress instead of its name. In OpenShift környezetben a , we have to use the name of the service nevét adjuk meg}}
<pre>
# oc set env dc/myrouter ROUTER_LOG_LEVEL=debug -n default
deploymentconfig.apps.openshift.io/myrouter updated
</pre>
{{warning|Teljesítmény tesztel meg kell vizsgálni hogy mekkora plusz terhelést jelent a Performance test must be carried out to see how much is the extra load when running the haproxy-nak ha in debug módban futmode}}
<br>
<pre>
# kubectl exec -it myrouter-5-hf5cs /bin/bash -n default
$ cat /var/lib/haproxy/conf/haproxy.config
global
..
</pre>
<br>
<br>
<br>
===Testing the rsyslog szerver teszteléseserver ===Generáljunk egy kis forgalmat a Generate some traffic through haproxy-n keresztül, majd lépjünk vissza a then go back to the haproxy-exporter konténerbe, és listázzuk a container and list the content of the messages fájl tartalmátfile.
<pre>
# kubectl exec -it haproxy-exporter-744d84f5df-9fj9m /bin/bash -n default
#
# tail -f /var/log/messages
Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy fe_sni stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_no_sni stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy fe_no_sni stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy openshift_default stopped (FE: 0 conns, BE: 1 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_edge_http:dsp:nginx-route stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_http:mynamespace:prometheus-alertmanager-jv69s stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_http:mynamespace:prometheus-server-2z6zc stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_edge_http:mynamespace:test-app-service stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[24]: Proxy be_edge_http:myproject:nginx-route stopped (FE: 0 conns, BE: 0 conns).Aug 9 12:52:17 192.168.122.223 haproxy[32]: 127.0.0.1:43720 [09/Aug/2019:12:52:17.361] public openshift_default/<NOSRV> 1/-1/-1/-1/0 503 3278 - - SC-- 1/1/0/0/0 0/0 "HEAD / HTTP/1.1"
</pre>
<pre>
...
Aug 9 12:57:21 192.168.122.223 haproxy[32]: 192.168.42.1:48266 [09/Aug/2019:12:57:20.636] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.17:8080 1/0/12/428/440 200 135 - - --II 2/2/0/1/0 0/0 "GET /test/slowresponse/1 HTTP/1.1"Aug 9 12:57:28 192.168.122.223 haproxy[32]: 192.168.42.1:48266 [09/Aug/2019:12:57:21.075] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.17:8080 4334/0/0/3021/7354 200 135 - - --VN 2/2/0/1/0 0/0 "GET /test/slowresponse/3000 HTTP/1.1"Aug 9 12:57:28 192.168.122.223 haproxy[32]: 192.168.42.1:48266 [09/Aug/2019:12:57:28.430] public be_edge_http:mynamespace:test-app-service/pod:test-app-57574c8466-qbtg8:test-app-service:172.17.0.17:8080 90/0/0/100/189 404 539 - - --VN 2/2/0/1/0 0/0 "GET /favicon.ico HTTP/1.1"Aug 9 12:57:35 192.168.122.223 haproxy[32]: 192.168.42.1:48268 [09/Aug/2019:12:57:20.648] public public/<NOSRV> -1/-1/-1/-1/15002 408 212 - - cR-- 2/2/0/0/0 0/0 "<BADREQ>"
</pre>
===Testing the grok-exporter tesztelésecomponent ===Kérjük le a grokPlease open the gork-exporter metrikákat a metrics at http://<pod IP>:9144/metrics címen. Vagy a You can open this URL either in the haproxy-exporter pod-ban itself with on localhost hívással, vagy bármelyik másik or in any other pod-ban a using the haporxy-exporter pod 's IP címét felhasználvaaddress. Az alábbi példában a test-app-ba lépek be. Látnunk kell a metrikák között a We have to see the '''haproxy_http_request_duration_seconds_bucket''' histogramothistogram among the metrics.
<pre>
# kubectl exec -it test-app-57574c8466-qbtg8 /bin/bash -n mynamespace$
$ curl http://172.30.213.183:9144/metrics
...
# HELP haproxy_http_request_duration_seconds The request durations of for the applications running in openshift openhift that have route defined.
# TYPE haproxy_http_request_duration_seconds histogram
haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="0.1"} 0haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="0.2"} 1haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="0.4"} 1haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="1"} 2haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="3"} 2haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="8"} 3haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="20"} 3haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="60"} 3haproxy_http_request_duration_seconds_bucket{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="120"} 3haproxy_http_request_duration_seconds_bucket{haproxy={ "haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service",le="+Inf"} 3haproxy_http_request_duration_seconds_sum{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service"} 7.9830000000000005haproxy_http_request_duration_seconds_count{haproxy="haproxy[32]",namespace="mynamespace",pod_name="test-app-57574c8466-qbtg8",service="test-app-service"} 3
</pre>
<br>
==Prometheus beállításokSettings ==
===Statikus konfigurációStatic configuration ===<source lang="C++"> - job_name: grok-exporter scrape_interval scrape_interval: 5s metrics_path metrics_path: /metrics static_configs static_configs: - targets: ['grok-exporter-service.default:9144']
</source>
=== Pod Level Data Collection ===
<pre>
# kubectl get Endpoints haproxy-exporter-service -n default -o yaml
kind: Endpoints
metadata:
...
</pre>
* __meta_kubernetes_endpoint_port_name: metrics -> 9144
* __meta_kubernetes_service_name: haproxy-exporter-service
<br>
<pre>
# kubectl apply -f cm-prometheus-server-haproxy-full.yaml
</pre>
<pre>
# kubectl logs -f -c prometheus-server prometheus-server-75c9d576c9-gjlcr -n mynamespace
...
level=info ts=2019-07-22T20:25:36.016Z caller=main.go:730 msg="Loading configuration file" filename=/etc/config/prometheus.yml
</pre>
<br>
<br>
===scaling haproxy-exporter skálázása===
<pre>
# kubectl scale deployment haproxy-exporter --replicas=2 -n defaultdeployment.extensions/haproxy-exporter scaled
</pre>
<pre>
# kubectl get deployment haproxy-exporter -n default
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEhaproxy-exporter 2 2 2 2 3h
</pre>
<br>
<br>
==Metrika fajtákMetric types ==
===haproxy_http_request_duration_seconds_bucket===
type: histogram
<br>
===haproxy_http_request_duration_seconds_bucket_count===type: counter<br>Az összes darabszáma az adott histogramba eső request-ek számánakThe total number of requests in that histogram
<pre>
haproxy_http_request_duration_seconds_count{haproxy={ "haproxy[39]",jobJob ="haproxy-exporter",namespace="mynamespace",pod_name="testapp-appbody",service="testbody-app-service"} 5
</pre>
<br>
<br>
===haproxy_http_request_duration_seconds_sum===type: counter<br>A válaszidők idejének összege az adott hisztogrambanThe sum of the response times in a given histogram. Az előző példa alapján összesen 5 kérés jöttBased on the previous example, és there were a kiszolgálási idő összeadva total of 5 requests and the summ serving time was 13 s volt.
<pre>
haproxy_http_request_duration_seconds_sum{haproxy={ "haproxy[39]",jobJob ="haproxy-exporter",namespace="mynamespace",pod_name="testapp-appbody",service="testbody-app-service"13663} 13.663
</pre>
<br>
=OpenShift router + rsyslog=
Starting with OpenShift 3.11-től kezdődően lehet olyan , it is possible to fire up a router-t definiálni, hogy az OpenShfit automatikusan elindít egy that will contain a side car rsyslog konténert a container in the router pod-ban és be is állítja, hogy a and configure HAproxy egy socket-en keresztül (to send logs to the rsyslog server via an emptyDir volume) elküldje a logokat az rsyslog szervernek, ami az which writes them to stdout-ra írja azokat alapértelmezettenby default. Az The configuration of rsyslog konfigurációja egy is in a configMap-ban van.
<br>
<pre>
# oc adm router myrouter --extended-logging -n default
info: password for stats user admin has been set to O6S6Ao3wTX
</pre>
<br>
<pre>
# oc set env dc/myrouter ROUTER_LOG_LEVEL=debug -n default
deploymentconfig.apps.openshift.io/myrouter updated
</pre>
<br>
<pre>
# kubectl describe pod/myrouter-2-bps5v -n default
..
Containers:
...
...
</pre>
<br>
<br>
===router konténercontainer ===Ha belépünk a When we enter the router konténerbecontainer, láthatjuk, hogy már fel is nyalta a konfigurációwe can see that the configuration has already been modified:
<pre>
# kubectl exec -it myrouter-2-bps5v /bin/bash -n default -c routerbash-4.2$ cat /var/lib/haproxy/conf/haproxy.config
global
...
...
defaults
...
...
backend be_edge_http:mynamespace:test-app-service
</pre>
<br>
<br>
===rsyslog konténercontainer ===
<pre>
# kubectl exec -it myrouter-2-bps5v /bin/bash -n default -c syslog
$ cat /etc/rsyslog/rsyslog.conf $ModLoad imuxsock$SystemLogSocketName /var/lib/rsyslog/rsyslog.sock$ModLoad omstdout.so*.* :omstdout:
</pre>
<br>
<pre>
# kubectl get cm rsyslog-config -n default -o yaml
apiVersion: v1
data:
kind: ConfigMap
metadata:
</pre>
<br>
<br>
===Viewing HAproxy logok nézegetéseLogs ===
<pre>
# kubectl logs -f myrouter-2-bps5v -c syslog
</pre>