<commit_before>package server

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"os"
	"strings"
	"time"
)

func graphiteMetric(name string, value int) {
	strTpl := "%s.%s %d\n"
	apiKey := os.Getenv("HOSTEDGRAPHITE_APIKEY")
	datum := fmt.Sprintf(strTpl, apiKey, name, value)
	conn, _ := net.Dial("udp", "carbon.hostedgraphite.com:2003")
	defer conn.Close()
	conn.Write([]byte(datum))
}

func forwardMetric(name string, value int) {
	url := "http://sandbox.influxdb.com:8086/db/eagle/series?u=rmg&p=GpqW1DtL3Png"
	jsonTpl := "[{ \"name\": \"%s\", \"columns\": [\"value\"], \"points\": [[%d]] }]"
	jsonStr := fmt.Sprintf(jsonTpl, name, value)

	req, _ := http.NewRequest("POST", url, strings.NewReader(jsonStr))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, _ := client.Do(req)
	defer resp.Body.Close()

	// fmt.Println("request Body:", jsonStr)
	// fmt.Println("response Status:", resp.Status)
	// fmt.Println("response Headers:", resp.Header)
	// body, _ := ioutil.ReadAll(resp.Body)
	// fmt.Println("response Body:", string(body))
}<commit_msg>Replace hardcoded URL/KEY with env vars<commit_after>package server

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"os"
	"strings"
	"time"
)

func graphiteMetric(name string, value int) {
	apiKey := os.Getenv("HOSTEDGRAPHITE_APIKEY")
	if len(apiKey) < 1 {
		return
	}
	strTpl := "%s.%s %d\n"
	datum := fmt.Sprintf(strTpl, apiKey, name, value)
	conn, _ := net.Dial("udp", "carbon.hostedgraphite.com:2003")
	defer conn.Close()
	conn.Write([]byte(datum))
}

func forwardMetric(name string, value int) {
	url := os.Getenv("INFLUXDB_URL")
	if len(url) < 1 {
		return
	}
	jsonTpl := "[{ \"name\": \"%s\", \"columns\": [\"value\"], \"points\": [[%d]] }]"
	jsonStr := fmt.Sprintf(jsonTpl, name, value)

	req, _ := http.NewRequest("POST", url, strings.NewReader(jsonStr))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, _ := client.Do(req)
	defer resp.Body.Close()

	// fmt.Println("request Body:", jsonStr)
	// fmt.Println("response Status:", resp.Status)
	// fmt.Println("response Headers:", resp.Header)
	// body, _ := ioutil.ReadAll(resp.Body)
	// fmt.Println("response Body:", string(body))
}
{'fraction_non_alphanumeric': 0.21064108155255123, 'fraction_numerical': 0.006977758395115569, 'mean_word_length': 4.448931116389549, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7510406', 'n_tokens_mistral': 935, 'n_tokens_neox': 902, 'n_words': 169}