Skip to main content

· 2 min read
Hreniuc Cristian-Alexandru

Prometheus

To run a container with prometheus, we need two things:

  • prometheus.yml file
  • Docker volume

The prometheus.yml file should contain something like this:

# my global config
global:
scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 5s # Evaluate rules every 15 seconds. The default is every 1 minute.

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'docker'
static_configs:
- targets: ['localhost:9999']

- job_name: 'other_collector'
scrape_interval: 1s
static_configs:
- targets: ['192.168.1.28:8000']

To create a docker volume, run:

docker create volume prometheus_data

This way, your collected data won\'t be lost on restarts.

docker run -d --restart=always --name=prometheus --network=host -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml -v prometheus_data:/prometheus prom/prometheus

You should open the browser and check if everything works, by default it is 9090 port.

Grafana

For grafana we will also use a docker volume:

docker create volume grafana_data

This way we will save all data from grafana(panels, users, etc...).

To run the grafana container, simply run:

docker run -d --name=grafana --restart=always --network=host -e GF_SERVER_ROOT_URL=http://grafana.server.name -e GF_SECURITY_ADMIN_PASSWORD=secret -v grafana_data:/var/lib/grafana grafana/grafana

You can check it on port 3000.

Now you should add the Prometheus server as a data source. You can do this by going to Configuration -> Datasources -> Select Prometheus

· One min read
Hreniuc Cristian-Alexandru

For some countries the Ship From filter is missing. To filter manually you can add this to the url: &shipFromCountry=DE

· One min read
Hreniuc Cristian-Alexandru

LE: 14th Sept 2022 - Use regolith-linux instead or use Ubuntu and use the default keybindings that support some tilling.

  1. First step, you have to install i3``apt-get install i32. Go to LXpanel menu > Preferences > Default application for LXSession then go to tab Core applications and set to Window Manager: i33. Edit the autostart script by adding --desktop-off in the file ~/.config/lxsession/LXDE/autostart to the pcmanfm command, it should look like this after you edit it: @pcmanfm --desktop --profile LXDE. If the dmenu doesn\'t find your local binaries(the folders you added to the $PATH) you should create a ~/.xsessionrc and export the $PATH env variable there:
#!/bin/bash
# Content of ~/.xsessionrc


export PATH=${PATH}:${HOME}/.local/bin

Note: On archlinux + lxde I added that export in .xinitrc I was having some problems with lxpanel, it was taking too much resources so a I deactivated. I commented the line @lxpanel --profile LXDE from file ~/.config/lxsession/LXDE/autostart. #### Debian + xfce: I followed these steps: https://feeblenerd.blogspot.com/2015/11/pretty-i3-with-xfce.html bash apt-get install i3 Deactivated xfwm4 and xfdesktop from : \'Session and Startup\' -> \'Session\' tab.. Added i3 in \'Application Autostart\' tab. Removed all keybindings. Reboot.

· One min read
Hreniuc Cristian-Alexandru

LE: 14th Sept 2022 - Ubuntu 20.04 supports most of these out of the box now, with other keybinings.

Add these in :~/.config/openbox/lxde-rc.xml or ~/.config/openbox/lubuntu-rc.xml :

<!-- Keybindings for window tiling -->

<keybind key=C-W-Up> # FullScreen
<action name=Maximize/>
</keybind>
<keybind key=C-W-Down> # MiddleScreen
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>center</x><y>center</y><width>50%</width><height>50%</height></action>
</keybind>

<keybind key=C-W-Left> # HalfLeftScreen
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>0</x><y>0</y><height>100%</height><width>50%</width></action>
</keybind>
<keybind key=C-W-Right> # HalfRightScreen
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>-0</x><y>0</y><height>100%</height><width>50%</width></action>
</keybind>

<keybind key=C-W-1> # UpperQuarterLeft
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>0</x><y>0</y><height>50%</height><width>50%</width></action>
</keybind>

<keybind key=C-W-2> # LowerQuarterLeft
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>0</x><y>-0</y><height>50%</height><width>50%</width></action>
</keybind>

<keybind key=C-W-3> # LowerQuarterRight
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>-0</x><y>-0</y><height>50%</height><width>50%</width></action>
</keybind>

<keybind key=C-W-4> # UpperQuarterRight
<action name=UnmaximizeFull/>
<action name=MoveResizeTo><x>-0</x><y>0</y><height>50%</height><width>50%</width></action>
</keybind>

Add those inside <keyboard></keyboard>tags. Then run: openbox --reconfigureAdding a shortcut in lxde

· One min read
Hreniuc Cristian-Alexandru

Print lines that matches a regex starting from a line that matches another regex until an until a line that matches a different regex:

cat file | awk '/startling_regex_excluded/{next} /printable_regex/{print} /until_regex/{exit}'

Having this file:

text
text2
startling_regex_excluded
printable_regex
printable_regex
printable_regex
until_regex
test
printable_regex
printable_regex

The output will be:

printable_regex
printable_regex
printable_regex

AWK CheatSheet

Get all lines starting from a position:

