deepstream-tracker參數調整

Accuracy-Performance Tradeoffs

下面這些參數的調整將會影響到準確度和效能。

Visual Feature Types and Feature Sizes

Visual feature types

  • useColorNames
  • useHog

Feature sizes

  • featureImgSizeLevel
  • searchRegionPaddingScale

Linux下的Docker更改image儲存位置

官方方法

修改/etc/docker/daemon.json加入下面設定

1
2
3
{
"data-root": "/mnt/docker-data"
}

重新啟動docker service

1
2
sudo systemctl stop docker.service
sudo systemctl start docker.service

確認路徑已經修改

1
docker info | grep "Docker Root Dir"

https://docs.docker.com/config/daemon/#daemon-data-directory

步驟參考(Docker更新後原本設定的位置會被改回去,不推薦)

https://linuxconfig.org/how-to-move-docker-s-default-var-lib-docker-to-another-directory-on-ubuntu-debian-linux

Linux使用SOCKS5-proxy上網

簡介

這裡將介紹一個只需要使用SSH連線到一台可以連到對網網路的主機,就可以讓防火牆內的主機上網的方法
圖片說明

注意Docker pull沒辦法用proxychains,解法在後面

利用ssh連接到可以上網的機器

首先本機電腦和遠端電腦都必須有ssh server
首先在本機電腦ssh登入到遠端沒有外網的遠端電腦,然後在遠端電腦使用以下指令連回去本機電腦建立一條SOCKS5 proxy的通道。

1
ssh -D 4444 -q -C -N local_username@192.168.50.1

檢查SOCKS是否開通了

https://superuser.com/questions/303251/how-to-check-if-a-socks5-proxy-works

遠端電腦用以下指令可以檢查開通的port

1
netstat -tlnp

假設我們在4444port開SOCKS proxy,如果有成功開啟SOCKS proxy,應該會看到下面這行

1
tcp        0      0 127.0.0.1:4444          0.0.0.0:*               LISTEN  

安裝Proxychains4

https://blog.csdn.net/leishupei/article/details/120736869
sudo apt-get install proxychains4

在還沒安裝Proxychains4機器上用SOCKS5安裝Proxychains4

1
2
3
 apt -o Acquire::http::Proxy="socks5h://127.0.0.1:4444" -o Acquire::https::Proxy="socks5h://127.0.0.1:4444" update

apt -o Acquire::http::Proxy="socks5h://127.0.0.1:4444" -o Acquire::https::Proxy="socks5h://127.0.0.1:4444" install proxychains4

設定Proxychains4

https://feifei.tw/proxychains4/

sudo nano /usr/local/etc/proxychains.conf
proxy_dns 的功能不要關掉

設定檔位置
https://askubuntu.com/a/1477936

手動設定DNS server

export DNS_SERVER=8.8.8.8

https://github.com/rofl0r/proxychains-ng/issues/178#issuecomment-347439800

測試apt指令

proxychains4 sudo apt install zip

docker pull 無法使用proxychains4的解法

1
2
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/proxy.conf
1
2
3
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:4444"
Environment="HTTPS_PROXY=socks5://127.0.0.1:4444"
1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

https://docs.docker.com/engine/daemon/proxy/

https://markvanlent.dev/2022/05/10/pulling-docker-images-via-a-socks5-proxy/

elasticsearch API

search

使用keyword使得搜尋條件必須完全符合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
GET people-2023.04/_search
{ "query":
{
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gt" : "2023-04-08T10:22:28Z",
"lt" : "2023-04-08T10:22:44Z"
}
}
},
{
"match": {
"StreamID.keyword": "eb2baea2-d52c-434c-af44-256c0301f4df"
}
}
]
}
}
}

delete

1
2
3
4
5
6
7
8
9
10
POST poc/_delete_by_query
{
"query":{
"range":{
"@timestamp":{
"gt" : "2018-05-04T23:04:00Z"
}
}
}
}

樹梅派學習Liunx

CH1

  • 樹梅派不適合做real-time的應用
  • 樹梅派不適合作為production的應用,如果要做成production的應用,可以考慮BeagleBone
  • 其他參考資源:
  • 建議購買的配件
    • USB to Serial UART TTL 3.3 V (for Finding Problems)線,可以用於透過USB就可以使用command line控制樹梅派

logstash設定教學

設定檔編寫

logstash基本元素

input, filter, 和 output,每個元素可能一個或多個

建立一個基本的pipeline

下面建立一個基本的pipeline,從stdin讀取資料,然後輸出到stdout。我們將建立一個first-pipeline.conf並且放在C:\ELK\logstash-7.17.3\logstash-7.17.3(與bin同一個資料夾)

1
2
3
4
5
6
7
8
9
10
11
12
13
# The # character at the beginning of a line indicates a comment. Use
# comments to describe your configuration.
input {
stdin { }
}
# The filter part of this file is commented out to indicate that it is
# optional.
# filter {
#
# }
output {
stdout {}
}

檢查pipeline語法

打開powershell,利用以下指令檢查pipeline語法,注意要確認沒有任何錯誤,因為檢查程式如果找不到檔案位置最後也會顯示檢查OK。
我們在C:\ELK\logstash-7.17.3\logstash-7.17.3輸入以下指令bin/logstash -f first-pipeline1.conf --config.test_and_exit

輸出如下

