mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
WIP for grafana
This commit is contained in:
parent
ce9f0b04aa
commit
63922d4fe1
5 changed files with 89 additions and 3 deletions
|
@ -14,4 +14,4 @@ from apps.monitor.views.newsblur_tasks_times import TasksTimes
|
|||
from apps.monitor.views.newsblur_updates import Updates
|
||||
from apps.monitor.views.newsblur_users import Users
|
||||
|
||||
from apps.monitor.views.monitor import MongoDBHeapUsage, MongoDBObjects, MongoDBOpsReplsetLag, MongoDBSize, MongoDBOps, MongoDBPageFaults, MongoDBPageQueues
|
||||
from apps.monitor.views.mongo_monitor import MongoDBHeapUsage, MongoDBObjects, MongoDBOpsReplsetLag, MongoDBSize, MongoDBOps, MongoDBPageFaults, MongoDBPageQueues
|
83
apps/monitor/views/prometheus_redis.py
Normal file
83
apps/monitor/views/prometheus_redis.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
import os
|
||||
import socket
|
||||
|
||||
from django.views import View
|
||||
from django.shortcuts import render
|
||||
|
||||
"""
|
||||
RedisActiveConnections
|
||||
RedisCommands
|
||||
RedisConnects
|
||||
RedisUsedMemory
|
||||
RedisSize
|
||||
"""
|
||||
|
||||
class RedisGrafanaMetric(View):
|
||||
category = "Redis"
|
||||
|
||||
def autoconf(self):
|
||||
try:
|
||||
self.get_info()
|
||||
except socket.error:
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_info(self):
|
||||
host = os.environ.get('REDIS_HOST') or '127.0.0.1'
|
||||
port = int(os.environ.get('REDIS_PORT') or '6379')
|
||||
if host.startswith('/'):
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.connect(host)
|
||||
else:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
s.send("*1\r\n$4\r\ninfo\r\n")
|
||||
buf = ""
|
||||
while '\r\n' not in buf:
|
||||
buf += s.recv(1024)
|
||||
l, buf = buf.split('\r\n', 1)
|
||||
if l[0] != "$":
|
||||
s.close()
|
||||
raise Exception("Protocol error")
|
||||
remaining = int(l[1:]) - len(buf)
|
||||
if remaining > 0:
|
||||
buf += s.recv(remaining)
|
||||
s.close()
|
||||
return dict(x.split(':', 1) for x in buf.split('\r\n') if ':' in x)
|
||||
|
||||
def execute(self):
|
||||
stats = self.get_info()
|
||||
values = {}
|
||||
for k, v in self.get_fields():
|
||||
try:
|
||||
value = stats[k]
|
||||
except KeyError:
|
||||
value = "U"
|
||||
values[k] = value
|
||||
return values
|
||||
|
||||
def get_fields(self):
|
||||
raise NotImplementedError('You must implement the get_fields function')
|
||||
|
||||
def get_context(self):
|
||||
raise NotImplementedError('You must implement the get_context function')
|
||||
|
||||
def get(self, request):
|
||||
context = self.get_context()
|
||||
return render(request, 'monitor/prometheus_data.html', context, content_type="text/plain")
|
||||
|
||||
class RedisActiveConnection(RedisGrafanaMetric):
|
||||
|
||||
def get_context(self):
|
||||
|
||||
def get_fields(self):
|
||||
return (
|
||||
('connected_clients', dict(
|
||||
label = "connections",
|
||||
info = "connections",
|
||||
type = "GAUGE",
|
||||
)),
|
||||
)
|
||||
|
||||
def get_context(self):
|
||||
raise NotImplementedError('You must implement the get_context function')
|
3
package-lock.json
generated
Normal file
3
package-lock.json
generated
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
|
@ -2,8 +2,8 @@ import os
|
|||
import sys
|
||||
import time
|
||||
import mimetypes
|
||||
from boto.s3.connection import S3Connection
|
||||
from boto.s3.key import Key
|
||||
#from boto.s3.connection import S3Connection
|
||||
#from boto.s3.key import Key
|
||||
from utils.image_functions import ImageOps
|
||||
|
||||
if '/srv/newsblur' not in ' '.join(sys.path):
|
||||
|
|
Loading…
Add table
Reference in a new issue