Created
June 27, 2017 13:15
-
-
Save jerojasro/7e550b047e21bfd14b3d20e8c316a96b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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