I have a graphite instance configured on one server, and I use it to monitor my environment, which, unfortunately, consists of linux and windows machines. I want to monitor the well-being of my servers, so I chose a collector on my Linux machines that does a great job with statistics statistics.
Sadly for windows, it seems there are not many solutions for getting system statistics and sending them to graphite, but I managed to deal with this situation using powershell. I am using a script that was suggested here http://josh.behrends.us/2012/07/windows-powershell-graphite-awesome/ for graphite connection as well as for getting metrics from a computer I am using get-counter comandlet which , surprisingly, can gather a lot of information.
My script looks like this:
while (1 -eq 1) { $carbonServer = "hostname" $carbonServerPort = 2003 $epochtime = [int][double]::Parse((Get-Date -UFormat %s)) $socket = New-Object System.Net.Sockets.TCPClient $socket.connect($carbonServer, $carbonServerPort) $stream = $socket.GetStream() $writer = new-object System.IO.StreamWriter($stream) #Write out metric to the stream. $DiskQue = [int]((get-counter -Counter "\PhysicalDisk(1 e: f:)\Current Disk Queue Length" ).countersamples | select -property cookedvalue).cookedvalue $BytesReceived = [int]((get-counter -Counter "\Server\Bytes Received/sec" ).countersamples | select -property cookedvalue).cookedvalue $BytesSent = [int]((get-counter -Counter "\Server\Bytes Transmitted/sec").countersamples | select -property cookedvalue).cookedvalue $MemAvail = ((get-counter -Counter "\Memory\Available Bytes").countersamples | select -property cookedvalue).cookedvalue $MemCommit = ((get-counter -Counter "\Memory\Committed Bytes").countersamples | select -property cookedvalue).cookedvalue $ReadOp = [int]((get-counter -Counter "\System\File Read Operations/sec").countersamples | select -property cookedvalue).cookedvalue $WriteOp = [int]((get-counter -Counter "\System\File Write Operations/sec").countersamples | select -property cookedvalue).cookedvalue $metric7 = ("hostname.metrics.WriteOp " + $WriteOp + " " + $epochTime+"`n") $metric7 $writer.WriteLine($metric7) $writer.Flush() #Flush and write our metrics. $writer.Close() $stream.Close() sleep 5 }
Now this script displays what it should at first glance. The output is in the format hostname.metrics.name $metric_value $epochTime , but there are no graphs. They appear on the graphite panel, but they are empty. I checked the output sent to the graphite server with wirehark. It’s seams that in windows a message is added with CRLF unlike Linux, where you have only LF. I added \n manually, and for a short period of time it did the trick, but now it has stopped working.
My question is that I am doing something wrong in the transfer because I analyzed trafic and the only difference between the stream forms of linux machines that receive graphed and those that do not receive graphed from the windows are line terminators. In linux its LF (0a) and in windows is CRLF (0d0a), but again I tried to send from linux LFCRLF (0a0d0a) hoping that the graphite server will only read until the first LF, not an interepret message, but still I do not receive schedules.
Also, when I submit from linux, I only have one message, and when I submit the powershell form, I have three messages. From what I saw using strace in the cache cache process, I have one system call with the message I want, and I have another that is empty, and a SIX script to write (when transferring from powershell), unlike yo, one message per message and one message (when transferring from netcat to linux),