Skip to content

Instantly share code, notes, and snippets.

@jerojasro
Created June 27, 2017 13:15
Show Gist options
  • Save jerojasro/7e550b047e21bfd14b3d20e8c316a96b to your computer and use it in GitHub Desktop.
Save jerojasro/7e550b047e21bfd14b3d20e8c316a96b to your computer and use it in GitHub Desktop.
from random import randint
from random import choice
from time import sleep
import graphitesend
def get_metrics():
metrics = []
for meter in ["{0:02d}".format(i) for i in range(1, 11)]:
for (metric, base) in [("tension", 110), ("corriente", 2), ("temperatura", 35)]:
tenth = base / 10.0
delta = randint(0, 3)
sgn = choice([1, -1])
metrics.append((
"meter{}.{}".format(meter, metric),
base + (sgn * tenth * delta),
))
return metrics
def main():
graphite = graphitesend.GraphiteClient(
prefix='',
graphite_server='localhost',
debug=True,
system_name='',
)
while True:
sleep(1)
print('sending ...')
metrics = get_metrics()
print(metrics)
graphite.send_list(metrics)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment