Statistics
| Branch: | Tag: | Revision:

root / doc / design-monitoring-agent.rst @ daff2f81

History | View | Annotate | Download (23.4 kB)

1
=======================
2
Ganeti monitoring agent
3
=======================
4

    
5
.. contents:: :depth: 4
6

    
7
This is a design document detailing the implementation of a Ganeti
8
monitoring agent report system, that can be queried by a monitoring
9
system to calculate health information for a Ganeti cluster.
10

    
11
Current state and shortcomings
12
==============================
13

    
14
There is currently no monitoring support in Ganeti. While we don't want
15
to build something like Nagios or Pacemaker as part of Ganeti, it would
16
be useful if such tools could easily extract information from a Ganeti
17
machine in order to take actions (example actions include logging an
18
outage for future reporting or alerting a person or system about it).
19

    
20
Proposed changes
21
================
22

    
23
Each Ganeti node should export a status page that can be queried by a
24
monitoring system. Such status page will be exported on a network port
25
and will be encoded in JSON (simple text) over HTTP.
26

    
27
The choice of JSON is obvious as we already depend on it in Ganeti and
28
thus we don't need to add extra libraries to use it, as opposed to what
29
would happen for XML or some other markup format.
30

    
31
Location of agent report
32
------------------------
33

    
34
The report will be available from all nodes, and be concerned for all
35
node-local resources. This allows more real-time information to be
36
available, at the cost of querying all nodes.
37

    
38
Information reported
39
--------------------
40

    
41
The monitoring agent system will report on the following basic information:
42

    
43
- Instance status
44
- Instance disk status
45
- Status of storage for instances
46
- Ganeti daemons status, CPU usage, memory footprint
47
- Hypervisor resources report (memory, CPU, network interfaces)
48
- Node OS resources report (memory, CPU, network interfaces)
49
- Information from a plugin system
50

    
51
Format of the query
52
-------------------
53

    
54
The query will be an HTTP GET request on a particular port. At the
55
beginning it will only be possible to query the full status report.
56

    
57
Format of the report
58
--------------------
59

    
60
The report of the will be in JSON format, and it will present an array
61
of report objects.
62
Each report object will be produced by a specific data collector.
63
Each report object includes some mandatory fields, to be provided by all
64
the data collectors:
65

    
66
``name``
67
  The name of the data collector that produced this part of the report.
68
  It is supposed to be unique inside a report.
69

    
70
``version``
71
  The version of the data collector that produces this part of the
72
  report. Built-in data collectors (as opposed to those implemented as
73
  plugins) should have "B" as the version number.
74

    
75
``formatVersion``
76
  The format of what is represented in the "data" field for each data
77
  collector might change over time. Every time this happens, the
78
  format_version should be changed, so that who reads the report knows
79
  what format to expect, and how to correctly interpret it.
80

    
81
``timestamp``
82
  The time when the reported data were gathered. Is has to be expressed
83
  in nanoseconds since the unix epoch (0:00:00 January 01, 1970). If not
84
  enough precision is available (or needed) it can be padded with
85
  zeroes. If a report object needs multiple timestamps, it can add more
86
  and/or override this one inside its own "data" section.
87

    
88
``category``
89
  A collector can belong to a given category of collectors (e.g.: storage
90
  collectors, daemon collector). This means that it will have to provide a
91
  minumum set of prescribed fields, as documented for each category.
92
  This field will contain the name of the category the collector belongs to,
93
  if any, or just the ``null`` value.
94

    
95
``kind``
96
  Two kinds of collectors are possible:
97
  `Performance reporting collectors`_ and `Status reporting collectors`_.
98
  The respective paragraphs will describe them and the value of this field.
99

    
100
``data``
101
  This field contains all the data generated by the specific data collector,
102
  in its own independently defined format. The monitoring agent could check
103
  this syntactically (according to the JSON specifications) but not
104
  semantically.
