Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
ngxtop - real-time metrics for nginx server (and others)

ngxtop parses your nginx access log and outputs useful, top-like, metrics of your nginx server. So you can tell what is happening with your server in real-time. ngxtop tries to determine the correct location and format of nginx access log file by default, so you can just run ngxtop and having a close look at all requests coming to your nginx server. But it does not limit you to nginx and the default top view. ngxtop is flexible enough for you to configure and change most of its behaviours. You can query for different things, specify your log and format, even parse remote Apache common access log with ease. See sample usages below for some ideas about what you can do with it.


Installation:

pip install ngxtop


It is easy as pie, you just need to run it and look at the results:

nxtop

It will reports for total requests served and total bytes sent to client and will report requests based on their status code. At the pictures in the next post you can see sample usages.

#linux #nginx #top #nxtop #web_server
View top source IPs of clients #nxtop
Default output #nxtop
List 4xx or 5xx responses together with HTTP referer #nxtop
Did you know you can syntax highlight your codes in google docs using an add on?

This is code block! An addon that adds syntax highlighting to your documents. In order to download it, go to Add-ons menu in google docs and click on Get add-ons. Search for code block and install it.

After installation Code Block option will be added to Add-ons menu. Click it and hit Start. Now you will have a great syntax highlighting right in your toolbox. :)

Happy syntax highlighting! :D

#google #code #syntax_highlight #code_block #addon #google_doc
How to create a network scanner in python using socket?

socket library is used to work with network and here we use it to simulate a network scanner.

A network scanner iterates over all the possible IP addresses on the network and for every IP it tries to connect to one of the ports. If the connection was successful (ACK received) we know that this host is available at the given IP address. This is the philosophy of a network scanner.

For now we just try to connect to a specific port of the server and leave the other parts to you to iterate and check the status:

import socket

addr = '172.16.132.20'
port = 27017

socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = socket_obj.connect_ex((addr,port))
print result
socket_obj.close()

The above code connects to the given address:port and returns a status code. If returned code is 0 then the
port is open otherwise the port is probably blocked/closed.

#python #socket #network #tcp #tcp_scanner
PostgreSQL: Up and Running: A Practical Guide to the Advanced Open Source Database #ebook #book #pdf
How to use regex in MongoDB?

I had a query that I had to find records that their numbers does not start with +98. For regex you need to use $regex in MongoDB find query:

db.my_collection.find({'destination_number': {'$regex': '^(?!\\+98)(\\+.*).*$'}})

The above regex says that the number should not start with +98 and then it says that it should start with + (to ignore non-standard numbers, strings, etc).

NOTE: ?! is used to negate the regex inside of parenthesis.

#mongodb #mongo #regex
What is CDN?

CDN is short for content delivery network. A content delivery network (CDN) is a system of distributed servers (network) that deliver pages and other Web content to a user, based on the geographic locations of the user, the origin of the webpage and the content delivery server.

This service is effective in speeding the delivery of content of websites with high traffic and websites that have global reach. The closer the CDN server is to the user geographically, the faster the content will be delivered to the user. CDNs also provide protection from large surges in traffic.


What are the benefits of using a CDN?

- Improving website load times
- Reducing bandwidth costs
- Increasing content availability and redundancy
- Improving website security


Telegram is an example of those services that use CDN in order to serve public channels media to end users with faster pace.

#cdn #content_delivery_network #telegram
504 Gateway timeout

It is a known issue to many people even those who are not in the programming field. 504 timeout happens when a response for a request has taken longer than expected. There are times that you know and are sure that you need to increase this time. For example if users export a huge excel file as a report. In nginx you can increase this time to what seems to be appropriate from programmer point of view.

In nginx.conf usually in /etc/nginx/ do as follow:

proxy_connect_timeout       600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;

More info: http://nginx.org/en/docs/http/ngx_http_proxy_module.html


#504 #gateway_timeout #timeout #nginx #proxy_read_timeout #proxy_send_timeout