README.md 8.6 KB
Newer Older
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
Monitor
=======

This stack has for purpose to know if all promises went/are ok.

It provides a web interface, to see which promises failed. It also provide a rss
feed to easily know the actual state of your instance, and to know when it
started to went bad.

THIS STACK IS A KIND OF FORK OF THE `stack/monitor`. THIS ONE WAS CREATED AS A
REDESIGNED ONE TO REMOVE UNWANTED FEATURES AND TO GO FURTHER TO THE GOOD DESIGN
DIRECTION. PLEASE, DO NOT USE THE OLD MONITORING INTERFACE OR ONLY FOR BACKWARD
COMPATIBILITY REASON.

Summary:

- Activate monitoring for you software
- Add a monitor promise
- Information about URL access
- Monitor promise configuration example
- Promise requirements
- monitor.haljson example
- monitor.conf example


Activate monitoring for your software
-------------------------------------

You just have to extend the monitor stack from your software.cfg.

You can also create a new buildout which extends your software, and the
monitoring stack:

    [buildout]
    extends =
      monitor_url
      my_software_url

In your instance.cfg, your publish section should be named `[publish]` in order
to extends the one of the monitoring stack.

Then, in the same file you can configure the monitor by adding this section:

    [monitor-instance-parameter]
    monitor-httpd-ipv6 = ...
    monitor-httpd-port = ...
    monitor-title = ...


Add a monitor promise
---------------------

For instance, we want to create a promise for KVM log parsing. Add these
sections in its instance.cfg:

    [directory]
    monitor-promise = ${:etc}/monitor-promise

    [kvm-log-parser-promise]
    recipe = ....
    filename = kvm-log-parser
    rendered = ${directory:monitor-promise}/${:filename}
    mode = 0755

    [buildout]
    parts += kvm-log-parser-promise

We can optionaly add promise title:

    [kvm-log-parser-promise-parameter]
    # fill with -> see "Service config example" below
    title = Kvm log parse

    [kvm-log-parser-promise-cfg]
    recipe = slapos.recipe.template:jinja2
    rendered = ${directory:monitor-promise}/${kvm-log-parser-promise:filename}.cfg
    template = service.cfg
    context = section parameter_dict kvm-log-parser-promise-parameter

    [buildout]
    parts += kvm-log-parser-promise-cfg

... and optionaly a specific frequency:

    [kvm-log-parser-promise-parameter]
    frequency = */5 * * * *

Optionaly, we also want a custom interface:

    [directory]
    kvm-log-parser-promise-interface-dir = ....../interface

    [kvm-log-parser-promise-parameter]
    private-path-list += ${directory:kvm-log-parser-promise-interface-dir}

    [kvm-log-parser-promise-interface]
    recipe = ....
    rendered = ${directory:kvm-log-parser-interface-dir}/index.html

    [buildout]
    parts += kvm-log-parser-promise-interface

service.cfg:

    [service]
    {% for key, value in parameter_dict.items() -%}
Tristan Cavelier's avatar
Tristan Cavelier committed
107
    {{ key }} = {{ value.strip().replace("\n", "\n  ") }}
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    {% endfor -%}


Information about URL access
----------------------------

Open HTTP GET on static files, open HTTP POST on cgi

    GET  <root_monitor>/                              // classical monitoring interface
    GET  <root_monitor>/monitor.haljson               // monitor conf
    GET  <root_monitor>/public/<service>.status.json  // service status json

Example for KVM log parsing promise

    GET  <kvm_monitor>/monitor.haljson
    GET  <kvm_monitor>/public/kvm-log-parser.status.json
    GET  <kvm_monitor>/public/kvm-log-parser/index.html
    POST <kvm_monitor>/cgi-bin/monitor-run-promise.cgi?service=kvm-log-parse  // rerun the promise


Information about internal file tree
------------------------------------

Tree for monitor runtime:

    etc/monitor.conf                 // generated by slapos
    etc/cron.d/monitor               // generated by slapos
    bin/monitor.py                   // generated by slapos
    srv/monitor/web/index.html       // static
    srv/monitor/web/monitor.css      // static
    srv/monitor/web/monitor.js       // static
    srv/monitor/web/monitor.haljson  // generated by monitor.py
    srv/monitor/public/....          // generated by monitor.py
    srv/monitor/private/....         // generated by monitor.py
