-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gazer): Integrated with prometheus (#4)
* Setup filters * feat(gazer): Intergrated with prometheus * Clean up
- Loading branch information
Showing
8 changed files
with
383 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
## Python | ||
**/__pycache__/** | ||
**/venv/** |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import threading | ||
import pyinotify | ||
import yaml | ||
import os | ||
|
||
NODE_NAME = os.getenv("NODE_NAME") | ||
|
||
|
||
class ConfigWatcher(pyinotify.ProcessEvent): | ||
config = None | ||
|
||
def __init__(self, **kargs): | ||
super().__init__(**kargs) | ||
self.read_config() | ||
|
||
def read_config(self): | ||
with open(r'config/config.yaml') as file: | ||
self.config = yaml.load(file, Loader=yaml.FullLoader) | ||
self.config = dict(filter(lambda elem: elem[1]['node'] == NODE_NAME, self.config.items())) | ||
|
||
def process_IN_CLOSE_WRITE(self, evt): | ||
self.read_config() | ||
|
||
|
||
config_watcher = ConfigWatcher() | ||
wm = pyinotify.WatchManager() | ||
notifier = pyinotify.Notifier(wm, config_watcher) | ||
wdd = wm.add_watch("config/config.yaml", pyinotify.IN_CLOSE_WRITE) | ||
config_watcher_thread = threading.Thread(target=notifier.loop, args=()) | ||
config_watcher_thread.daemon = True | ||
config_watcher_thread.start() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
10.244.1.9: | ||
name: service-1 | ||
namespace: default | ||
node: minikube-0 | ||
10.244.1.10: | ||
name: service-2 | ||
namespace: default | ||
node: minikube-0 | ||
10.244.11: | ||
name: service-1 | ||
namespace: default | ||
node: minikube-1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import curses | ||
import time | ||
from gazer import Gazer | ||
|
||
|
||
def draw_menu(stdscr: curses.window): | ||
k = 0 | ||
cursor_x = 0 | ||
cursor_y = 0 | ||
|
||
# Clear and refresh the screen for a blank canvas | ||
stdscr.clear() | ||
stdscr.refresh() | ||
stdscr.nodelay(True) | ||
# curses.delay_output(100) | ||
|
||
# Start colors in curses | ||
curses.start_color() | ||
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) | ||
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) | ||
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) | ||
|
||
# Loop where k is the last character pressed | ||
while k != ord('q'): | ||
try: | ||
# Initialization | ||
stdscr.clear() | ||
height, width = stdscr.getmaxyx() | ||
|
||
if k == curses.KEY_DOWN: | ||
cursor_y = cursor_y + 1 | ||
elif k == curses.KEY_UP: | ||
cursor_y = cursor_y - 1 | ||
elif k == curses.KEY_RIGHT: | ||
cursor_x = cursor_x + 1 | ||
elif k == curses.KEY_LEFT: | ||
cursor_x = cursor_x - 1 | ||
|
||
cursor_x = max(0, cursor_x) | ||
cursor_x = min(width - 1, cursor_x) | ||
|
||
cursor_y = max(0, cursor_y) | ||
cursor_y = min(height - 1, cursor_y) | ||
|
||
statusbarstr = "Press 'q' to exit | STATUS BAR | Pos: {}, {}".format(cursor_x, cursor_y) | ||
|
||
stdscr.addstr(0, 0, "Requests", curses.color_pair(1)) | ||
stdscr.addstr(2, 0, gazer.request_log_text(), curses.color_pair(1)) | ||
stdscr.addstr(15, 0, gazer.syn_backlog_text(), curses.color_pair(1)) | ||
|
||
# Render status bar | ||
stdscr.attron(curses.color_pair(3)) | ||
stdscr.addstr(height - 1, 0, statusbarstr) | ||
stdscr.addstr(height - 1, len(statusbarstr), " " * (width - len(statusbarstr) - 1)) | ||
stdscr.attroff(curses.color_pair(3)) | ||
|
||
stdscr.move(cursor_y, cursor_x) | ||
|
||
# Refresh the screen | ||
stdscr.refresh() | ||
|
||
# Wait for next input | ||
k = stdscr.getch() | ||
time.sleep(1 / 30) | ||
except: | ||
# Refresh the screen | ||
stdscr.refresh() | ||
|
||
# Wait for next input | ||
k = stdscr.getch() | ||
|
||
|
||
gazer = Gazer(console=True) | ||
gazer.poll_data_in_bg() | ||
|
||
curses.wrapper(draw_menu) |
This file contains 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
Oops, something went wrong.