Giter Site home page Giter Site logo

tcp_port_exporter's Introduction

tcp_port_exporter

A TCP Ports Monitor Exporter for Prometheus.

tcp_port_exporter/
├── grafana
│   └── TCP\ Ports\ Monitor-1524464207634.json # Grafana Dashboard Json
├── README.md  # 使用说明
├── requirements.txt # 依赖包
├── rules
│   └── check_tcp_port.rules  # 告警规则
├── systemd
│   └── tcp_port_exporter.service  # 以systemd方式运行exporter
├── src
     ├── check_tcp_port.list  # 监控目标文件
     └── tcp_port_exporter.py # 主程序

Usage

  • cd tcp_port_exporter/v1
  • Create a check_tcp_port.list file if not exists; add the targets like this format hostname--192.168.111.111:9100 what u want to monitor;
  • Run nohup python ./tcp_port_exporter.py >> ./tcp_port_exporter.log 2>&1 &
  • Go to http://your_ip:1990/metrics to see metrics

Alternatively, if you don't wish to install the package, run using $ vmware_exporter/vmware_exporter.py

Configuration

add the following config parameters to prometheus.yml:

   - job_name: 'tcp_port_exporter'
    metrics_path: /metrics
    scrape_interval: 60s
    file_sd_configs:
      - files: ['/path/to/file/check_tcp_port.json']

the check_tcp_port.json is like that:

[
    {
        "targets": [
            "your_ip:1990"
        ],
        "labels": {}
    }
]

Metrics

# HELP check_tcp_port # 端口存活监测
# TYPE check_tcp_port gauge
check_tcp_port{host="192.168.111.111",port="9100"} 1.0

References

The exporter uses theses libraries:

tcp_port_exporter's People

Contributors

plynte avatar

Stargazers

 avatar

Forkers

zhuziyuan

tcp_port_exporter's Issues

Django Practice - Use Python's builtin Logging

Django Practice - Use Python's builtin Logging

settings.py

LOG_LEVEL = 'DEBUG' if DEBUG else 'WARNING'
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'main': {
            'datefmt': '%Y-%m-%d %H:%M:%S',
            'format': '%(asctime)s [%(module)s %(levelname)s] %(message)s',
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {

    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'mail_admins': {
            'level': 'DEBUG',
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': True,
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'main'
        },
        'default': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'formatter': 'main',
            'filename': os.path.join(BASE_DIR, 'logs', 'output.log')
        },
        'myhandler': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'formatter': 'main',
            'filename': os.path.join(BASE_DIR, 'logs', 'azurecloudapi.log')
        },
    },
    'loggers': {
        # loggers 类型 为"django" 这将处理所有类型的日志
        'django': {
            'handlers': ['null'],
            'propagate': False,
            'level': LOG_LEVEL,
        },
        'django.request': {
            'handlers': ['console', 'default'],
            'level': LOG_LEVEL,
            'propagate': False,
        },
        'django.server': {
            'handlers': ['console', 'default'],
            'level': LOG_LEVEL,
            'propagate': False,
        },
        'mylogger': {
            'handlers': ['console', 'myhandler'],
            'level': LOG_LEVEL,
        },
    }
}
  • formatters
    定义日志输出的具体格式
  • handlers
    定义如何处理日志,比如发送到文件,console等
  • filters
    定义一个日志记录是否发送到handler
  • loggers
    记录日志接口,供代码使用

How to use logging

import logging

# logger = logging.getLogger(str('mylogger'))
logger = logging.getLogger(__name__)  # 用__name__通用,自动检测

def test():
	logger.debug()
	logger.info()
	logger.warning()
	logger.error()
	logger.critical()
	#...

NO start tcp_port_exporter.service

tcp_port_exporter.py[16478]: Traceback (most recent call last):
tcp_port_exporter.py[16478]: File "/opt/prometheus/tcp_port_exporter.py", line 7, in
tcp_port_exporter.py[16478]: from prometheus_client.core import GaugeMetricFamily, _floatToGoString
tcp_port_exporter.py[16478]: ImportError: cannot import name _floatToGoString
systemd[1]: tcp_port_exporter.service: control process exited, code=exited status=1
systemd[1]: Failed to start TCP_Port_Exporter.

Install requirements.txt packages.
NO start tcp_port_exporter.service. Help me.

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.