Où sommes nous ?

Retour

Custom probe creation

This page describes how to create a custom probe.

Probe description

Here, we will build a probe that will track memory usage of Domestik's monitor.

  1. In our case, it's not difficult to find out the process number : this probe will run within dmkcheckd process.
  2. we are looking only for memory leakage due to dmkcheckd own usage, so we have to look for data and stack used

On Linux, those information can be found in /proc file-system, especially in /proc/.../status. (Notez-bien : they are more easily available in /proc/.../statm but the corresponding field is marked as broken).

Note

In this example, we are tracking only Domestik's monitor, but it's using resources of a more general probe named "process_tracking" at server side.

You can use or process_tracking or dmkc_tracking but not both at the same time.

Probe script (.../Client/Probes/dmkc_tracking.lua)

Tasks to be done are the following :

  1. find out our process number

It can be done by using LuaPosix getpid().

  1. read /proc/<pid>/status
  2. extract VmData & VmStk fields
  3. build a response for dmkcheck process.

resulting to the following code :


dmkc_tracking.lua

and generating these data :

{
    'dmkcheckd' = {
        'data' = "476"
        'stack' = "136"
    }
}

Notes : in order to be compatible with process_probe

return res, "process_tracking"

Database

storing data

As we want to get some trends, data have to be stored inside a database.

CREATE TABLE Domestik.probe_process_tracking (
    host TEXT NOT NULL,
    process TEXT NOT NULL,
    data INTEGER,
    stack INTEGER,
    sample_time TIMESTAMP WITH TIME ZONE
);

In addition to already known process, data and stack fields, we need

We need also to provide access to Apache's user

GRANT ALL PRIVILEGES ON TABLE Domestik.probe_process_tracking TO www;

and add some indexes to speedup access

CREATE INDEX dmkppth ON Domestik.probe_process_tracking (host);
CREATE INDEX dmkppthm ON Domestik.probe_process_tracking (host, process);

archiving data

We want also a long term storage thru archiving

CREATE TABLE Domestik.probe_process_tracking_archive (
    host TEXT NOT NULL,
    process TEXT NOT NULL,
    sample_time TIMESTAMP WITH TIME ZONE NOT NULL,
    data_min REAL,
    data_max REAL,
    stack_min REAL,
    stack_max REAL,
    used_min REAL,
    used_max REAL
);

We will store both minimum and maximum value for a period of time for each value, plus a new one, used, which is the sum of data and stack (as obviously, maximum used data is not max(stack) + max(data)).

As for live data, we need also to provide access to Apache's user and to do some indexing

GRANT ALL PRIVILEGES ON TABLE Domestik.probe_process_tracking_archive TO www;
CREATE INDEX dmkpptah ON Domestik.probe_process_tracking_archive (host);
CREATE INDEX dmkpptahm ON Domestik.probe_process_tracking_archive (host, process);

server side probe (.../Server/Include/Domestik/Probes/probe_process_tracking.inc)

This file defines a class which implements the way Domestik handles data.

It's inheriting from Probe class, an abstract class which defines the interface of each probes vs Domestik engine. Our probe class skeleton is

require_once('Domestik/Probe.inc');

class probe_process_tracking extends Probe {
}

and this class has to contains following methods

NewSample

Arguments are :

Return a boolean : true for success, false if something went wrong.

function NewSample($machine, $data, $sample_time){
        $res = true;

        foreach($data as $process => $dt){    // walk against $data
            $res = $res and $this->getContext()->dbInsert('probe_process_tracking',
                array( 'host'=>$machine->getName(), 'process'=>$process,
                    'data'=>$dt['data'], 'stack'=>$dt['stack'],
                    'sample_time'=>$time
                )
            );
        }

        return $res;
    }

archive

Note regarding purging & archiving

For the moment, $host is only used to segregate action by host (as explained in Data Life Cycle page, it helps to ensure last data are kept in case of crashes). But, it way be used in the future to have different archiving and purging policy per monitored host.

Argument :

Compute archived data older than the day before.

purge

Argument :

Remove archived data older than 1 month.

StoredData

Argument :

This method returns the list of monitored process for a specific host.

function StoredData( $machine ){
if( !( $res = $this->getContext()->dbSelect('probe_process_tracking', array('process'), array('host'=>$machine->getName()), array('process'=>true), true))) // 0 entry or error
return false;

foreach( $res as $d )
$r[] = $d['process'];

return $r;
}

getStoredData

Arguments :

Please have a look .../Server/Include/Domestik/Probes/probe_process_tracking.inc for the implementation which is quite complex as we are handling several processes and not only dmkcheckd.

And the result is :

ArchivedData

Argument :

This method returns the list of archived process for a specific host. It's basically the same code as StoredData() but dealing archive table.

function StoredData( $machine ){
if( !( $res = $this->getContext()->dbSelect('probe_process_tracking_archive', array('process'), array('host'=>$machine->getName()), array('process'=>true), true))) // 0 entry or error
return false;

foreach( $res as $d )
$r[] = $d['process'];

return $r;
}

getArchivedData

It's more or less the same code as getStoredData() but dealing with archived data and generate ranges.


Visitez :
La liste de nos voyages
Nos sorties Ski et rando
Copyright Laurent Faillie 2001-2018
N'oubliez pas d'entrer le mot de passe pour voir aussi les photos perso.
Contactez moi si vous souhaitez réutiliser ces photos et pour les obtenir avec une plus grande résolution.
Visites durant les 7 derniers jours Nombre de visites au total.

Vous pouvez laissez un commentaire sur cette page.