zoukankan      html  css  js  c++  java
  • 【工作笔记】python+influxdb+grafana监控云行情

    最近供应商提供的上海阿里云行情站点比较卡,为此用python+influxdb+grafana监控服务器在开市期间与休市期间请求应答耗时,代码如下:

    #!/usr/bin/env python3
    # -*-coding:utf-8-*-
    # author by Michael Ho
    # contact:rui.he@geekthings.com.cn
    # description:moniter Shanghai AliCloud
    
    import requests, time
    from influxdb import InfluxDBClient
    
    # connect to influxdb
    client = InfluxDBClient('localhost', 8086, 'root', 'xxxxxx', 'hq_moniter')
    
    while True:
        url = "http://172.50.1.151:3006/reqxml?"
        params = {
            "action": "60",
            "mobilecode": "13988888888",
            "StartPos": "1",
            "StockIndex": "1",
            "maxcount": "3",
            "AccountIndex": "6",
            "Grid": "00600|4353,000001|4609,600000|4353"
        }
        r = requests.get(url=url, params=params)
        request_time = r.elapsed.total_seconds()
    
        json_body = [
            {
                "measurement": "hq_server",
                "tags": {
                    "host": "Shanghai_AliCloud",
                },
                "fields": {
                    "request_time": request_time
                }
            }
        ]
        client.write_points(json_body)
        time.sleep(10)

    守护进程脚本,代码如下:

    #!/bin/bash
    # description : moniter Shanghai AliCloud Service
    # author by : Michael Ho
    # contact : rui.he@geekthings.com.cn
    
    service="/usr/bin/env python3 /opt/scripts/moniter_zzCloudHq/moniter_shAliCloud.py"
    pid_file=shAliCloud.pid
    
    start() {
      ${service} &
      # shellcheck disable=SC2181
      if [[ $? -eq 0 ]]; then
        echo $! > ${pid_file}
      else
        exit 1
      fi
    }
    
    stop() {
        # shellcheck disable=SC2046
        kill -9 $(cat ${pid_file})
        # shellcheck disable=SC2181
        if [[ $? -eq 0 ]]; then
            rm -f ${pid_file}
        else
          exit 1
        fi
    }
    
    case $1 in
      start )
        echo "moniter Shanghai AliCloud Service is start ..."
        start
        ;;
    
      stop )
        echo "moniter Shanghai AliCloud Service is stop ..."
        stop
        ;;
    
      * )
        echo "Please input start | stop ..."
        ;;
    esac
  • 相关阅读:
    JBoss 性能优化(解决Jboss内存紧张的问题)
    JBOSS最大连接数配置和jvm内存配置
    DWR与AJAX
    使AJAX调用尽可能利用缓存特性
    Java Map各遍历方式的性能比较
    java cache过期策略两种实现,一个基于list轮询一个基于timer定时
    自己动手实现java中cache
    Java实现cache的基本机制
    jvm垃圾回收的时间问题
    nginx的健康检查功能将挂掉的Tomcat舍弃
  • 原文地址:https://www.cnblogs.com/herui1991/p/12508081.html
Copyright © 2011-2022 走看看