<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Rosa on Medium]]></title>
        <description><![CDATA[Stories by Daniel Rosa on Medium]]></description>
        <link>https://medium.com/@danielmrosa?source=rss-42e3b7082f0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f4eEjCAmt6DoBAEELUomXg.png</url>
            <title>Stories by Daniel Rosa on Medium</title>
            <link>https://medium.com/@danielmrosa?source=rss-42e3b7082f0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:32:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielmrosa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Crossplane: Delivering cloud resources in a self-service model]]></title>
            <link>https://danielmrosa.medium.com/crossplane-delivering-cloud-resources-in-a-self-service-model-2d9d7ea4847a?source=rss-42e3b7082f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d9d7ea4847a</guid>
            <category><![CDATA[crossplane]]></category>
            <category><![CDATA[open-application-model]]></category>
            <category><![CDATA[crossplane-compositions]]></category>
            <dc:creator><![CDATA[Daniel Rosa]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 21:52:11 GMT</pubDate>
            <atom:updated>2021-04-17T02:27:24.564Z</atom:updated>
            <content:encoded><![CDATA[<p>I this article, I will demonstrate how to allow your developers to create their application requirements such as a database instance, a queue service, cache service, etc with no dependency on your Ops team using crossplane.</p><p>First, I assume you already have <a href="http://crosplane.io/">crossplane</a> installed in your Kubernetes cluster, if not, please follow the instructions <a href="https://crossplane.io/docs/v1.1/getting-started/install-configure.html"><strong>here</strong></a></p><p><strong>Crossplane compositions</strong> allow you to abstract all the infrastructure requirements need to create some cloud resources in a self-service model, hiding the infrastructure complexity. With compositions, developers can create their applications dependency by themselves using Kubernetes as a control plane.</p><p>In this scenario, <strong>Platform Builders </strong>can define previously all the infrastructure requirements to provide some cloud resources such as a database instance. As you may know, to create a database instance on your cloud provider you need to provide certain components such as virtual private networks, subnets, security groups, and so on, and your developers may not be confident or they don´t be familiar with this infrastructure base, so how can you abstract it for then? using compositions!</p><p>Now, <strong>Platform consumers</strong> can take advantage of this approach and consume the resources in a self-service model. In other words, developers can create a database instance or another component just by applying one single <strong>declarative manifest</strong> configuring only the settings that you defined to be customized such as the storage size, instance type, and the database name as well.</p><p>One of the most benefits of this approach is to allow your developers to create their application dependencies following all the best practices your organization requires such as security patterns.<br>Crossplane Providers are a set of Kubernetes CRDs and <a href="https://kubernetes.io/docs/concepts/architecture/controller/">controllers</a> that <strong>reconcile them!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mg9eN4M6DuCyfwBk.png" /><figcaption><a href="https://npm.io/package/crossplane-cdk">https://npm.io/package/crossplane-cdk</a></figcaption></figure><p>Well, let´s explain how to do it using an RDS Instance on AWS but not limited to because you can use the same approach to prepare the infrastructure requirements to provisioning cloud resources on others cloud providers supported too.</p><p><strong>RDS Instance composition</strong>:<br>composition.yaml</p><pre>apiVersion: apiextensions.crossplane.io/v1<br>kind: Composition<br>metadata:<br>  name: compositepostgresqlinstances.aws.database.example.org<br>  labels:<br>    provider: aws-provider<br>    guide: quickstart<br>    vpc: vpc-xxxxxxxxxxxxxx<br>spec:<br>  writeConnectionSecretsToNamespace: crossplane-system<br>  compositeTypeRef:<br>    apiVersion: database.example.org/v1alpha1<br>    kind: CompositePostgreSQLInstance<br>  resources:<br>    - name: securitygroup<br>      base:<br>        apiVersion: ec2.aws.crossplane.io/v1beta1<br>        kind: SecurityGroup<br>        spec:<br>          providerConfigRef:<br>            name: aws-provider<br>          forProvider:<br>            region: us-east-1<br>            vpcIdRef:<br>              name: my-vpc-name<br>            groupName: default<br>            description: default<br>            ingress:<br>              - fromPort: 5432<br>                toPort: 5432<br>                ipProtocol: tcp<br>                ipRanges:<br>                  - cidrIp: x.x.x.x/x<br>      patches:<br>        - fromFieldPath: &quot;metadata.name&quot;<br>          toFieldPath: &quot;spec.forProvider.groupName&quot;</pre><pre>- name: rdsinstance<br>      base:<br>        apiVersion: database.aws.crossplane.io/v1beta1<br>        kind: RDSInstance<br>        spec:<br>          providerConfigRef:<br>            name: aws-provider<br>          forProvider:<br>            dbSubnetGroupName: &quot;db-subnet-group&quot;<br>            region: us-east-1<br>            vpcSecurityGroupIDSelector:<br>              matchControllerRef: true<br>            allocatedStorage: 20<br>            autoMinorVersionUpgrade: true<br>            backupRetentionPeriod: 0<br>            caCertificateIdentifier: rds-ca-2019<br>            copyTagsToSnapshot: false<br>            dbInstanceClass: db.t3.micro<br>            deletionProtection: false<br>            enableIAMDatabaseAuthentication: false<br>            enablePerformanceInsights: false<br>            engine: postgres<br>            engineVersion: &quot;13&quot;<br>            finalDBSnapshotIdentifier: sample<br>            masterUsername: demo<br>            multiAZ: false<br>            port: 5432<br>            preferredBackupWindow: 06:15-06:45<br>            preferredMaintenanceWindow: sat:09:21-sat:09:51<br>            publiclyAccessible: false<br>            storageEncrypted: false<br>            storageType: gp2<br>          writeConnectionSecretToRef:<br>            namespace: crossplane-system<br>            name: default<br>      patches:<br>        - fromFieldPath: &quot;metadata.uid&quot;<br>          toFieldPath: &quot;spec.writeConnectionSecretToRef.name&quot;<br>          transforms:<br>            - type: string<br>              string:<br>                fmt: &quot;%s-postgresql&quot;<br>        - fromFieldPath: &quot;spec.parameters.storageGB&quot;<br>          toFieldPath: &quot;spec.forProvider.allocatedStorage&quot;<br>        - fromFieldPath: &quot;spec.parameters.finalDBSnapshot&quot;<br>          toFieldPath: &quot;spec.forProvider.finalDBSnapshotIdentifier&quot;<br>        - fromFieldPath: &quot;spec.parameters.dbInstanceClass&quot;<br>          toFieldPath: &quot;spec.forProvider.dbInstanceClass&quot;<br>        - fromFieldPath: &quot;metadata.namespace&quot;<br>          toFieldPath: &quot;spec.writeConnectionSecretToRef.namespace&quot;<br>        - fromFieldPath: &quot;metadata.name&quot;<br>          toFieldPath: &quot;spec.writeConnectionSecretToRef.name&quot;<br>      connectionDetails:<br>        - fromConnectionSecretKey: username<br>        - fromConnectionSecretKey: password<br>        - fromConnectionSecretKey: endpoint<br>        - fromConnectionSecretKey: port</pre><p>Note that you abstract most of all the infrastructure needs to create RDS Instance, you defined the right VPC to use, defined the create a right security group rules, the subnet group, backup window, upgrade policy, and many others configurations regarding your organization best practices.</p><p><strong>XRD Example<br></strong>xrd.yaml</p><pre>apiVersion: apiextensions.crossplane.io/v1<br>kind: CompositeResourceDefinition<br>metadata:<br>  name: compositepostgresqlinstances.database.example.org<br>spec:<br>  group: database.example.org<br>  names:<br>    kind: CompositePostgreSQLInstance<br>    plural: compositepostgresqlinstances<br>  claimNames:<br>    kind: RDSPostgresInstance<br>    plural: rdspostgresqlinstancess<br>  connectionSecretKeys:<br>    - username<br>    - password<br>    - endpoint<br>    - port<br>  versions:<br>  - name: v1alpha1<br>    served: true<br>    referenceable: true<br>    schema:<br>      openAPIV3Schema:<br>        type: object<br>        properties:<br>          spec:<br>            type: object<br>            properties:<br>              parameters:<br>                type: object<br>                properties:<br>                  storageGB:<br>                    type: integer<br>                  finalDBSnapshot:<br>                    type: string<br>                  dbInstanceClass:<br>                    type: string<br>                required:<br>                  - storageGB<br>                  - finalDBSnapshot<br>                  - dbInstanceClass<br>            required:<br>              - parameters</pre><p>Note that you defined the required fields to be informed as a required field, some fields will be <strong>patched</strong> as soon as the <strong>Resource Claim</strong> is applied.</p><p><strong>DB Subnet Group<br></strong>db-subnet-group.yaml</p><pre>apiVersion: database.aws.crossplane.io/v1beta1<br>kind: DBSubnetGroup<br>metadata:<br>  name: db-subnet-group<br>spec:<br>  forProvider:<br>    region: us-east-1<br>    description: &quot;DB Subnet Group&quot;<br>    subnetIds:<br>      - subnet-xxxxxx<br>      - subnet-xxxxxx<br>      - subnet-xxxxxx<br>  providerConfigRef:<br>    name: aws-provider</pre><p><strong>VPC<br></strong>vpc.yaml</p><p>In case you already have a VPC provisioned, you need to import the VPC reference to crossplane make a reference when you mention the VPC.<br>If this is your case, you can use the example below.</p><pre>apiVersion: ec2.aws.crossplane.io/v1beta1 <br>kind: VPC<br>metadata:<br>  name: my-vpc-name<br>  annotations:<br>    crossplane.io/external-name: vpc-0880f7bca04b71622<br>spec:<br>  forProvider:  <br>    region: us-east-1<br>    cidrBlock: x.x.x.x/X<br>    enableDnsHostNames: true<br>    enableDnsSupport: true<br>    instanceTenancy: default<br>    tags:<br>      - key: Name<br>        value: my-vpc-name<br>  providerConfigRef:<br>    name: aws-provider</pre><p>So, <strong>after you apply all the compositions</strong> above to let your infrastructure ready to receive the claims, the only thing your developer can do is to apply this <strong>Claim</strong> manifest to create RDS Instance with the name <strong>my-db-instance</strong>, using 10 GB of storage and using the instance type <strong>db.t3.medium</strong></p><p><strong>Claim<br></strong>claim.yaml</p><pre>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: demo<br>---<br>apiVersion: database.example.org/v1alpha1<br>kind: RDSPostgresInstance<br>metadata:<br>  name: my-db-instance<br>  namespace: demo<br>spec:<br>  parameters:<br>    storageGB: 10<br>    finalDBSnapshot: my-db-instance<br>    dbInstanceClass: db.t3.medium<br>  compositionSelector:<br>    matchLabels:<br>      provider: aws-provider<br>  writeConnectionSecretToRef:<br>    name: my-db-instance</pre><p><strong>Apply all the compositions:</strong></p><pre>kubectl apply -f composition.yaml<br>kubectl apply -f xrd.yaml<br>kubectl apply -f db-subnet-group.yaml<br>kubectl apply -f vpc.yaml<br>kubectl apply -f claim.yam</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*_KDY5BVIQa5PZ_IiMmWSKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*X-qAdNX5UvW-Nov5lukcDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mvyr-ftfchNPxPW7SBpQ_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*1ITY6FcuzAwDsgXkPtKwAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFtGVbA_hM1CdOqTF6DAww.png" /></figure><p>So, if another developer wants to create another database but using <strong>db.t3.large</strong> instance type and <strong>50GB</strong> of storage, he just needs to apply as below :</p><pre>apiVersion: database.example.org/v1alpha1<br>kind: RDSPostgresInstance<br>metadata:<br>  name: my-db-instance-2<br>  namespace: demo<br>spec:<br>  parameters:<br>    storageGB: 50<br>    finalDBSnapshot: my-db-instance-2<br>    dbInstanceClass: db.t3.large<br>  compositionSelector:<br>    matchLabels:<br>      provider: aws-provider<br>  writeConnectionSecretToRef:<br>    name: my-db-instance-2</pre><p><strong>Remember</strong>: If you would like to work with more than one cloud provider allowing your developers to provide their needs, you as a <strong>Platform Builder </strong>just need to <a href="https://crossplane.io/docs/v0.3/cloud-providers.html">create another provider</a> and apply<strong> the right compositions related to your cloud provider</strong>. After that, you just need to provide a template of claim to your developers, instructed them to reference another cloud provider on their claims. Example:</p><pre>compositionSelector:<br>    matchLabels:<br>      provider: azure-provider</pre><pre>compositionSelector:<br>    matchLabels:<br>      provider: gcp-provider</pre><p>In this way, you are abstracting all the infrastructure complexities, allowing your developers to create their infrastructure requirements by just applying a Kubernetes <strong>Kind.</strong></p><p><strong>Note</strong>: You can use the git-ops process to automatize this using a CI/CD pipeline to provisioning this resource along with the application manifest as well.</p><p>Thanks for reading!</p><p><strong>Further Readings</strong></p><p><a href="https://crossplane.io/">https://crossplane.io</a><br><a href="https://alibaba-cloud.medium.com/oam-and-crossplane-the-next-stage-for-building-modern-application-6a0e8642dbda">https://alibaba-cloud.medium.com/oam-and-crossplane-the-next-stage-for-building-modern-application-6a0e8642dbda</a><br><a href="https://blog.crossplane.io/crossplane-vs-terraform/">https://blog.crossplane.io/crossplane-vs-terraform/</a><br><a href="https://next.redhat.com/2021/03/31/crossplane-as-an-abstraction-platform-to-manage-and-deploy-service-operators/">https://next.redhat.com/2021/03/31/crossplane-as-an-abstraction-platform-to-manage-and-deploy-service-operators/</a><br><a href="https://danielmangum.com/posts/crossplane-infrastructure-llvm/">https://danielmangum.com/posts/crossplane-infrastructure-llvm/</a><br><a href="https://blog.crossplane.io/">https://blog.crossplane.io/</a></p><p><strong>Videos</strong><br><a href="https://www.cncf.io/webinars/this-week-in-cloud-native-crossplane-gitops-based-infrastructure-as-code-through-kubernetes-api/">https://www.cncf.io/webinars/this-week-in-cloud-native-crossplane-gitops-based-infrastructure-as-code-through-kubernetes-api/</a><br><a href="https://www.youtube.com/watch?v=yrj4lmScKHQ&amp;t=1s">https://www.youtube.com/watch?v=yrj4lmScKHQ&amp;t=1s</a><br><a href="https://www.youtube.com/watch?v=RaoKcJGchKM&amp;t=1874s">https://www.youtube.com/watch?v=RaoKcJGchKM&amp;t=1874s</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d9d7ea4847a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring Kafka]]></title>
            <link>https://danielmrosa.medium.com/monitoring-kafka-b97d2d5a5434?source=rss-42e3b7082f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b97d2d5a5434</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <dc:creator><![CDATA[Daniel Rosa]]></dc:creator>
            <pubDate>Wed, 30 May 2018 01:09:41 GMT</pubDate>
            <atom:updated>2018-05-30T01:09:41.735Z</atom:updated>
            <content:encoded><![CDATA[<h4>Monitoring Kafka with Kafka exporter + Prometheus + Grafana</h4><p>Hi All,<br>For you that read my article about <a href="https://medium.com/@danielmrosa/kafka-f8b6df58f1a">Install and Configure Kafka</a> or is in charge to keep or build a Kafka cluster, probably asked himself : How can I monitor my Kafka cluster using opensource tools ?<br>Everyone knows that monitor a Kafka cluster using opensource tools is not so easy and monitor only the basics components like disk space, cpu usage and memory consumption is not enough.</p><p>Well, I have a pleasure to share with you one solution to monitor Kafka brokers using <strong>Kafka Exporter, JMX exporter, Prometheus and Grafana.</strong></p><p>If you are used to work with containers, the steps to build this monitoring platform will be easy, if not, I will do my best to better describe the components relationship so you can decide to go ahead using containers or do a standalone installation using the sources.</p><p><strong>Scenario</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*jL6bP5xQhCz-Q0J_tk7-3g.png" /></figure><p>Basically, if you are using a container cluster to run your apps, you can add 3 new containers (kafka-exporter , prometheus and grafana) to monitor your kafka cluster. In this example, I´m using a cluster of docker in swarm mode to demonstrate.</p><p><strong>Components detailed</strong></p><p><strong>Kafka-Exporter</strong><br>Kafka exporter for Prometheus. For more information about exporters, <a href="https://prometheus.io/docs/instrumenting/exporters/">click here</a></p><p><strong>Prometheus<br></strong><a href="https://github.com/prometheus">Prometheus</a> is an <strong>open-source</strong> systems monitoring and alerting toolkit originally built at <a href="http://soundcloud.com/">SoundCloud</a>. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user <a href="https://prometheus.io/community">community</a>.</p><p><strong>Grafana<br></strong><a href="https://grafana.com/">Grafana</a> allows you to query, visualize, alert on and <strong>understand</strong> your metrics no matter where they are stored. Create, explore, and share dashboards with your team and foster a <strong>data driven culture</strong>.</p><p><strong>JMX Exporter<br></strong>JMX to Prometheus exporter: a collector that can configurably scrape and expose mBeans of a JMX target.<br>This exporter is intended to be run as a Java Agent, exposing a HTTP server and serving metrics of the local JVM. It can be also run as an independent HTTP server and scrape remote JMX targets, but this has various disadvantages, such as being harder to configure and being unable to expose process metrics (e.g., memory and CPU usage). Running the exporter as a Java Agent is thus strongly encouraged.</p><p><strong>A Pause for reflection</strong></p><blockquote>The most important part here is to understand the components relationship. In few words, this is what will happens :<br>1. Kafka Exporter and JMX Exporter will collect some broker metrics from Kafka cluster<br>2. Prometheus will collect these metrics and store in it´s time series database.</blockquote><blockquote>3. Grafana will connect on Prometheus to show some beautiful dashboards.<br>Cool, huh?</blockquote><p><strong>Let´s get started!</strong></p><p>If you intend to using containers, take a look on this docker compose.<br><strong>Note</strong>: I will skip the details related to docker swarm overview ,the overlay network (<strong>monitoring</strong>) and other docker concepts like secrets that I´m using ok ?</p><p>I will suppose that you already have your own docker cluster up and running :-)<br>As I said before, you can decide go ahead and install these components out of docker cluster, but I really encourage you to use docker due the facilities.</p><pre>version: &#39;3.4&#39;</pre><pre>services:</pre><pre>kafka_exporter:<br>    image: danielqsj/kafka-exporter<br>    networks:<br>      - monitoring<br>    command: --kafka.server=kafka01.foo.bar:9092 --kafka.server=kafka02.foo.bar:9092 --kafka.server=kafka03.foo.bar:9092<br>    deploy:<br>      mode: replicated<br>      resources:<br>        limits:<br>          memory: 128M<br>        reservations:<br>          memory: 64M      <br>      replicas: 1<br>      endpoint_mode: vip</pre><pre>prometheus:<br>    image: prom/prometheus<br>    ports:<br>      - &quot;9090:9090&quot;<br>    networks:<br>      - monitoring<br>    volumes:<br>      - /prometheus:/prometheus<br>    secrets:<br>      - prometheus.yml</pre><pre>command: --config.file=/run/secrets/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.retention=168h<br>    deploy:<br>      resources:<br>        limits:<br>          cpus: &#39;2&#39;<br>          memory: 4096M<br>        reservations:<br>          memory: 1024M<br>      replicas: 1<br>      endpoint_mode: vip<br>      placement:<br>        constraints:<br>           - &quot;node.labels.prometheus == true&quot;</pre><pre>grafana:<br>    image: grafana/grafana<br>    ports:<br>      - &quot;3000:3000&quot;<br>    networks:<br>      - monitoring<br>    volumes:<br>      - /var/lib/grafana:/var/lib/grafana<br>    deploy:<br>      mode: replicated<br>      resources:<br>        limits:<br>          memory: 512M<br>        reservations:<br>          memory: 128M<br>      replicas: 1<br>      endpoint_mode: vip<br>      placement:<br>        constraints:<br>           - &quot;node.labels.grafana == true&quot;</pre><pre>secrets:<br>  prometheus.yml:<br>    file: config/prometheus.yml<br>  alertmanager.yml:<br>    file: config/alertmanager.yml</pre><pre>networks:<br>  monitoring<br>    external: true</pre><p><strong>Prometheus.yml</strong></p><pre>global:<br>  scrape_interval:     30s<br>  evaluation_interval: 30s</pre><pre># Attach these labels to any time series or alerts when communicating with<br>  # external systems (federation, remote storage, Alertmanager).<br>  external_labels:<br>    monitor: &#39;prometheus-swarm&#39;</pre><pre>rule_files:<br>  - &quot;alert.rules_nodes&quot;<br>  - &quot;alert.rules_tasks&quot;<br>  - &quot;alert.rules_service-groups&quot;</pre><pre>scrape_configs:<br>  - job_name: &#39;prometheus&#39;<br>    dns_sd_configs:<br>    - names:<br>      - &#39;tasks.prometheus&#39;<br>      type: &#39;A&#39;<br>      port: 9090</pre><pre>- job_name: &#39;kafka_exporter&#39;<br>    dns_sd_configs:<br>    - names:<br>      - &#39;tasks.kafka_exporter&#39;<br>      type: &#39;A&#39;<br>      port: 9308<br>      <br> - job_name: &#39;kafka&#39;<br>    static_configs:<br>    - targets:<br>      - kafka01.foo.bar:7072<br>      - kafka02.foo.bar:7072<br>      - kafka03.foo.bar:7072</pre><p><strong>Prometheus.yml explanation:</strong></p><p>This is the Prometheus configuration file and as you can see we have 3 jobs ( prometheus itself, kafka_exporter and kafka)</p><p><strong>kafka_exporter</strong> . This job is one exporter container explained early that will collect kafka broker metrics. Prometheus will connect on this container through the port TCP 9308 to get metrics collected and store on it´s time series database.</p><p><strong>kafka. </strong>This job is the JMX exporter that runs on the kafka brokers as a javaagent. It runs on port TCP 7072 and Prometheus will connect on this port to get metrics and store on it´s time series database.</p><p><strong>JMX Exporter. </strong>To install this exporter I followed the <a href="https://www.robustperception.io/monitoring-kafka-with-prometheus/">instructions here</a></p><p>After download jmx_prometheus_javaagent-0.9.jar and kafka-0–8–2.yml , in each kafka broker, insert the javaagent<strong> </strong>on the<strong> kafka-server-start.sh</strong> file and insert the lines :<br>export PROMETHEUS_PORT=${PROMETHEUS_PORT:-7072}<br>javaagent:/opt/kafka/libs/jmx_prometheus_javaagent-0.9.jar=$PROMETHEUS_PORT:/opt/kafka/libs/kafka-0–8–2.yml</p><p>And restart each kafka services.</p><p>Example:</p><pre>#!/bin/bash<br># Licensed to the Apache Software Foundation (ASF) under one or more<br># contributor license agreements.  See the NOTICE file distributed with<br># this work for additional information regarding copyright ownership.<br># The ASF licenses this file to You under the Apache License, Version 2.0<br># (the &quot;License&quot;); you may not use this file except in compliance with<br># the License.  You may obtain a copy of the License at<br>#<br>#    <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>#<br># Unless required by applicable law or agreed to in writing, software<br># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,<br># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br># See the License for the specific language governing permissions and<br># limitations under the License.</pre><pre>if [ $# -lt 1 ];<br>then<br> echo &quot;USAGE: $0 [-daemon] server.properties [--override property=value]*&quot;<br> exit 1<br>fi<br>base_dir=$(dirname $0)</pre><pre>if [ &quot;x$KAFKA_LOG4J_OPTS&quot; = &quot;x&quot; ]; then<br>    export KAFKA_LOG4J_OPTS=&quot;-Dlog4j.configuration=file:$base_dir/../config/log4j.properties&quot;<br>fi</pre><pre>if [ &quot;x$KAFKA_HEAP_OPTS&quot; = &quot;x&quot; ]; then<br>    export KAFKA_HEAP_OPTS=&quot;-Xmx4G -Xms4G&quot;<br>fi</pre><pre>EXTRA_ARGS=${EXTRA_ARGS-&#39;-name kafkaServer -loggc&#39;}<br>export JMX_PORT=${JMX_PORT:-9999}<br>export PROMETHEUS_PORT=${PROMETHEUS_PORT:-7072}<br>COMMAND=$1<br>case $COMMAND in<br>  -daemon)<br>    EXTRA_ARGS=&quot;-daemon &quot;$EXTRA_ARGS<br>    shift<br>    ;;<br>  *)<br>    ;;<br>esac</pre><pre>exec $base_dir/kafka-run-class.sh $EXTRA_ARGS -javaagent:/opt/kafka/libs/jmx_prometheus_javaagent-0.9.jar=$PROMETHEUS_PORT:/opt/kafka/libs/kafka-0-8-2.yml kafka.Kafka &quot;$@&quot;</pre><p>Now you need to connect on Grafana on port 3000, configure the prometheus as a Data source and import the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-_iQZtpN3mxU1lzcJGr_A.png" /></figure><p><strong>Pause for reflection again</strong></p><blockquote>There are many <a href="https://docs.confluent.io/current/kafka/monitoring.html#broker-metrics">broker metrics</a> important to monitor and some of then is the <strong>LAG of consumers</strong> <strong>groups</strong> and <strong>under replicated partitions. </strong>The first is a metric that you need to pay attention because if the LAG are increasing, means that you should take a look if your consumers are running properly, or may be you need to scale then. The another means that your cluster are unstable due a network issues, or some broker is down, etc. Messages in Per Topics is interesting also because you can take a look if your cluster are receiving a traffic spike.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glkgCh0HdZx43jd79vWL3A.png" /></figure><p>To see these metrics available to monitor, you can do a query on Prometheus interface though port 9090. I encourage you to take a look on <a href="https://prometheus.io/docs/prometheus/latest/querying/basics/">PromQL</a> language to perform some queries and extract what really matter to you.</p><p>When you get the right query, you can create a graph on Grafana. Example of the Kafka consumers group LAG :</p><pre>sum(kafka_consumergroup_lag) by (consumergroup)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBvaPhPCkiexsoPrxvss3Q.png" /></figure><p>That´s it, thanks for reading!</p><p><strong>References</strong></p><p><a href="https://github.com/prometheus/jmx_exporter">https://github.com/prometheus/jmx_exporter</a><br><a href="https://prometheus.io/docs/prometheus/latest/querying/basics/">https://prometheus.io/docs/prometheus/latest/querying/basics/</a><br><a href="https://prometheus.io/docs/instrumenting/exporters/">https://prometheus.io/docs/instrumenting/exporters/</a><br><a href="https://github.com/danielqsj/kafka_exporter">https://github.com/danielqsj/kafka_exporter</a><br><a href="https://www.robustperception.io/monitoring-kafka-with-prometheus/">https://www.robustperception.io/monitoring-kafka-with-prometheus/</a><br><a href="https://grafana.com/dashboards/721">https://grafana.com/dashboards/721</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b97d2d5a5434" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka]]></title>
            <link>https://danielmrosa.medium.com/kafka-f8b6df58f1a?source=rss-42e3b7082f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8b6df58f1a</guid>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[zookeeper]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Daniel Rosa]]></dc:creator>
            <pubDate>Sat, 19 May 2018 23:56:58 GMT</pubDate>
            <atom:updated>2018-05-29T22:11:47.643Z</atom:updated>
            <content:encoded><![CDATA[<h4>Instalation &amp; Configuration</h4><p>Hi All,<br>This is my first post of many that I intend to write. I wish you could learn how to install and configure a cluster of Kafka and its dependency Zookeeper.</p><p>In this article, I´m installing a Kafka and Zookeeper cluster using virtual machines running CentOS 7, not using containers instead. I will skip the discussion about use Kafka and Zookeeper in containers.</p><p>Kafka uses Zookeeper to do leadership election of Kafka Broker and Topic Partitions and uses Zookeeper to manage service discovery for Kafka Brokers that form the cluster.</p><h3>What is Kafka ?</h3><h4>Apache Kafka® is a distributed streaming platform.</h4><p>A streaming platform has three key capabilities:</p><ul><li>Publish and subscribe to streams of records, similar to a message queue or enterprise messaging system.</li><li>Store streams of records in a fault-tolerant durable way.</li><li>Process streams of records as they occur.</li></ul><h4>Zookeeper Instalation &amp; Configuration<br>Steps to Install Zookeeper</h4><ol><li>Install the last version of Java</li><li>Download the last Zookeeper version <a href="https://zookeeper.apache.org/releases.html#download">here</a> , decompress on <strong>/opt </strong>and <strong>rename</strong> the directory to <strong>zookeeper</strong></li><li>Create a file /opt/zookeeper/conf/<strong>zoo.cfg</strong> like below<br>In this case, I´m using 3 servers.</li></ol><pre>tickTime=2000<br>dataDir=/var/lib/zookeeper<br>dataLogDir=/var/log/zookeeper<br>clientPort=2181<br>initLimit=5<br>syncLimit=2<br>server.1=zookeeper01.foo.bar:2888:3888<br>server.2=zookeeper02.foo.bar:2888:3888<br>server.3=zookeeper03.foo.bar:2888:3888<br>autopurge.snapRetainCount=3<br>autopurge.purgeInterval=1</pre><p>4. Create a file called <strong>java.env </strong>inside on <strong>conf </strong>directory to configure JVM flags<br>This configuration instruct Zookeeper to use only 2GB.</p><pre>export JVMFLAGS=”-Xmx2048m”</pre><p>5. Configure the Systemd Unit<br>create a file <strong>/etc/systemd/system/zookeeper.service</strong> and paste the script below:</p><pre>[Unit]<br>Description=ZooKeeper Service<br>Documentation=<a href="http://zookeeper.apache.org/">http://zookeeper.apache.org</a><br>Requires=network.target<br>After=network.target</pre><pre>[Service]<br>Type=forking<br>User=root<br>Group=root<br>ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg<br>ExecStop=/opt/zookeeper/bin/zkServer.sh stop /opt/zookeeper/conf/zoo.cfg<br>ExecReload=/opt/zookeeper/bin/zkServer.sh restart /opt/zookeeper/conf/zoo.cfg<br>WorkingDirectory=/var/lib/zookeeper</pre><pre>[Install]<br>WantedBy=default.target</pre><p>6. Create a myid file on each zookeeper server like below.<br><em>Server 1 will be the ID 1 , Server 2 will be the ID 2 and so on…</em></p><pre>echo “1” &gt; /var/lib/zookeeper/myid</pre><p>7. Enable and start zookeeper</p><pre>systemctl enable zookeeper.service &amp;&amp; systemctl start zookeeper.service</pre><p>8. Make sure Zookeeper are running on all servers</p><pre>systemctl status zookeeper</pre><h4>kafka Instalation &amp; Configuration</h4><p>Now that you installed the Zookeeper, It´s time to install and configure the cluster of Kafka brokers.</p><h4>Steps to Install Kafka</h4><ol><li>Install the last version of Java</li><li>Download the last Kafka version <a href="https://kafka.apache.org/downloads">here</a> , decompress on <strong>/opt </strong>and <strong>rename</strong> the directory to <strong>kafka</strong></li><li>Create a user and group kafka and change the ownership of /opt/kafka and /var/log/kafka-logs to kafka user</li></ol><pre>chown -R kafka:kafka /opt/kafka<br>chown -R kafka:kafka /var/log/kafka-logs</pre><p>4. Create a directory <strong>/var/log/kafka-logs</strong> to store Kakfa logs. It´s recommended to use a dedicated volume to store kafka logs.</p><p>5. Create a file /opt/kafka/conf/<strong>server.properties</strong> like below</p><pre>num.network.threads=3<br>num.io.threads=8<br>socket.send.buffer.bytes=102400<br>socket.receive.buffer.bytes=102400<br>socket.request.max.bytes=104857600<br>log.dirs=/var/log/kafka-logs<br>num.partitions=32<br>num.recovery.threads.per.data.dir=1<br>log.retention.hours=24<br>log.segment.bytes=1073741824<br>log.retention.check.interval.ms=300000<br>zookeeper.connection.timeout.ms=6000<br>zookeeper.connect=zookeeper01.foo.bar:2181,zookeeper02.foo.bar:2181,zookeeper03.foo.bar:2181<br>broker.id=1<br>controlled.shutdown.enable=true<br>default.replication.factor=3<br>delete.topic.enable=true</pre><p><strong>Notes</strong></p><blockquote>Each server must have the properly <strong>broker.id </strong>configuration</blockquote><blockquote>Configure the <strong>log.retention.hours</strong> according your needs. <strong>24</strong> Means that after 24 hours all messages inside on topics that were not consumed will be expired/lost.</blockquote><blockquote>Configure <strong>default.replication.factor </strong>according to the number of brokers you have. In this example is 3.</blockquote><p>6. Configure the Systemd Unit<br>create a file <strong>/etc/systemd/system/zookeeper.service</strong> and paste the script below:</p><pre>[Unit]<br>Description=Apache Kafka server (broker)<br>Documentation=http://kafka.apache.org/documentation.html<br>Requires=network.target remote-fs.target<br>After=network.target remote-fs.target<br><br>[Service]<br>Type=simple<br>PIDFile=/var/run/kafka.pid<br>User=kafka<br>Group=kafka<br>ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties<br>ExecStop=/opt/kafka/bin/kafka-server-stop.sh<br>Restart=on-failure<br>SyslogIdentifier=kafka<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>7. Enable and start Kafka</p><pre>systemctl enable kafka.service &amp;&amp; systemctl start kafka.service</pre><h3>Validate if Kafka is running properly</h3><p>Follow the steps below</p><h4>Create a Topic</h4><p>Let’s create a topic named “test” with a single partition and only one replica:</p><p>./kafka-topics.sh --create --zookeeper zookeeper01.foo.bar:2181 --replication-factor 1 --partitions 1 --topic test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*YeKGWcctzQbEoBulUMaAJg.png" /></figure><h4>List Topics</h4><p>./kafka-topics.sh --list --zookeeper zookeeper01.foo.bar:2181</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*Smyrh_e8vAkkzb8iWhOA1w.png" /></figure><h4>Send Messages</h4><p>Run the producer and then type a few messages into the console to send to the server.<br>./kafka-console-producer.sh --broker-list localhost:9092 --topic test</p><h4>Start a consumer</h4><p>Kafka also has a command line consumer that will dump out messages to standard output.</p><p>./kafka-console-consumer.sh --bootstrap-server kafka01.foo.bar:9092 --topic test --from-beginning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*6A_3FpETaorP9uy5GLelqg.png" /></figure><h3>References</h3><p><a href="https://kafka.apache.org/">https://kafka.apache.org</a><br><a href="https://docs.confluent.io/current/kafka/deployment.html">https://docs.confluent.io/current/kafka/deployment.html</a><br><a href="https://docs.confluent.io/current/zookeeper/deployment.html">https://docs.confluent.io/current/zookeeper/deployment.html</a></p><p>Thanks for reading. I will write soon a post related to how monitor the Kafka cluster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8b6df58f1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>