awk '/start line/{flag=1;next}flag' file.log

· One min read
Hreniuc Cristian-Alexandru

LE: 14th Sept 2022 - Use Vue3 and you no longer need actions and mutations. Use State Management with Reactivity API

1. When you want to commit to a state(using actions and mutations), do not pass multiple parameters to the commit method, they will have the value undefined. Create an object and pass it like that. This:

commit(types.UPDATE_JOB, index, title);

Will become this:

commit(types.UPDATE_JOB, {index: index, title: job.title});

2. Props that have default value:

export default {
props: {
prop_without_defaut_value: {},
prop_with_defaut_value: {
default: false // this is a bool value
},
prop_with_defaut_value_string: {
default: String
}
},
data() {
return {
var_name: false
}
}
}

3. Use mapActions and custom methods:

methods: Object.assign({},
/* If we want to use mapActions and other
custom methods this is the way to do it
otherwise it will give an error */
mapActions([
'action_1',
'action_2'
]), {
method_1() {
this.title = this.job.title;
this.edit_mode = !this.edit_mode;
},
method_2() {}
}
),

· 3 min read
Hreniuc Cristian-Alexandru

Debian host - ubuntu docker:

# Allow x11 forwarding
xhosts +

docker run --rm=true --name="container_name" -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix -it image_name /bin/bash
# This is the most important part from the command:
# -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix

Run GUI apps on docker without xserver installed on host

We have three layers: A -> My desktop PC**B -> Host server(runs docker) C -> docker container that runs on BHow to connect to C and run a GUI app from A? Without having installed xserver on B** (no -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix options given to the docker run command). I did it this way:

  1. Create a docker image with ssh running on it: Here
  FROM ubuntu:16.04

RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE in users profile
RUN echo export VISIBLE=now >> /etc/profile

EXPOSE 22
CMD [/usr/sbin/sshd, -D]
  1. Build the image: docker build -t ubuntu_sshd .

  2. Run the container: docker run -d -P --name test_sshd ubuntu_sshd

  3. Get port of the docker container: docker port test_sshd 22

  4. Now connect to it using ssh:

    ssh root@ip -p port
    # The password is ``screencast``.
    root@f38c87f2a42d:/#
  5. Enable X11Forwarding : Add X11Forwarding yes to /etc/ssh/sshd_config

  6. Disable X11UseLocalhost : Add X11UseLocalhost no to /etc/ssh/sshd_config

  7. Reload ssh config: /etc/init.d/ssh reload

  8. Exit from the ssh session

  9. All those commands were made from the B machine(from 5 - 8 were run on the docker container)

  10. Now go to your desktop machine A and connect via ssh on the docker machine(also enable x forwarding on your destktop PC), using the ip of B and the port you got from the command at step 4:

  # Allow xserver forward(allow clients to connect to your x server)
$ xhost +
# Connect via ssh and forward the xserver `-X`
$ ssh -X root@B_host_ip -p docker_port
# The password is ``screencast``.
root@f38c87f2a42d:/# apt-get install x11-apps -y
root@f38c87f2a42d:/# xeyes
# Magic happens!!!

Debian:

# Debian with sshd
FROM debian
RUN apt-get update

RUN apt-get install -y openssh-server

RUN echo 'root:password' | chpasswd

RUN mkdir -p /var/run/sshd && sed -i s/UsePrivilegeSeparation.*//g /etc/ssh/sshd_config \
&& sed -i 's/PermitRootLogin without-password//' /etc/ssh/sshd_config \
&& touch /root/.Xauthority \
&& true

RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config

RUN echo X11UseLocalhost no >> /etc/ssh/sshd_config
RUN echo PermitRootLogin yes >> /etc/ssh/sshd_config
RUN echo UsePrivilegeSeparation no >> /etc/ssh/sshd_config

EXPOSE 22

CMD [/usr/sbin/sshd, -D]

· One min read
Hreniuc Cristian-Alexandru

Install nodejs in a specific path:

echo 'export PATH=$HOME/programs/bin:$PATH' >> ~/.bashrc
# the `programs` dir should exist, the `bin` will be
# created if it doesn't exist, when you will be running `./configure`
source ~/.bashrc
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/programs # your prefix
make install# --j8
# The `make install` step takes a lot, you should do it on multiple threads using --j option

Install npm on specific path:

wget https://registry.npmjs.org/npm/-/npm-5.8.0.tgz # specify what version you want 
tar xzf npm-5.8.0.tgz
cd package/
node bin/npm-cli.js install -gf --prefix=~/programs/ ../npm-5.8.0.tgz
# use the prefix where node was installed

Test them both:

node -v
#
npm -v

· One min read
Hreniuc Cristian-Alexandru

In your application you have to copy the dynamic libraries to the user space from the local cache. To do that you have to have the import method in the conanfile.py from your application. You will have to paste this code in the conanfile.py from your project:

def import(self):
self.copy(*.dll, bin, bin)
self.copy(*.dylib, bin, bin)

Here is the official documentation of the method: http://docs.conan.io/en/latest/reference/conanfile/methods.html#imports