Skip to content

Fetch metrics from Elasticsearch and calculate statistics

Changyuan Lin edited this page Jan 29, 2019 · 1 revision

class metricbeat(ELSaddress,ELSport,worker_node_hostname)

GetStatistics(**kwargs)

Return statistics dict Parameters:

start_time: the start of the time range for which we want to query system status in ISO format, default "now-1m"

duration_in_seconds: (int) the duration of waiting time in seconds, default 0

wait: (boolean) True or false to use time.sleep() to wait for a certain duration or not, default False

For example,

from ELSbeat import metricbeat
metricbeatinstance=metricbeat("10.12.7.26","9200","hkg-worker1")
statisticsdata=metricbeatinstance.GetStatistics()

Sample output: Type: dict

{'cpu_idle': {'avg': 1993.1,
  'max': 1996,
  'min': 1980,
  'percentile5': 1985.85,
  'percentile95': 1996.0,
  'std': 4.4821869662029945},
 'cpu_io_wait': {'avg': 1.6,
  'max': 14,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 8.599999999999987,
  'std': 4.17612260356422},
 'cpu_krn': {'avg': 2.4,
  'max': 4,
  'min': 0,
  'percentile5': 0.9,
  'percentile95': 4.0,
  'std': 1.1135528725660044},
 'cpu_sint_time': {'avg': 4329.4,
  'max': 4331,
  'min': 4317,
  'percentile5': 4322.400000000001,
  'percentile95': 4331.0,
  'std': 4.17612260356422},
 'cpu_time': {'avg': 1999.8,
  'max': 2001,
  'min': 1998,
  'percentile5': 1998.0,
  'percentile95': 2001.0,
  'std': 1.1661903789690602},
 'cpu_usr': {'avg': 2.7,
  'max': 4,
  'min': 1,
  'percentile5': 1.0,
  'percentile95': 4.0,
  'std': 1.1874342087037917},
 'drm': {'avg': 0.0,
  'max': 0,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 0.0,
  'std': 0.0},
 'dsr': {'avg': 0.0,
  'max': 0.0,
  'min': 0.0,
  'percentile5': 0.0,
  'percentile95': 0.0,
  'std': 0.0},
 'dsreads': {'avg': 0.0,
  'max': 0,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 0.0,
  'std': 0.0},
 'dsw': {'avg': 8.8,
  'max': 56.0,
  'min': 0.0,
  'percentile5': 0.0,
  'percentile95': 41.599999999999966,
  'std': 17.325126262166172},
 'dswrites': {'avg': 0.9,
  'max': 6,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 4.199999999999996,
  'std': 1.8138357147217055},
 'dwm': {'avg': 0.03637273182045568,
  'max': 0.2001000500250125,
  'min': 0.0,
  'percentile5': 0.0,
  'percentile95': 0.20005002501250624,
  'std': 0.077158218910061},
 'loadavg': {'avg': 0.09090909090909091,
  'max': 1,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 0.5,
  'std': 0.28747978728803447},
 'mem_used_bytes': {'avg': 3335633082.181818,
  'max': 3336069120,
  'min': 3335180288,
  'percentile5': 3335180288.0,
  'percentile95': 3336052736.0,
  'std': 414965.4846557763},
 'mem_used_pct': {'avg': 0.39883636363636366,
  'max': 0.3989,
  'min': 0.3988,
  'percentile5': 0.3988,
  'percentile95': 0.3989,
  'std': 4.8104569292078165e-05},
 'nbr': {'avg': 3204.1,
  'max': 3247,
  'min': 3187,
  'percentile5': 3187.9,
  'percentile95': 3242.05,
  'std': 21.997499857938404},
 'nbs': {'avg': 512.3,
  'max': 514,
  'min': 510,
  'percentile5': 510.45000000000005,
  'percentile95': 514.0,
  'std': 1.268857754044952},
 'readtime': {'avg': 0.0,
  'max': 0,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 0.0,
  'std': 0.0},
 'writetime': {'avg': 16.0,
  'max': 140,
  'min': 0,
  'percentile5': 0.0,
  'percentile95': 85.99999999999989,
  'std': 41.7612260356422}}