Code Monkey home page Code Monkey logo

pinga's Introduction

CI Maintainability Test Coverage

Pinga - A simple website status checker

Pinga is website status checker written in Python. It consists of two independent components. On one hand, there is a producer that asynchronously and periodically (every 5 seconds) checks a given list of websites and sends the results as events to a configured aiven Kafka cluster. The second component is a consumer of Kafka messages that will process the produced events and persist them in a configured aiven PostgreSQL database.

Given the nature of Kafka, both processes above are independent from each other and can be executed in any given order.

Dependencies

  • Python 3
  • gevent
  • kafka-python
  • psycopg2
  • jsonschema
  • requests
  • aiven for Apache Kafka
  • aiven for PostgreSQL

Setup of aiven services and Pinga configuration

At this stage of development, Pinga relies on two DBaaS products: aiven for Apache Kafka and aiven for PostgreSQL. It is assumed that those services are provisioned and running. Please refer to aiven documentation for details about setting up those services.

Pinga configuration is set in the pinga.cfg file. It consists of three sections, kafka, postgres and checker.

kafka

This section specifies the aiven Kafka cluster that Pinga will connect to. Please replace the placeholders for service_uri, ssl_cafile, ssl_certfile and ssl_keyfile with the appropriate values. They can be easily retrieved from the aiven console.

IMPORTANT: it is assumed that a topic named 'pinga-events' is available

postgres

This section defines the PostgreSQL instance where events will be saved. Please fill the service_uri with the value provided by the aiven console.

IMPORTANT: it is assumed that a database named 'pinga-events' is available with write permissions

checker

This section specifies a JSON file containing a list of websites to be checked by Pinga. An example is provided and named sites.json.

Running Pinga components using docker-compose

The easiest way to see Pinga working is by running the provided docker-compose configuration.

$ docker-compose up

The command above will run both Pinga Producer and Pinga Consumer in separate containers.

In case of code changes, docker-compose build must be executed before restarting.

Running Pinga components separately as standalone processes

Pinga Producer

The producer is responsible for making periodic checks and send the results to the Kafka cluster. It can be run as a standalone process by doing the following:

$ ./pinga.sh producer

Pinga Consumer

The consumer connects to the Kafka cluster, subscribes to the topic and consumes the messages as they arrive. All events are persisted in PostgreSQL right after consumption. The consumer can be executed by doing the following:

$ ./pinga.sh consumer

Running the tests

The unit tests were written based on pytest. They can be executed by following these steps:

$ python3 -m venv .venv-tests
$ source .venv-tests/bin/activate
$ pip3 install -r requirements.txt
$ pip3 install -r requirements-dev.txt
$ pytest -v

Assuming the above is done, test coverage data can be generated by running coverage.

$ coverage run --source ./pinga -m pytest
$ coverage report -m

CI

Tests and Code Climate checks are done for every PR. GitHub Actions is triggered for every PR and after a merge into master.

Links

Further documentation and references

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.