105

    
106
Here follows a minimal example of a report::
107

    
108
  [
109
  {
110
      "name" : "TheCollectorIdentifier",
111
      "version" : "1.2",
112
      "formatVersion" : 1,
113
      "timestamp" : 1351607182000000000,
114
      "category" : null,
115
      "kind" : 0,
116
      "data" : { "plugin_specific_data" : "go_here" }
117
  },
118
  {
119
      "name" : "AnotherDataCollector",
120
      "version" : "B",
121
      "formatVersion" : 7,
122
      "timestamp" : 1351609526123854000,
123
      "category" : "storage",
124
      "kind" : 1,
125
      "data" : { "status" : { "code" : 1,
126
                              "message" : "Error on disk 2"
127
                            },
128
                 "plugin_specific" : "data",
129
                 "some_late_data" : { "timestamp" : 1351609526123942720,
130
                                      ...
131
                                    }
132
               }
133
  }
134
  ]
135

    
136
Performance reporting collectors
137
++++++++++++++++++++++++++++++++
138

    
139
These collectors only provide data about some component of the system, without
140
giving any interpretation over their meaning.
141

    
142
The value of the ``kind`` field of the report will be ``0``.
143

    
144
Status reporting collectors
145
+++++++++++++++++++++++++++
146

    
147
These collectors will provide information about the status of some
148
component of ganeti, or managed by ganeti.
149

    
150
The value of their ``kind`` field will be ``1``.
151

    
152
The rationale behind this kind of collectors is that there are some situations
153
where exporting data about the underlying subsystems would expose potential
154
issues. But if Ganeti itself is able (and going) to fix the problem, conflicts
155
might arise between Ganeti and something/somebody else trying to fix the same
156
problem.
157
Also, some external monitoring systems might not be aware of the internals of a
158
particular subsystem (e.g.: DRBD) and might only exploit the high level
159
response of its data collector, alerting an administrator if anything is wrong.
160
Still, completely hiding the underlying data is not a good idea, as they might
161
still be of use in some cases. So status reporting plugins will provide two
162
output modes: one just exporting a high level information about the status,
163
and one also exporting all the data they gathered.
164
The default output mode will be the status-only one. Through a command line
165
parameter (for stand-alone data collectors) or through the HTTP request to the
166
monitoring agent
167
(when collectors are executed as part of it) the verbose output mode providing
168
all the data can be selected.
169

    
170
When exporting just the status each status reporting collector will provide,
171
in its ``data`` section, at least the following field:
172

    
173
``status``
174
  summarizes the status of the component being monitored and consists of two
175
  subfields:
176

    
177
  ``code``
178
    It assumes a numeric value, encoded in such a way to allow using a bitset
179
    to easily distinguish which states are currently present in the whole cluster.
180
    If the bitwise OR of all the ``status`` fields is 0, the cluster is
181
    completely healty.
182
    The status codes are as follows:
183

    
184
    ``0``
185
      The collector can determine that everything is working as
186
      intended.
187

    
188
    ``1``
189
      Something is temporarily wrong but it is being automatically fixed by
190
      Ganeti.
191
      There is no need of external intervention.
192

    
193
    ``2``
194
      The collector can determine that something is wrong and Ganeti has no
195
      way to fix it autonomously. External intervention is required.
196

    
197
    ``4``
198
      The collector has failed to understand whether the status is good or
199
      bad. Further analysis is required. Interpret this status as a
200
      potentially dangerous situation.
201

    
202
  ``message``
203
    A message to better explain the reason of the status.
204
    The exact format of the message string is data collector dependent.
205

    
206
    The field is mandatory, but the content can be ``null`` if the code is
207
    ``0`` (working as intended) or ``1`` (being fixed automatically).
208

    
209
    If the status code is ``2``, the message should specify what has gone
210
    wrong.
211
    If the status code is ``4``, the message shoud explain why it was not
212
    possible to determine a proper status.
