In
Read more here:
- https://docs.docker.com/engine/swarm/manage-nodes/#update-a-node
The great thing about this labeling is in docker compose file that you can tell docker which server should get deployed on which server (node):
#docker #node #swarm #label #role
docker
swarm mode you can list nodes with docker node ls
. If you want to assign a label to each node you can use the below command to update node labels. For example you can assign a key=value
pair like role=storage
to one of your node listed with the first command:docker node update --label-add role=storage YOUR_HOSTNAME
Read more here:
- https://docs.docker.com/engine/swarm/manage-nodes/#update-a-node
The great thing about this labeling is in docker compose file that you can tell docker which server should get deployed on which server (node):
deploy:
replicas: 4
placement:
constraints:
- node.labels.role == storage
NOTE:
role
is something that we ourselves have been defined. You can define your own as requirements vary.#docker #node #swarm #label #role
Docker Documentation
Manage nodes in a swarm
Manage existing nodes in a swarm
پیروزی ایران بر مراکش رو خدمت تمامی فوتبال دوستان و ایران دوستان تبریک میگم. به امید موفقیتهای بیشتر
🇮🇷🇮🇷🇮🇷🇮🇷🇮🇷
🇮🇷🇮🇷🇮🇷🇮🇷🇮🇷
این موضوع نسبتا بی ربط به بحث کانال رو دوستان لطفا بخونند و تحمل کنند، پیشاپیش عذر خواهی میکنم:
If you have worked with
When you run it in linux you would see IO, CPU, RAM, Network bandwidth, latest system errors, etc in one glance! When you run it it displays the heaviest process on top by default. Read about its UI, installation, etc here:
- https://www.tecmint.com/glances-an-advanced-real-time-system-monitoring-tool-for-linux/
#linux #htop #glance
htop
you would definitely love Glance
, an advanced real time system monitoring tool for Linux
.When you run it in linux you would see IO, CPU, RAM, Network bandwidth, latest system errors, etc in one glance! When you run it it displays the heaviest process on top by default. Read about its UI, installation, etc here:
- https://www.tecmint.com/glances-an-advanced-real-time-system-monitoring-tool-for-linux/
#linux #htop #glance
Glances – An Advanced Real Time System Monitoring Tool for Linux
Glances: A Powerful Tool for Monitoring Linux Systems
Glances is a cross-platform curses-based system monitoring tool written in Python language which uses the psutil library to grab information from the system.
Tech C**P
#glance
You can use
Grafana
to display your OS metrics. You can use its API endpoints to get data in JSON or XML and moreover it provides a web UI for you to take look at the graphs.By default when you install
If you take a look at the config rotation of nginX you will see a part called postrotate that run a command, for nginx it is as below:
If you run the command between
Just remove a file related to
Now you can run
Now every log will be directed to its file not
#nginx #policy_rc #invoke_rc #log_rotate #rotate
nginX
on Linux
a logrotate config file will be created in /etc/logrotate.d/nginx
. Sometimes you may see that after a while logs inside of nginX access log is empty and it is logged into the file usually named access.log.1
. This error happens when a process cannot close its file handler and has to write into access.log.1.If you take a look at the config rotation of nginX you will see a part called postrotate that run a command, for nginx it is as below:
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
If you run the command between
postrotate
and endscript
it may gives the below error:invoke-rc.d: action rotate is unknown, but proceeding anyway.
invoke-rc.d: policy-rc.d denied execution of rotate.
Just remove a file related to
i-MSCP
:rm /usr/sbin/policy-rc.d
NOTE:
Or if you want to be safe rename it to something else.Now you can run
invoke-rc.d
command and you should see a result like below:[ ok ] Re-opening nginx log files: nginx.
Now every log will be directed to its file not
it_file_name.log.1
, and file handlers are closed safely.#nginx #policy_rc #invoke_rc #log_rotate #rotate
There are times that you noway but getting data from a third part library and that library has rate limit on their endpoints. For example I have recently used
This library by default sends its requests to
Now read from cache in case it exists:
Make sure to put
#python #geopy #geo #latitude #longitude #Nominatim #redis #hset #geocoders
geopy
python library to get latitude and longitude by giving city name to the function:from geopy.geocoders import Nominatim
city_name = 'Tehran'
geolocator = Nominatim()
location = geolocator.geocode(city_name)
print location.latitude, location.longitude
This library by default sends its requests to
https://nominatim.openstreetmap.org/search
to get geo location data. It's rate limit is 1 request per second. To circumvent these problems and limitations use redis to cache results in your server and read cached result from your own system:self.redis.hset(city_name, 'lat', lat)
self.redis.hset(city_name, 'long', longitude)
Now read from cache in case it exists:
if self.redis.hexists(city_name, 'lat'):
location = self.redis.hgetall(city_name)
Make sure to put
sleep(1)
when reading from Nominatim
in order to by pass its limitation.NOTE:
instead of Nominatim
other 3rd parties can be used.#python #geopy #geo #latitude #longitude #Nominatim #redis #hset #geocoders
Apply new basic license on
You need to download the license first:
- https://register.elastic.co/xpack_register
The license is a json file that can be applied by
#kibana #curl #license #elasticsearch
Kibana
:You need to download the license first:
- https://register.elastic.co/xpack_register
The license is a json file that can be applied by
cURL
, first go to your server where elasticsearch is running and then:curl -XPUT 'http://172.16.133.102:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
NOTE:
license.json is the file that should be present beside from where you are issuing the cURL
command.#kibana #curl #license #elasticsearch
register.elastic.co
Register | Elastic
space=$(df -k / | tail -1 | awk '{print $4}')
echo "free disk space is $space"
if [ $space -lt 510000 ]
then
echo $(date) + " - Purge elasticsearch indexes..."
curl -X DELETE "http://localhost:9200/your_index_name_*"
echo ''
else
echo $(date) + " - disk space seems OK"
fi
Put this in a
crontab
and you are good to go.#linux #sysadmin #bash #script #df #elasticsearch #es
tail
command in Linux
is used to see content of a file from the end. It is usually used for checking log files in server. The interesting thing about tail
is that you can use this command to get the last line. So in a bash script if you want to get last row of the below output:root@server:~# ls -l
total 24
-rw-r--r-- 1 root root 291 May 26 05:19 es_queries
-rw-r--r-- 1 root root 1198 Jun 19 10:34 users.json
-rwxr-xr-x 1 root root 272 Jun 19 11:22 monitor_disk_space.sh
-rwxr-xr-x 1 root root 433 Jun 19 10:00 another_script.sh
You would do:
root@server:~# ls -l | tail -1That's why we have used this command in the previous post on
-rwxr-xr-x 1 root root 433 Jun 19 10:00 another_script.sh
df -k /
.#bash #tail #script #ls
Have you ever wanted to syntax highlight text area with specific content in it? Let's say it contains json data. We also need to have
code folding (+/- in front of objects to collapse them). The tool that can be used for this purpose is
- https://codemirror.net/index.html
One of the things that I want to note here is that textarea wont get updated when you enter data in codeMirror field. For that you need to call save() method of codeMirror like below:
Download all the demos from github:
- https://github.com/codemirror/codemirror
Instead of myEditor change you can update textarea on form submit.
#syntax_highlighting #syntax #codeMirror #code_folding
code folding (+/- in front of objects to collapse them). The tool that can be used for this purpose is
codeMirror
:- https://codemirror.net/index.html
One of the things that I want to note here is that textarea wont get updated when you enter data in codeMirror field. For that you need to call save() method of codeMirror like below:
var myEditor = CodeMirror.fromTextArea(page_content, {
lineNumbers: true,
mode: "markdown",
lineWrapping: true,
lineNumbers:false,
indentWithTabs: true
});
function updateTextArea() {
myEditor.save();
}
myEditor.on('change', updateTextArea);
Download all the demos from github:
- https://github.com/codemirror/codemirror
Instead of myEditor change you can update textarea on form submit.
#syntax_highlighting #syntax #codeMirror #code_folding
codemirror.net
In-browser code editor
pyflame, a fantastic python profiler that uses linux ptrace system call to collect profiling information. It gives you a graph to see where you have messed things up!
One of the great great great things about this library is that you can attach it to a currently running process to profile it. A command like below will do the job:
Code and installation can be found in github:
- https://github.com/uber/pyflame
Read more about it:
- https://pyflame.readthedocs.io/en/latest/
#python #pyflame #profiler
One of the great great great things about this library is that you can attach it to a currently running process to profile it. A command like below will do the job:
# Attach to PID 12345 and profile it for 1 second
pyflame -p 12345
Code and installation can be found in github:
- https://github.com/uber/pyflame
Read more about it:
- https://pyflame.readthedocs.io/en/latest/
#python #pyflame #profiler
GitHub
GitHub - uber-archive/pyflame: 🔥 Pyflame: A Ptracing Profiler For Python. This project is deprecated and not maintained.
🔥 Pyflame: A Ptracing Profiler For Python. This project is deprecated and not maintained. - GitHub - uber-archive/pyflame: 🔥 Pyflame: A Ptracing Profiler For Python. This project is deprecated and ...