Giter Club home page Giter Club logo

Comments (4)

msirovy avatar msirovy commented on May 15, 2024 3

My finally solution is "don't use black box exporter". This project has poor documentation and it's much easier, faster and finally better to create own check with report to file /var/metrics/url_responses.prom and export it by node_exporter.

For example:

Run node exporter like this:
node_exporter --collector.textfile.directory=/var/metrics/"

Than write script in your favorite language, that can generate under path /var/metrics/ file *.prom and content like this:
application_response_time{url="appurl.domain.ltd",region="brasil",server_name="my.server.com"} 0.17377614974975586
than I can correlate by server_name, by region etc...

The python primitive way how to generate check like this could be script below, but I removed a few parts so it is maybe broken :-)

#!/usr/bin/env python3
#
# silly multithreeding application check 0.2
#

from multiprocessing import Pool
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
from os import path
import re, sys, time, socket
# import settings
from conf import *
from string import Template
from pprint import pprint


response_time = Template('application_response_time{url="$url",region="$region",server_name="$server"}  $time')


def load_file2list(file_path):
    ''' Read whole file each line is item in array with removed \n char
        file_path = str()
    '''
    try:
        if path.isfile(file_path):
            with open(file_path, "r") as _F:
                return _F.read().splitlines()
        else:
            print("Required file {} does not exist, so use empty".format(file_path))
            return list()
    except IOError as err:
        print(err)
        sys.exit(1)


def check_site(domain):
    ''' Get https://{{domain}}/ site and try to find SITE: {{domain}} string
        in returned page source. Return True if OK, or False.
        In case that chack will fail, print simple Error message.
        domain = str()  # without https://, just domain
    '''
    # by default application is in error status
    _ret = dict(url=domain, region="japan", server=None, time=999999)
    try:
        # measure response time
        t1 = time.time()

        req = Request("http://{}/".format(domain))
        if len(re.findall('_.O.K._: {}' , str(urlopen(req).read()))) >= 1:
            #print('Ok: Domain {} is OK!!!'.format(domain), file=sys.stdout)
            _ret['status'] = True
            _ret['msg'] = "OK"
        else:
            #print('Err: Domain {} is BROKEN!!!'.format(domain), file=sys.stderr)
            _ret['msg'] = "Broken site"    # probably don't contain right domain in source

        _ret['time'] = time.time() - t1

        _ret['server'] = socket.gethostbyaddr(domain)[0]
    except URLError:
        _ret['msg'] = "Unrechable"
        #print("Err: Domain {} is UNREACHABLE!!!".format(domain), file=sys.stderr)

    finally:
        return _ret


if __name__ == '__main__':
    # load last data
    DOMAINS = list(set(load_file2list(PATH_DOMAINS)))

    # paralelne jedeme seznam domen
    pool = Pool(8)
    results = pool.map(check_site, DOMAINS)
    with open(PATH_METRICS, "w") as metrics_f:
        #metrics_f.seek(0)          # rewrite file from begining
        for dom in results:
            print(response_time.substitute(dom), file=metrics_f)

from blackbox_exporter.

brian-brazil avatar brian-brazil commented on May 15, 2024

You would create one module per site, each with a different fail_if_not_matches_regexp.

from blackbox_exporter.

msirovy avatar msirovy commented on May 15, 2024

Hi you mean that for each site I may create module http_2xx config in blackbox.yml? Please give me an example...

from blackbox_exporter.

suptimal avatar suptimal commented on May 15, 2024

iam looking for the same thing, cant we use relabeling.

use the label match_regex="if u read this i am broken" and match_not_regex="if u cant read this i am broken"

from blackbox_exporter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.