213

    
214
The ``data`` section will also contain all the fields describing the gathered
215
data, according to a collector-specific format.
216

    
217
Instance status
218
+++++++++++++++
219

    
220
At the moment each node knows which instances are running on it, which
221
instances it is primary for, but not the cause why an instance might not
222
be running. On the other hand we don't want to distribute full instance
223
"admin" status information to all nodes, because of the performance
224
impact this would have.
225

    
226
As such we propose that:
227

    
228
- Any operation that can affect instance status will have an optional
229
  "reason" attached to it (at opcode level). This can be used for
230
  example to distinguish an admin request, from a scheduled maintenance
231
  or an automated tool's work. If this reason is not passed, Ganeti will
232
  just use the information it has about the source of the request: for
233
  example a cli shutdown operation will have "cli:shutdown" as a reason,
234
  a cli failover operation will have "cli:failover". Operations coming
235
  from the remote API will use "rapi" instead of "cli". Of course
236
  setting a real site-specific reason is still preferred.
237
- RPCs that affect the instance status will be changed so that the
238
  "reason" and the version of the config object they ran on is passed to
239
  them. They will then export the new expected instance status, together
240
  with the associated reason and object version to the status report
241
  system, which then will export those themselves.
242

    
243
Monitoring and auditing systems can then use the reason to understand
244
the cause of an instance status, and they can use the timestamp to
245
understand the freshness of their data even in the absence of an atomic
246
cross-node reporting: for example if they see an instance "up" on a node
247
after seeing it running on a previous one, they can compare these values
248
to understand which data is freshest, and repoll the "older" node. Of
249
course if they keep seeing this status this represents an error (either
250
an instance continuously "flapping" between nodes, or an instance is
251
constantly up on more than one), which should be reported and acted
252
upon.
253

    
254
The instance status will be on each node, for the instances it is
255
primary for, and its ``data`` section of the report will contain a list
256
of instances, with at least the following fields for each instance:
257

    
258
``name``
259
  The name of the instance.
260

    
261
``uuid``
262
  The UUID of the instance (stable on name change).
263

    
264
``admin_state``
265
  The status of the instance (up/down/offline) as requested by the admin.
266

    
267
``actual_state``
268
  The actual status of the instance. It can be ``up``, ``down``, or
269
  ``hung`` if the instance is up but it appears to be completely stuck.
270

    
271
``uptime``
272
  The uptime of the instance (if it is up, "null" otherwise).
273

    
274
``mtime``
275
  The timestamp of the last known change to the instance state.
276

    
277
``state_reason``
278
  The last known reason for state change, described according to the
279
  following subfields:
280

    
281
  ``text``
282
    Either a user-provided reason (if any), or the name of the command that
283
    triggered the state change, as a fallback.
284

    
285
  ``jobID``
286
    The ID of the job that caused the state change.
287

    
288
  ``source``
289
    Where the state change was triggered (RAPI, CLI).
290

    
291
``status``
292
  It represents the status of the instance, and its format is the same as that
293
  of the ``status`` field of `Status reporting collectors`_.
294

    
295
Each hypervisor should provide its own instance status data collector, possibly
296
with the addition of more, specific, fields.
297
The ``category`` field of all of them will be ``instance``.
298
The ``kind`` field will be ``1``.
299

    
300
Note that as soon as a node knows it's not the primary anymore for an
301
instance it will stop reporting status for it: this means the instance
302
will either disappear, if it has been deleted, or appear on another
303
node, if it's been moved.
304

    
305
The ``code`` of the ``status`` field of the report of the Instance status data
306
collector will be:
307

    
308
``0``
309
  if ``status`` is ``0`` for all the instances it is reporting about.
310

    
311
``1``
312
  otherwise.