1
2
3
4
5
6
7
8
9
10
11
Using LS_JAVA_HOME defined java: C:\ELK\logstash-7.17.3\logstash-7.17.3\jdk\
WARNING: Using LS_JAVA_HOME while Logstash distribution comes with a bundled JDK.
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Sending Logstash logs to C:/ELK/logstash-7.17.3/logstash-7.17.3/logs which is now configured via log4j2.properties
[2023-05-05T14:24:31,585][INFO ][logstash.runner ] Log4j configuration path used is: C:\ELK\logstash-7.17.3\logstash-7.17.3\config\log4j2.properties
[2023-05-05T14:24:31,601][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.17.3", "jruby.version"=>"jruby 9.2.20.1 (2.5.8) 2021-11-30 2a2962fbd1 OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +indy +jit [mswin32-x86_64]"}
[2023-05-05T14:24:31,601][INFO ][logstash.runner ] JVM bootstrap flags: [-Xms1g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djruby.compile.invokedynamic=true, -Djruby.jit.threshold=0, -Djruby.regexp.interruptible=true, -XX:+HeapDumpOnOutOfMemoryError, -Djava.security.egd=file:/dev/urandom, -Dlog4j2.isThreadContextMapInheritable=true]
[2023-05-05T14:24:31,761][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2023-05-05T14:24:32,816][INFO ][org.reflections.Reflections] Reflections took 78 ms to scan 1 urls, producing 119 keys and 419 values
Configuration OK
[2023-05-05T14:24:33,781][INFO ][logstash.runner ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash

自動重載設定檔

檢查通過後我們用--config.reload.automatic選項重新載入設定檔,如此一來就不用一直重啟程式。在過程中你可能會看到忽略pipelines.yml的警告,因為我們已經在命令中明確指定要用的設定檔了,所以可以忽略這個警告,之後我們再學習使用pipelines.yml

bin/logstash -f first-pipeline.conf --config.reload.automatic

等到看到[main] Pipeline started {"pipeline.id"=>"main"}這個訊息後,我們可以直接輸入一些文字,按下enter,就可以看到輸入的文字被輸出到stdout了。
例如入Hello wordl後按下Enter,結果如下

1
2
3
4
5
6
7
Hello World
{
"@version" => "1",
"host" => "eastcoastVM01",
"message" => "Hello World\r",
"@timestamp" => 2023-05-05T06:32:33.396Z
}

使用 Grok Filter 外掛程式(Plugin)

Grok是眾多logstash外掛程式的其中一個,這裡可以看到更多關於logstash的外掛程式。

grok filter plugin可以幫我們將沒有結構化的log轉化成結構化的log

多個資料來源

以下範例是多個資料來源,分別來自twitter和firebeat,輸出也有多個,分別為elasticsearch和寫到檔案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
input {
twitter {
consumer_key => "enter_your_consumer_key_here"
consumer_secret => "enter_your_secret_here"
keywords => ["cloud"]
oauth_token => "enter_your_access_token_here"
oauth_token_secret => "enter_your_access_token_secret_here"
}
beats {
port => "5044"
}
}
output {
elasticsearch {
hosts => ["IP Address 1:port1", "IP Address 2:port2", "IP Address 3"]
}
file {
path => "/path/to/target/file"
}
}

建立一個接收rabbitmq訊號的範例

解析rabbitmq訊號

在input中我們可以加入input plugin,這裡我們使用rabbitmq plugin,先建立一個最簡單的範例並且將解析結果輸出到console。
在rabbitmq plugin中的說明文件有提到,預設的輸出是json codec

設定rabbitmq的參數在這裡,我們會需要設定rabbitmq的連線資訊,範例如下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# The # character at the beginning of a line indicates a comment. Use
# comments to describe your configuration.
input {
rabbitmq {
host => "localhost"
port => 5672
username => guest
password => guest
}
}
# The filter part of this file is commented out to indicate that it is
# optional.
# filter {
#
# }
output {
stdout {}
}

抽取事件中的欄位

有時候我們會需要依據事件中欄位的資料做一些處理,Field Reference可以幫助我們抽取事件中的欄位。以下事件為範例
,如果要取得第一階的欄位如agent, ip, request, response, ua,只需要一個[]就可以取得例如[request],如果是第二階欄位如os則要用[ua][os]

1
2
3
4
5
6
7
8
9
10
11
12
{
"agent": "Mozilla/5.0 (compatible; MSIE 9.0)",
"ip": "192.168.24.44",
"request": "/index.html"
"response": {
"status": 200,
"bytes": 52353
},
"ua": {
"os": "Windows 7"
}
}

對欄位操作Mutate filter plugin

https://www.elastic.co/guide/en/logstash/7.17/plugins-filters-mutate.html#plugins-filters-mutate-replace

檢查子欄位是否存在

https://github.com/elastic/logstash/issues/10215#issuecomment-447912618

加入一個filed,其值是一個sub field

https://stackoverflow.com/a/39126309

設定watchdog

測試watchdog

L4T已經預設有watchdog,可以透過下面指令測試,他預設的機制是如果有人讀取/dev/watchdog這個檔案,他就會開始倒數計時,如果有人寫入檔案,則timer重置,下面指令將會讓watchgod重啟系統。

1
sudo tail -f /dev/watchdog

如果要避免重啟就必須寫入/dev/watchdog檔。或是結束tail -f

https://forums.developer.nvidia.com/t/configuring-watchdog-timer-on-tx1/44361/2?u=jenhao

參考:
官方文件下載區
https://developer.nvidia.com/embedded/downloads