Mackerelでサービスメトリックの送信

sudo mkdir /opt/mackerel
curl -s https://gist.githubusercontent.com/tomoyk/3918bd2859e53b60787f7057c9d67103/raw/e9ed5da413a2f9542ca1c3210a7def49a3e4be9d/mackerel-service-metric-sender-with-http-get.py | sudo tee /opt/mackerel/monit.py
sudo chmod a+x /opt/mackerel/monit.py

fix code

def main():
    # check http-server
    sample = send_http_get_req('http://example.com/')
    print("samp:", sample)

    # send to mackerel
    current_date = int(time.time()
    req_payloads = [
        {
            "name": "YOUR_HOSTNAME.resStatus",  ### set status
            "time": current_date,
            "value": sample[0]
        },
        {
            "name": "YOUR_HOSTNAME.resTime",  ### set time
            "time": current_date,
            "value": sample[1]
        }
    ]
    ### set service_name and api_key
    send_metric(service_name='hoge', api_key='fuga', payloads=req_payloads)

add crontab: crontab -e

  * *  *   *   *     /usr/bin/python3 /opt/mackerel/monit.py