Skip to content

Commit

Permalink
fix readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzv committed Nov 3, 2023
1 parent 7b26d37 commit 510ed99
Showing 1 changed file with 91 additions and 42 deletions.
133 changes: 91 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,141 @@
# Prometheus to CSV Exporter

# Prometheus 2 CSV Exporter



This is a Go application that exports data from Prometheus as a CSV file and optionally uploads it to an AWS S3 bucket. This README will guide you through setting up and running the application.



## Table of Contents


- [Table of Contents](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Demo](#demo)
- [Installation](#installation)
- [Usage](#usage)
- [Options](#options)
- [Build](#build)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)

## Demo
[![asciicast](https://asciinema.org/a/dnnGv3ZYarAeXER37uYTKYdZt.png)](https://asciinema.org/a/dnnGv3ZYarAeXER37uYTKYdZt)
Tested on Ubuntu 22.04 and Golang 1.18, 1.21



## Prerequisites



Before using this exporter, you should have the following prerequisites installed and configured:
- Go (Golang): Make sure you have Go installed on your system. You can download and install Go from the [official Go website](https://golang.org/doc/install).
- AWS CLI: If you plan to upload the CSV file to an AWS S3 bucket, make sure you have the AWS CLI installed and configured with the appropriate credentials. You can install the AWS CLI and configure it using the `aws configure` command.
- Prometheus: You should have access to a Prometheus server with a valid address to query data.

- Go (tested with Golang 1.21.1): Make sure you have Go installed on your system, you can download and install Go from the [official Go website](https://golang.org/doc/install).

- AWS S3 bucket (Optional): If you plan to upload the CSV file to an AWS S3 bucket, make sure you have the AWS credentials configured, the Go script will automatically load the default AWS credentials or take them from enviroment variables `AWS_SECRET_ACCESS_KEY` and `AWS_ACCESS_KEY_ID`

- Prometheus: You must have access to a Prometheus server with a valid address to query data.


## Demo

Tested on Ubuntu 22.04 and Golang 1.18, 1.21

[![asciicast](https://asciinema.org/a/dnnGv3ZYarAeXER37uYTKYdZt.png)](https://asciinema.org/a/dnnGv3ZYarAeXER37uYTKYdZt)



## Installation



1. Clone this repository to your local machine:

```shell
git clone https://github.com/yourusername/prometheus-to-csv-exporter.git
`git clone https://github.com/fnzv/p2c.git`

Change your working directory to the project folder:


shell
Change your working directory to the project folder:

cd prometheus-to-csv-exporter

Build the Go application:
`cd p2c/`

shell
## Build

go build exporter.go

`go build p2c.go`


The exporter binary will be created in the project folder.
Usage

`./p2c`


You can run the Prometheus to CSV exporter using the following command:

shell

./exporter --query <Prometheus query> --time-range <time range> --address <Prometheus address> [--upload-s3 <S3 destination>] [--region <AWS region>] [--filename <Destination file name>]

```
./p2c --query <Prometheus query> --time-range <time range> --address <Prometheus address> [--upload-s3 <S3 destination>] [--region <AWS region>] [--filename <Destination file name>]
```


Options

--query: (Required) The Prometheus query to fetch data.
--time-range: (Required) The time range for the query (e.g., "29d" for 29 days).
--address: (Required) The address of the Prometheus server.
--upload-s3: (Optional) The S3 destination in the format "s3://bucket-name/path/to/folder/". If provided, the CSV file will be uploaded to this S3 location.
--region: (Optional) The AWS region for S3. Required if --upload-s3 is specified.
--filename: (Optional) The name of the destination CSV file. If not provided, a default file name will be used.

```
--query: (Required) The Prometheus query to fetch data.
Examples
--time-range: (Required) The time range for the query (e.g., "29d" for 29 days).
Export data from Prometheus to a local CSV file:
--address: (Required) The address of the Prometheus server.
shell
--upload-s3: (Optional) The S3 destination in the format "s3://bucket-name/path/to/folder/". If provided, the CSV file will be uploaded to this S3 location.
./exporter --query "up" --time-range "7d" --address "http://prometheus.example.com:9090"
--region: (Optional) The AWS region for S3. Required if --upload-s3 is specified.
Export data from Prometheus and upload it to an AWS S3 bucket:
--filename: (Optional) The name of the destination CSV file. If not provided, a default file name will be used.
shell
--debug: (Optional) Enable debug output
./exporter --query "up" --time-range "7d" --address "http://prometheus.example.com:9090" --upload-s3 "s3://my-s3-bucket/folder/" --region "us-west-1"
```
All the following options can be used also via enviroment variables as you can see in the k8s/cronjob.tf example, the variables have the prefix `P2C_NAME` , here are some examples using environment variables:

```
P2C_QUERY='up' P2C_TIMERANGE='29d' P2C_ADDRESS='http://prometheus.ingress' P2C_UPLOAD_S3='s3://your-s3-buckets/metrics/' P2C_REGION='eu-west-1' ./p2c
```

Specify a custom destination file name:
## Examples

shell

./exporter --query "up" --time-range "7d" --address "http://prometheus.example.com:9090" --filename "custom_data.csv"
Export data from Prometheus to a local CSV file:

Contributing

Contributions to this project are welcome! If you have any ideas, improvements, or bug fixes, feel free to create an issue or submit a pull request.
License
`./p2c --query "up" --time-range "7d" --address "http://prometheus.example.com:9090"`

This project is licensed under the MIT License - see the LICENSE file for details.

rust
Export data from Prometheus and upload it to an AWS S3 bucket:

`./p2c --query "up" --time-range "7d" --address "http://prometheus.example.com:9090" --upload-s3 "s3://my-s3-bucket/folder/" --region "us-west-1"`



Specify a custom destination file name:

`./p2c --query "up" --time-range "7d" --address "http://prometheus.example.com:9090" --filename "custom_data.csv"`



## Contributing


Contributions to this project are welcome! If you have any ideas, improvements, or bug fixes, feel free to create an issue or submit a pull request.

## License


This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to customize the information as needed for your specific project.

0 comments on commit 510ed99

Please sign in to comment.