Tristan Cavelier's avatar
Tristan Cavelier committed
142
    srv/monitor/cgi-bin/....         // generated by monitor.py
143 144 145 146 147 148 149 150 151 152 153 154

Example for KVM log parsing promise

    etc/monitor-promise/kvm-log-parse.cfg                                                                    // generated by slapos (kvm-log-parser-promise)
    etc/monitor-promise/kvm-log-parse                                                                        // generated by slapos (kvm-log-parser-promise)
    var/kvm-log-parser-promise/interface/index.html                                                          // generated by slapos (kvm-log-parser-promise)
    var/log/kvm.log                                                                                          // generated by kvm
    var/log/kvm-log-parse-last-report.csv                                                                    // generated by kvm-log-parse
    srv/monitor/public/kvm-log-parse.status.json                                                             // generated by kvm-log-parse (indirectly by the monitor promise executor)
    srv/monitor/public/kvm-log-parse/kvm.log -> var/log/kvm.log                                              // generated by monitor.py
    srv/monitor/public/kvm-log-parse/kvm-log-parse-last-report.csv -> var/log/kvm-log-parse-last-report.csv  // genareted by monitor.py
    srv/monitor/private/kvm-log-parse/interface -> var/kvm-log-parser-promise/interface                      // generated by monitor.py
Tristan Cavelier's avatar
Tristan Cavelier committed
155
    srv/monitor/cgi-bin/kvm-log-parse/action.cgi -> var/kvm-log-parser-promise/action.cgi                    // generated by monitor.py
156 157 158 159 160 161 162 163 164 165 166


Monitor promise config example
------------------------------

Example for KVM log parsing promise

    # etc/monitor-promise/kvm-log-parse.cfg
    [service]
    title =             Kvm log parse
    frequency =         <Cron Syntax>
Tristan Cavelier's avatar
Tristan Cavelier committed
167 168 169 170 171 172 173
    cgi-path-list =                                   # automatically symlink to srv/monitor/cgi-bin/$service/
      $instance/var/kvm-log-parser-promise/action.cgi
    public-path-list =                                # automatically symlink to srv/monitor/public/$service/
      $instance/var/log/kvm.log
    private-path-list =                               # automatically symlink to srv/monitor/private/$service/
      $instance/var/log
      $instance/var/kvm-log-parser-promise/interface
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

On cron, the command will be something like:

    ${service:frequency} ${monitor:promise-executor-path} '${monitor:service-pid-folder}/${service:name}.pid' '${service:status-path}' '${promise_path}'

and "monitor:promise-executor-path" is a script that would run a promise if not
already on going (see `run-promise.py`).

TODO cron accepts 999 characters maximum for a command, so we should reduce the
size of the cron command

TODO put `run-promise.py` in the software


Promise requirements
--------------------

A promise should check something (like web page is well cached, there's not too
much slow queries, ...):

- MUST output the status.json in stdout
- SHOULD output on stdout
- MUST return 0 if status is good else != 0
- the status.json MUST contain "message" (string) which explains why the status is OK or bad


monitor.haljson example
-----------------------

    {
      "_links": {
        "related_monitor": [
          { "href": "<url>/static" },
          { "href": "http://my.other.monitor" }
        ]
      },
      "_embedded": {
        "service": [
          {
            "_links": {
              "status": { "href": "<url>/kvm-log-parse/status.json" },
              "interface": { "href": "<url>/kvm-log-parse/index.html" }
            },
            "title": "KVM log parse",
            "id": "kvm-log-parse"
          },
          {
            "_links": {
              "status": { "href": "<url>/<service>/status.json" },
              "interface": { "href": "<url>/<service>/index.html" }
            },
            "title": "Service name",
            "id": "<service>"
          }
        ]
      },
      "title": "KVM Monitoring interface"
    }


monitor.conf example
--------------------

    [monitor]
    title =              KVM Monitoring interface
    monitor-hal-json =   $instance/srv/monitor/web/monitor.haljson
    public-folder =      $instance/srv/monitor/public
    private-folder =     $instance/srv/monitor/private
    web-folder =         $instance/srv/monitor/web
    cgi-folder =         $instance/srv/monitor/cgi-bin
    service-pid-folder = $instance/var/monitor/service-pid
    public-path-list =
      $instance/var/log
    private-path-list =
      $instance/srv/backup/log_rotate
    monitor-url-list =
      https://[...]/
      https://[...]/