313

    
314
Storage status
315
++++++++++++++
316

    
317
The storage status collectors will be a series of data collectors
318
(drbd, rbd, plain, file) that will gather data about all the storage types
319
for the current node (this is right now hardcoded to the enabled storage
320
types, and in the future tied to the enabled storage pools for the nodegroup).
321

    
322
The ``name`` of each of these collector will reflect what storage type each of
323
them refers to.
324

    
325
The ``category`` field of these collector will be ``storage``.
326

    
327
The ``kind`` field will be ``1`` (`Status reporting collectors`_).
328

    
329
The ``data`` section of the report will provide at least the following fields:
330

    
331
``free``
332
  The amount of free space (in KBytes).
333

    
334
``used``
335
  The amount of used space (in KBytes).
336

    
337
``total``
338
  The total visible space (in KBytes).
339

    
340
Each specific storage type might provide more type-specific fields.
341

    
342
In case of error, the ``message`` subfield of the ``status`` field of the
343
report of the instance status collector will disclose the nature of the error
344
as a type specific information. Examples of these are "backend pv unavailable"
345
for lvm storage, "unreachable" for network based storage or "filesystem error"
346
for filesystem based implementations.
347

    
348
DRBD status
349
***********
350

    
351
This data collector will run only on nodes where DRBD is actually
352
present and it will gather information about DRBD devices.
353

    
354
Its ``kind`` in the report will be ``1`` (`Status reporting collectors`_).
355

    
356
Its ``category`` field in the report will contain the value ``storage``.
357

    
358
When executed in verbose mode, the ``data`` section of the report of this
359
collector will provide the following fields:
360

    
361
``versionInfo``
362
  Information about the DRBD version number, given by a combination of
363
  any (but at least one) of the following fields:
364

    
365
  ``version``
366
    The DRBD driver version.
367

    
368
  ``api``
369
    The API version number.
370

    
371
  ``proto``
372
    The protocol version.
373

    
374
  ``srcversion``
375
    The version of the source files.
376

    
377
  ``gitHash``
378
    Git hash of the source files.
379

    
380
  ``buildBy``
381
    Who built the binary, and, optionally, when.
382

    
383
``device``
384
  A list of structures, each describing a DRBD device (a minor) and containing
385
  the following fields:
386

    
387
  ``minor``
388
    The device minor number.
389

    
390
  ``connectionState``
391
    The state of the connection. If it is "Unconfigured", all the following
392
    fields are not present.
393

    
394
  ``localRole``
395
    The role of the local resource.
396

    
397
  ``remoteRole``
398
    The role of the remote resource.
399

    
400
  ``localState``
401
    The status of the local disk.
402

    
403
  ``remoteState``
404
    The status of the remote disk.
405

    
406
  ``replicationProtocol``
407
    The replication protocol being used.
408

    
409
  ``ioFlags``
410
    The input/output flags.
411

    
412
  ``perfIndicators``
413
    The performance indicators. This field will contain the following
414
    sub-fields:
415

    
416
    ``networkSend``
417
      KiB of data sent on the network.
418

    
419
    ``networkReceive``
420
      KiB of data received from the network.
421

    
422
    ``diskWrite``
423
      KiB of data written on local disk.
424

    
425
    ``diskRead``
426
      KiB of date read from the local disk.
427

    
428
    ``activityLog``
429
      Number of updates of the activity log.
430

    
431
    ``bitMap``
432
      Number of updates to the bitmap area of the metadata.
433

    
434
    ``localCount``
435
      Number of open requests to the local I/O subsystem.
436

    
437
    ``pending``
438
      Number of requests sent to the partner but not yet answered.
439

    
440
    ``unacknowledged``
441
      Number of requests received by the partner but still to be answered.
442

    
443
    ``applicationPending``
444
      Num of block input/output requests forwarded to DRBD but that have not yet
445
      been answered.
446

    
447
    ``epochs``
448
      (Optional) Number of epoch objects. Not provided by all DRBD versions.
449

    
450
    ``writeOrder``
451
      (Optional) Currently used write ordering method. Not provided by all DRBD
452
      versions.
453

    
454
    ``outOfSync``
455
      (Optional) KiB of storage currently out of sync. Not provided by all DRBD
