Author Archives: Dima

Oracle query: table size in bytes

SELECT TRUNC(sum(bytes)) table_size, table_name 
FROM (SELECT segment_name table_name, bytes
    FROM user_segments
    WHERE segment_type = 'TABLE'
    UNION ALL
    SELECT i.table_name, s.bytes
    FROM user_indexes i, user_segments s
    WHERE s.segment_name = i.index_name 
    AND   s.segment_type = 'INDEX'
    UNION ALL
    SELECT l.table_name, s.bytes
    FROM user_lobs l, user_segments s
    WHERE s.segment_name = l.segment_name 
    AND   s.segment_type = 'LOBSEGMENT'
    UNION ALL
    SELECT l.table_name, s.bytes
    FROM user_lobs l, user_segments s
    WHERE s.segment_name = l.index_name 
    AND   s.segment_type = 'LOBINDEX')
GROUP BY table_name
HAVING SUM(bytes)/1024/1024 > 100

DataDog Oracle custom_query: Only float values can be submitted as metrics

Errors in log

2021-12-30 13:07:02 UTC | CORE | WARN | (pkg/collector/python/datadog_agent.go:124 in LogMessage) | oracle:9eb61efa95cfcc8c | (base.py:580) | Metric: 'test.table_rows.rowcount' has non float value: 'ITEMS'. Only float values can be submitted as metrics.

Configuration with issue

instances:
  - custom_queries:
    - metric_prefix: test.table_rows        
      query: select table_name, regexp_replace(to_char(nvl(num_rows,-1), '99999999999.9'),'
            ', '') rowcount from all_tables where owner='TEST'
      columns:
        - name: rowcount
          nype: gauge
        - name: table_name
          type: tag

Solution:

Set first field as field with value:

select (...) rowcount, table_name from ...

docker-compose notes

version: '3.8'

services:

  filebeat-app:
  image: docker.elastic.co/beats/filebeat:${ELK_VERSION}
  hostname: "{{.Service.Name}}-{{.Task.Slot}}"
    deploy:
      mode: global
      placement:
        max_replicas_per_node: 1
        constraints:
          - "node.labels.zoom-connector==true"

rabbitmq: cluster on docker swarm can not be assembled

RabbitMQ cluster on docker swarm can not be assembled

Symptoms

oqpqhlailzzn   myproject_rabbitmq-2.1  rabbitmq:3.7-management-alpine   ip-10-103-32-185.us-east-1.compute.internal   Shutdown            Failed 22 seconds ago        "task: non-zero exit (69)"   
ngo5qnu2n4lk   myproject_rabbitmq-3.1  rabbitmq:3.7-management-alpine   ip-10-103-47-234.us-east-1.compute.internal   Shutdown            Failed 22 seconds ago        "task: non-zero exit (69)"

Continue reading

docker helpful commands

Get subnet’s CIDR

docker network ls -q | xargs docker network inspect -f '[{{ .Name }}]: {{ .IPAM.Config }}'

Get labels from nodes in swarm cluster

# execute on manager
docker node ls -q | xargs docker node inspect -f '[{{ .ID }} {{ .Description.Hostname }}]: {{ .Spec.Labels }}'
# 
docker node ls -q | xargs docker node inspect \
  -f '{{ .ID }} [{{ .Description.Hostname }}]: {{ range $k, $v := .Spec.Labels }}{{ $k }}={{ $v }} {{end}}'

Continue reading

transmission notes

Issue: Transmission Remote GUI 403 Forbidden

Package: transmission-daemon
Version: 2.94-2+deb10u1
find / -mount -type f -name settings.json -exec ls -l {} \;

-rw------- 1 root root 2186 Sep 20 22:29 /root/.config/transmission-daemon/settings.json
-rw-rw---- 1 debian-transmission debian-transmission 2398 Oct 30 16:37 /etc/transmission-daemon/settings.json
-rw------- 1 debian-transmission debian-transmission 2226 Oct 30 16:45 /home/debian-transmission/.config/transmission-daemon/settings.json

Continue reading

certbot notes

Issue: Unable to recover files from /var/lib/letsencrypt/temp_checkpoint

# certbot 1.7.0, CentOS 7
certbot --nginx -d site.domain.com
# echo
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Unable to recover files from /var/lib/letsencrypt/temp_checkpoint
Incomplete or failed recovery for /var/lib/letsencrypt/temp_checkpoint
Unable to revert temporary config

I did. Solved:

yum update
mv /var/lib/letsencrypt /var/lib/letsencrypt.original

Nextcloud notes

 

Move server to other host

  1. Install Nextcloud on the new server
  2. Set the old and new server to maintenance mode
  3. Dump the database on the old
  4. Copy the complete data directory to the new server
  5. Restore the database on the new server
  6. Edit the config.php on the new server. I think you have to copy passwordsalt a d secret from the old to the new server.
  7. Change the DNS record to point at your new server.
  8. Turn off maintenance mode on the new server.

Asterisk stop log to syslog

Issue

Asterisk put logs to /var/log/syslog
Affected OS: Ubuntu, Debian 9

Solution:

# Step1: create file for rsyslog
cat << EOF > /etc/rsyslog.d/10-asterisk.conf
if \$programname == "asterisk" then { stop }
EOF
# Step2:
systemctl restart rsyslog.service

jinja create file from template without empty lines

Issue

Creation of file from pillar simple list with Jinja template will be create empty line, in top or bottom of file, dependence for template syntax.
You can not create file without empty lines.

#!/usr/bin/python
from jinja2 import Template

d = {'testlist':['item1','item2','item3']}

tmpl = '''{%- for item in testlist %}
   {{ item }}
{%- endfor %}'''

t = Template(tmpl)
print( t.render( d ) )

Continue reading