mihai.leontescu / metrics (public) (License: GPLv3) (since 2018-07-12) (hash sha1)
Metrics for Linux to feed to Graphite in python
Disclaimer: I am not a programmer, I know some things can be done better. I choose to do them so, so I am able to understand them 80 years later :)

/metrics-nosend.py (0033fae7b80040519f94dee23c3a4d93d95f6aa9) (1187 bytes) (mode 100755) (type blob)

#!/usr/bin/python3


import time
import os
import socket
import json
import importlib
import sys

Path=sys.path[0]
ConfigFileLocation=Path+"/conf/metrics.conf"
MetricsLocation=Path+"/metrics.d"

sys.path.append(MetricsLocation)

## Read from Configfile
with open(ConfigFileLocation,'r') as ConfigFile:
   Configuration = json.load(ConfigFile)

GraphHost=Configuration["GraphHost"]
GraphPort=Configuration["GraphPort"]
LogFile=Configuration["LogFile"]

### / End Read Configfile

def WriteLog(message):
   Log = open(LogFile,'a')
   message=str(time.asctime())+' '+message
   Log.write(message)
   Log.close()

def graphSend(content):
    s = socket.socket()
    s.connect((GraphHost, GraphPort))
    s.sendall(content.encode())
    s.close()

try:
   import LinuxNetwork
   import LinuxDisk
   import LinuxCPU
except:
   print ("SNAFU")
   sys.exit(2)



while True: 
   toSend=""
   toSend+=LinuxNetwork.network()
   toSend+=LinuxDisk.disk()
   toSend+=LinuxCPU.cpu()
   WriteLog ("START: Sending metrics --> ")
   try:
      #graphSend(toSend)
      print(toSend)
      WriteLog (" OK\n")
   except Exception as err:
      WriteLog (" ERROR: %s\n" % (err))
      pass
   time.sleep(9)


Mode Type Size Ref File
040000 tree - bdfaa25bd7c44e6091d31189c9d10c7019ebef91 conf
040000 tree - 211ff1b3b194e0ed0810abcf99eaf6d7f2535fc9 graphana_examples
100755 blob 1187 0033fae7b80040519f94dee23c3a4d93d95f6aa9 metrics-nosend.py
040000 tree - 620b68dd84166f2b7d8045753feeacbd8ef282d3 metrics.d
100755 blob 1439 735b3280bf3c1f9913316c9dca0e5fef2c48aa13 metrics.py
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/mihai.leontescu/metrics

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/mihai.leontescu/metrics

Clone this repository using git:
git clone git://git.rocketgit.com/user/mihai.leontescu/metrics

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main