Home Changing Prometheus TSDB directory
Post
Cancel

Changing Prometheus TSDB directory

Changing Prometheus data directory

  1. Stop prometheus and take backup
    1
    2
    
    systemctl stop prometheus
    sudo cp -vr /var/lib/prometheus /opt/intersec/prometheus_backup
    
  2. Create new data directory
1
2
chown -R prometheus:prometheus /data
sudo -u prometheus mkdir /data/prometheus
  1. Change prometheus service to use new directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
After=network-online.target
Requires=local-fs.target
After=local-fs.target

[Service]
Type=simple
Environment="GOMAXPROCS=8"
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
  --storage.tsdb.path=/data/prometheus \  <---------- CHANGE DIRECTORY HERE
  --storage.tsdb.retention.time=30d \
  --storage.tsdb.retention.size=0 \
  --web.config.file=/etc/prometheus/web.yml \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.console.templates=/etc/prometheus/consoles \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url= \
  --config.file=/etc/prometheus/prometheus.yml

CapabilityBoundingSet=CAP_SET_UID
LimitNOFILE=65000
LockPersonality=true
NoNewPrivileges=true
MemoryDenyWriteExecute=true
PrivateDevices=true
PrivateTmp=true
ProtectHome=true
RemoveIPC=true
RestrictSUIDSGID=true
#SystemCallFilter=@signal @timer

ReadWritePaths=/data/prometheus   <--------------- CHANGE DIRECTORY HERE

PrivateUsers=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectSystem=strict


SyslogIdentifier=prometheus
Restart=always
TimeoutStopSec=600s

[Install]
WantedBy=multi-user.target

  1. Verify permissions and owner
1
2
3
4
5
6
ls -al /data/
ls -al /data/prometheus/
root@dc2-monitoring-server-1:~# ls -al /data/prometheus/
total 120
drwxr-xr-x 25 prometheus prometheus  4096  4 oct.  09:54 .
drwxr-xr-x  4 prometheus prometheus  4096  4 oct.  09:53 ..
  1. Move the TSDB to new location mv /var/lib/prometheus/* /data/prometheus/
  2. Reload service file and start prometheus, verify if all is ok with journalctl and df
    1
    2
    3
    4
    
    systemctl daemon-reload
    systemctl start prometheus
    journalctl -xe
    df -h
    
This post is licensed under CC BY 4.0 by the author.