456
      versions.
457

    
458
  ``syncStatus``
459
    (Optional) The status of the synchronization of the disk. This is present
460
    only if the disk is being synchronized, and includes the following fields:
461

    
462
    ``percentage``
463
      The percentage of synchronized data.
464

    
465
    ``progress``
466
      How far the synchronization is. Written as "x/y", where x and y are
467
      integer numbers expressed in the measurement unit stated in
468
      ``progressUnit``
469

    
470
    ``progressUnit``
471
      The measurement unit for the progress indicator.
472

    
473
    ``timeToFinish``
474
      The expected time before finishing the synchronization.
475

    
476
    ``speed``
477
      The speed of the synchronization.
478

    
479
    ``want``
480
      The desiderd speed of the synchronization.
481

    
482
    ``speedUnit``
483
      The measurement unit of the ``speed`` and ``want`` values. Expressed
484
      as "size/time".
485

    
486
  ``instance``
487
    The name of the Ganeti instance this disk is associated to.
488

    
489

    
490
Ganeti daemons status
491
+++++++++++++++++++++
492

    
493
Ganeti will report what information it has about its own daemons.
494
This should allow identifying possible problems with the Ganeti system itself:
495
for example memory leaks, crashes and high resource utilization should be
496
evident by analyzing this information.
497

    
498
The ``kind`` field will be ``1`` (`Status reporting collectors`_).
499

    
500
Each daemon will have its own data collector, and each of them will have
501
a ``category`` field valued ``daemon``.
502

    
503
When executed in verbose mode, their data section will include at least:
504

    
505
``memory``
506
  The amount of used memory.
507

    
508
``size_unit``
509
  The measurement unit used for the memory.
510

    
511
``uptime``
512
  The uptime of the daemon.
513

    
514
``CPU usage``
515
  How much cpu the daemon is using (percentage).
516

    
517
Any other daemon-specific information can be included as well in the ``data``
518
section.
519

    
520
Hypervisor resources report
521
+++++++++++++++++++++++++++
522

    
523
Each hypervisor has a view of system resources that sometimes is
524
different than the one the OS sees (for example in Xen the Node OS,
525
running as Dom0, has access to only part of those resources). In this
526
section we'll report all information we can in a "non hypervisor
527
specific" way. Each hypervisor can then add extra specific information
528
that is not generic enough be abstracted.
529

    
530
The ``kind`` field will be ``0`` (`Performance reporting collectors`_).
531

    
532
Each of the hypervisor data collectory will be of ``category``: ``hypervisor``.
533

    
534
Node OS resources report
535
++++++++++++++++++++++++
536

    
537
Since Ganeti assumes it's running on Linux, it's useful to export some
538
basic information as seen by the host system.
539

    
540
The ``category`` field of the report will be ``null``.
541

    
542
The ``kind`` field will be ``0`` (`Performance reporting collectors`_).
543

    
544
The ``data`` section will include:
545

    
546
``cpu_number``
547
  The number of available cpus.
548

    
549
``cpus``
550
  A list with one element per cpu, showing its average load.
551

    
552
``memory``
553
  The current view of memory (free, used, cached, etc.)
554

    
555
``filesystem``
556
  A list with one element per filesystem, showing a summary of the
557
  total/available space.
558

    
559
``NICs``
560
  A list with one element per network interface, showing the amount of
561
  sent/received data, error rate, IP address of the interface, etc.
562

    
563
``versions``
564
  A map using the name of a component Ganeti interacts (Linux, drbd,
565
  hypervisor, etc) as the key and its version number as the value.
