Skip to content

FarshidNooshi/Computer-Networking-Final-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In The Name of GOD

License: MIT

Computer Networking Project

The final project of Computer Network course at the Amirkabir University of Technology. The project is the implementation of a monitoring prometheus metric client that receive metrics from different agent programs and merge them in prometheus metrics and expose them for Prometheus Scraper.

What is Prometheus?

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project's governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.
Prometheus collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.

Requirements

the following requirements are needed for the project:

psutil
colorama
setuptools
prometheus-client

you should also download and install the prometheus for your system from the following link:
Prometheus Download Page

For installation, you can run the following command:

pip install -r requirements.txt

How to run the project

  1. replace the Project/prometheus.yml file with the prometheus.yml file of the one you downloaded from the link above.

  2. run prometheus in your system.

  3. inorder to run the project, you should run the following command in the Project/src/Client folder:

python3 main.py
  1. In a separate terminal, you should run the following command in the Project/src/Server folder:
python3 main.py

Metrics

I have implemented 5 metrics, but you can add more metrics by following the following steps:

  1. Add the metrics name in metrics field in Project/src/Business/json/data.json data file.
  2. Add the same metrics name in the metrics dictionary at the create_metrics method in the client.py file and give its value for each message to server.
@staticmethod
def create_metrics():
   metrics = {
       'cpu_utilization_percent': psutil.cpu_percent(interval=1),
       'memory_available': psutil.virtual_memory().available,
       'num_bytes_sent': psutil.net_io_counters().bytes_sent,
       'num_errors_recv': psutil.net_io_counters().errin,
   }
   return metrics
  1. Create the required metric at server side for handling in the Project/src/Server/Utils/ClientHandler.py file.
def create_metrics(self):
    self.cpu = Gauge(f'cpu_utilization_percent', 'percentage of cpu usage right now.', labelnames=['client_name'])
    self.mem = Gauge(f'memory_available', 'available memory in bytes.', labelnames=['client_name'])
    self.net = Counter(f'network_usage_total', 'total number of received bytes.', labelnames=['client_name'])
    self.client_net = Counter(f'network_send_total', 'total number of send bytes.', labelnames=['client_name'])
    self.err_net = Counter(f'received_error_total', 'total number of errors while receiving.',
                           labelnames=['client_name'])
  1. At the same file like 3 you should add the update instruction for each metric like below:
def update_metrics(self, client_name, metrics, sz):
    self.cpu.labels(client_name=client_name).set(metrics['cpu_utilization_percent'])
    self.net.labels(client_name=client_name).inc(sz)
    self.mem.labels(client_name=client_name).set(metrics['memory_available'])
    self.client_net.labels(client_name=client_name).inc(metrics['num_bytes_sent'])
    self.err_net.labels(client_name=client_name).inc(metrics['num_errors_recv'])
  1. done!

Screenshots

Image Image Image Image

Contributors

About

Computer Networking final project for CE at AUT Course

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages