summaryrefslogtreecommitdiff
path: root/devstack/lib/osprofiler
blob: d5b75e3319e364447f1ba279d7aa2b7418226949 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash

# lib/osprofiler
# Functions to control the configuration and operation of the **OSProfiler**

# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace


# Defaults
# --------

CONF_FILES=(
    $CINDER_CONF
    $HEAT_CONF
    $KEYSTONE_CONF
    $NOVA_CONF
    $NEUTRON_CONF
    $GLANCE_API_CONF
    $GLANCE_REGISTRY_CONF
    $TROVE_CONF
    $TROVE_CONDUCTOR_CONF
    $TROVE_GUESTAGENT_CONF
    $TROVE_TASKMANAGER_CONF
    $SENLIN_CONF
    $MAGNUM_CONF
    $ZUN_CONF
)

# Add config files of Nova Cells
NOVA_NUM_CELLS=${NOVA_NUM_CELLS:-1}
for i in $(seq 1 ${NOVA_NUM_CELLS}); do
    # call function `conductor_conf` defined in lib/nova to get file name
    conf=$(conductor_conf $i)
    CONF_FILES+=(${conf})
done


# Functions
# ---------

function install_redis() {
    if is_fedora; then
        install_package redis
    elif is_ubuntu; then
        install_package redis-server
    elif is_suse; then
        install_package redis
    else
        exit_distro_not_supported "redis installation"
    fi

    start_service redis

    pip_install_gr redis
}

function install_jaeger() {
    if is_ubuntu; then
        install_package docker.io
        start_service docker
        add_user_to_group stack docker
        sg docker -c "docker run -d --name jaeger -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:1.7"
    else
        exit_distro_not_supported "docker.io installation"
    fi

    pip_install jaeger-client
}

function install_elasticsearch() {
    if is_ubuntu; then
        install_package docker.io
        start_service docker
        add_user_to_group $STACK_USER docker
        # https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docker.html#docker-cli-run-dev-mode
        sg docker -c 'docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:5.6.14'
    else
        exit_distro_not_supported "docker.io installation"
    fi

    pip_install elasticsearch
}

function install_osprofiler_collector() {
    if [ -z "$OSPROFILER_COLLECTOR" ]; then
        OSPROFILER_CONNECTION_STRING=${OSPROFILER_CONNECTION_STRING:-"messaging://"}
    elif [ "$OSPROFILER_COLLECTOR" == "redis" ]; then
        install_redis
        OSPROFILER_CONNECTION_STRING=${OSPROFILER_CONNECTION_STRING:-"redis://localhost:6379"}
    elif [ "$OSPROFILER_COLLECTOR" == "jaeger" ]; then
        install_jaeger
        OSPROFILER_CONNECTION_STRING=${OSPROFILER_CONNECTION_STRING:-"jaeger://localhost:6831"}
    elif [ "$OSPROFILER_COLLECTOR" == "elasticsearch" ]; then
        install_elasticsearch
        OSPROFILER_CONNECTION_STRING=${OSPROFILER_CONNECTION_STRING:-"elasticsearch://elastic:changeme@localhost:9200"}
    else
        die $LINENO "OSProfiler collector $OSPROFILER_COLLECTOR is not supported"
    fi
}

function configure_osprofiler() {

    for conf in ${CONF_FILES[@]}; do
        if [ -f $conf ]
        then
            iniset $conf profiler enabled True
            iniset $conf profiler trace_sqlalchemy $OSPROFILER_TRACE_SQLALCHEMY
            iniset $conf profiler hmac_keys $OSPROFILER_HMAC_KEYS
            iniset $conf profiler connection_string $OSPROFILER_CONNECTION_STRING
        fi
    done

    # Insert osprofiler filter into Neutron paste configuration
    if [ -f $Q_API_PASTE_FILE ]; then
        VAL=$(iniget $Q_API_PASTE_FILE composite:neutronapi_v2_0 keystone)
        VAL=${VAL/catch_errors/catch_errors osprofiler}
        iniset $Q_API_PASTE_FILE composite:neutronapi_v2_0 keystone "$VAL"
    fi
}


# Restore xtrace
$XTRACE