Created
December 7, 2018 02:35
-
-
Save graphaelli/fedc888028ebd91ad7e531dde38fd56d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import requests | |
def main(): | |
rsp = requests.get("http://localhost:9200/.monitoring-beats*/_search?sort=timestamp:desc", headers={"Accept": "application/json"}) | |
rsp.raise_for_status() | |
hits = rsp.json()['hits']['hits'] | |
print(" "*32 + f'{"-- valid --":12s} {"-- error --":6s}') | |
print(f"{'time':24s} {'req':3s} {'all':3s} {'cnt':3s} {'ok':3s} {'acc':3s} {'cnt':3s} {'sum':3s}") | |
for hit in hits: | |
src = hit['_source'] | |
ts = src['timestamp'] | |
try: | |
server = src['beats_stats']['metrics']['apm-server']['server'] | |
except KeyError: | |
continue | |
response = server['response'] | |
error_cnt = response['errors'].pop("count") | |
errors = sum(response['errors'].values()) | |
print(f"{ts:24s} {server['request']['count']:3d} {response['count']:3d} {response['valid']['count']:3d} {response['valid']['ok']:3d} {response['valid']['accepted']:3d} {error_cnt:3d} {errors:3d}") | |
# print(response['errors']['internal']) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment