Coder Social home page Coder Social logo

service-health-checker's Introduction

Service health checker

This application plays two roles:

  • PUB Performs health checks on a target web service, collects metrics and sends them to Kafka broker;
  • SUB Reads Kafka topic and writes data to PostgreSQL table.

Design

KISS while both parts of this application might be implemented in async manner, I decided to refrain from this and keep things straightforward. This means that currently the scaling model will require more "workers" on both sides of Kafka.

Kickstart

Use docker, Luke!

This will start three docker containers locally and create a venv directory to hold python dependencies.

docker-compose up -d

Setup a new python virtual env with dependencies.

python3 -m venv venv
./venv/bin/pip install -r requirements.txt

Now we can run two parts of this program (in different shell sessions from this directory:

Reach the site twice a minute and send messages to Kafka.

export KAFKA_BROKER=localhost
export KAFKA_TOPIC=test
export TARGET="https://en.wikipedia.org/wiki/Special:Random"

./venv/bin/python metrics_flow.py pub --pattern foobar --delay 30

Wait for incoming messages from Kafka and relay them to database.

export KAFKA_BROKER=localhost
export KAFKA_TOPIC=test
export POSTGRESQL_DSN="host=localhost user=postgres password=postgres"

./venv/bin/python metrics_flow.py sub

See the results in the database.

PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -c "select * from test;" postgres

Parameters

This application uses argparse module which will show help page to you.

./venv/bin/python metrics_flow.py --help

SSL certificate could be used to authenticate against Kafka. See the --ssl-* arguments.

Most of the arguments are backed up by environment variables.

FAQ

Why not use docker-compose for all the pieces?

I have spent some time in debugging of connection timeouts in communication between Kafka broker and its clients. I saw name resolution issues as local python application wasn't able to send data to the broker while using container's name as the hostname. That issue was fixed by configuring KAFKA_CFG_ADVERTISED_LISTENERS option to point clients to localhost where the docker container is exposing the kafka broker's port.

Overall this application might also be containerised and started in a new docker network with all the supporting services after some changes in docker-compose. But running programs by hand brings much more fun (after some pain).

Post-scriptum

I want to dedicate this piece of work to my grandmother Nina who passed away this week. In my heart I keep warm memories of her house full of relatives gathered to celebrate her birthday on 7th of January (the Orthodox Christmas). I remember a long table with delicious food and a choir of old women singing traditional songs as entertainment. RIP

service-health-checker's People

Contributors

inesusvet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.