Coder Social home page Coder Social logo

graphite-csv-generator's Introduction

graphite-csv-generator

Graphite is a database for numeric time-series data. It's HTTP API allows us to render certain metrics in different formats like JSON, PNG or CSV. See Graphite HTTP API.

Problem

When rendering metrics into the CSV format, all data will be written into a single column. Obviously, this is very unpractical. The API call would be

http://<GRAPHITE_IP>/render?target=<METRICS>&format=csv

Example call: http://192.168.8.42:81/render/?target=smartmeter.strom.*&from=-10s&format=csv
The above call renders three metrics: Current in all three Phases of my Smartmeter and outputs it in a CSV, which looks like this (without the header):

Metric Date Time Value
smartmeter.strom.L1 2022-03-05 10:07:30 24.54
smartmeter.strom.L1 2022-03-05 10:07:35 24.53
smartmeter.strom.L2 2022-03-05 10:07:30 1.84
smartmeter.strom.L2 2022-03-05 10:07:35 1.8
smartmeter.strom.L3 2022-03-05 10:07:30 0.93
smartmeter.strom.L3 2022-03-05 10:07:35 0.93

Solution

In this program i requesting the data in the format raw and output the formatted data in a usable CSV, which will look like this:

time_smartmeter.strom.L1 smartmeter.strom.L1 time_smartmeter.strom.L2 smartmeter.strom.L2 time_smartmeter.strom.L3 smartmeter.strom.L3
05.03.2022 11:17:00 18.3 05.03.2022 11:17:00 1.91 05.03.2022 11:17:00 1.03
05.03.2022 11:17:05 1 05.03.2022 11:17:05 2.06 05.03.2022 11:17:05 1.03

Notice that each metric has its own time column. This is because some metrics may have different retention times and thus would not match.

Build

  • cygwin x64
  • cygwin CURL and REGEX is required

Build with

gcc main.c -lcurl

Disclaimer

This program uses metrics/settings/ip addresses which will probably only fit for me. You have to modify the code for your own purposes.

graphite-csv-generator's People

Contributors

fkw9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.