566

    
567
Note that we won't go into any hardware specific details (e.g. querying a
568
node RAID is outside the scope of this, and can be implemented as a
569
plugin) but we can easily just report the information above, since it's
570
standard enough across all systems.
571

    
572
Instance disk status propagation
573
--------------------------------
574

    
575
As for the instance status Ganeti has now only partial information about
576
its instance disks: in particular each node is unaware of the disk to
577
instance mapping, that exists only on the master.
578

    
579
For this design doc we plan to fix this by changing all RPCs that create
580
a backend storage or that put an already existing one in use and passing
581
the relevant instance to the node. The node can then export these to the
582
status reporting tool.
583

    
584
While we haven't implemented these RPC changes yet, we'll use Confd to
585
fetch this information in the data collectors.
586

    
587
Plugin system
588
-------------
589

    
590
The monitoring system will be equipped with a plugin system that can
591
export specific local information through it.
592

    
593
The plugin system is expected to be used by local installations to
594
export any installation specific information that they want to be
595
monitored, about either hardware or software on their systems.
596

    
597
The plugin system will be in the form of either scripts or binaries whose output
598
will be inserted in the report.
599

    
600
Eventually support for other kinds of plugins might be added as well, such as
601
plain text files which will be inserted into the report, or local unix or
602
network sockets from which the information has to be read.  This should allow
603
most flexibility for implementing an efficient system, while being able to keep
604
it as simple as possible.
605

    
606
Data collectors
607
---------------
608

    
609
In order to ease testing as well as to make it simple to reuse this
610
subsystem it will be possible to run just the "data collectors" on each
611
node without passing through the agent daemon.
612

    
613
If a data collector is run independently, it should print on stdout its
614
report, according to the format corresponding to a single data collector
615
report object, as described in the previous paragraphs.
616

    
617
Mode of operation
618
-----------------
619

    
620
In order to be able to report information fast the monitoring agent
621
daemon will keep an in-memory or on-disk cache of the status, which will
622
be returned when queries are made. The status system will then
623
periodically check resources to make sure the status is up to date.
624

    
625
Different parts of the report will be queried at different speeds. These
626
will depend on:
627
- how often they vary (or we expect them to vary)
628
- how fast they are to query
629
- how important their freshness is
630

    
631
Of course the last parameter is installation specific, and while we'll
632
try to have defaults, it will be configurable. The first two instead we
633
can use adaptively to query a certain resource faster or slower
634
depending on those two parameters.
635

    
636
When run as stand-alone binaries, the data collector will not using any
637
caching system, and just fetch and return the data immediately.
638

    
639
Implementation place
640
--------------------
641

    
642
The status daemon will be implemented as a standalone Haskell daemon. In
643
the future it should be easy to merge multiple daemons into one with
644
multiple entry points, should we find out it saves resources and doesn't
645
impact functionality.
646

    
647
The libekg library should be looked at for easily providing metrics in
648
json format.
649

    
650

    
651
Implementation order
652
--------------------
653

    
654
We will implement the agent system in this order:
655

    
656
- initial example data collectors (eg. for drbd and instance status).
657
- initial daemon for exporting data, integrating the existing collectors
658
- plugin system
659
- RPC updates for instance status reasons and disk to instance mapping
660
- cache layer for the daemon
661
- more data collectors
662

    
663

    
664
Future work
665
===========
666

    
667
As a future step it can be useful to "centralize" all this reporting
668
data on a single place. This for example can be just the master node, or
669
all the master candidates. We will evaluate doing this after the first
670
node-local version has been developed and tested.
671

    
672
Another possible change is replacing the "read-only" RPCs with queries
673
to the agent system, thus having only one way of collecting information
674
from the nodes from a monitoring system and for Ganeti itself.
675

    
676
One extra feature we may need is a way to query for only sub-parts of
677
the report (eg. instances status only). This can be done by passing
678
arguments to the HTTP GET, which will be defined when we get to this
679
funtionality.
680

    
681
Finally the :doc:`autorepair system design <design-autorepair>`. system
682
(see its design) can be expanded to use the monitoring agent system as a
683
source of information to decide which repairs it can perform.
684

    
685
.. vim: set textwidth=72 :
686
.. Local Variables:
687
.. mode: rst
688
.. fill-column: 72
689
.. End: