| Newsgroups |
gmane.comp.sysutils.pcp |
| Message-ID |
<[email protected]> |
--yabbadabbadoo
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
[speed:master] New Comment on Issue #35 Explain metric registration in docu=
mentation ( https://github.com/performancecopilot/speed/issues/35 )
By suyash ( https://github.com/suyash ) :
Hi
PCP detects metrics through memory mapped files. The default behavior is t=
o persist these files. If you want to make sure that the memory mapped file=
s are deleted (i.e. metrics are lost on stopping the client), please set Er=
aseFileOnStop to true (godoc https://godoc.org/github.com/performancecopilo=
t/speed#pkg-variables ( https://godoc.org/github.com/performancecopilot/spe=
ed#pkg-variables ) )
>=20
>=20
>=20
> I tried to register metrics dynamically stopping the client first but it
> did not work well (I was running into issues trying to stop already
> stopped client - maybe just a race condition)
>=20
>=20
You cannot stop an already stopped client, however it is possible to stop =
a client, register a new metric and restart it. I was trying the following =
snippet, and everything seems to be working fine, please reply if it satisf=
ies your use case, or any ways to modify the library that will satisfy your=
use cases. Notice that it sets EraseFileOnStop to true right at the end, s=
o all previous metrics are still there on restart, and only at the end the =
file is also deleted.
package main import ( "log" "math/rand" "strconv" "time" "github.com/perfo=
rmancecopilot/speed" ) var c speed . Client func main ( ) { speed . EnableL=
ogging ( true ) var err error c , err =3D speed . NewPCPClient ( "test" ) i=
f err ! =3D nil { log . Fatal ( "Sorry, No Client" ) } c . MustStart ( ) de=
fer c . MustStop ( ) go runner ( "a.b.c" ) go runner ( "d.e.f" ) go runner =
( "g.h.i" ) time . Sleep ( 10 * time . Second ) speed . EraseFileOnStop =3D=
true } func runner ( metricPrefix string ) { var x =3D 0 for { var sleepTi=
me =3D time . Duration ( rand . Intn ( 2000 ) ) * time . Millisecond time .=
Sleep ( sleepTime ) c . MustStop ( ) var metricName =3D metricPrefix + "."=
+ strconv . Itoa ( x ) c . MustRegisterString ( metricName , 0 , speed . I=
nt64Type , speed . CounterSemantics , speed . OneUnit ) c . MustStart ( ) x=
+ + } }
>=20
>=20
>=20
>=20
> Will this approach work with archiving and long-term monitoring?
>=20
>=20
The client must be stopped to re-register a metric because its an issue of=
read location. Adding a metric will modify locations of different blocks i=
nside the MMV file, which will require reinitialization of the client. Henc=
e a metric can only be registered if a client is stopped. Another idea is t=
o have multiple clients, each with a different name and writing their own m=
etrics. In fact, that is the idea of the client type and not having a singl=
e global registry of metrics.
--yabbadabbadoo
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
[speed:master] New Comment on Issue <a href=3D"https://github.com/performa=
ncecopilot/speed/issues/35">#35 Explain metric registration in documentatio=
n</a><br>
By <a href=3D"https://github.com/suyash">suyash</a>:<p>
<p>Hi</p>
<p>PCP detects metrics through memory mapped files. The default behavior i=
s to persist these files. If you want to make sure that the memory mapped f=
iles are deleted (i.e. metrics are lost on stopping the client), please set=
<code>EraseFileOnStop</code> to <code>true</code> (godoc <a href=3D"https:=
//godoc.org/github.com/performancecopilot/speed#pkg-variables" target=3D"_b=
lank">https://godoc.org/github.com/performancecopilot/speed#pkg-variables</=
a>)</p>
<blockquote>
<p>I tried to register metrics dynamically stopping the client first but i=
t did not work well (I was running into issues trying to stop already stopp=
ed client - maybe just a race condition)</p>
</blockquote>
<p>You cannot stop an already stopped client, however it is possible to st=
op a client, register a new metric and restart it. I was trying the followi=
ng snippet, and everything seems to be working fine, please reply if it sat=
isfies your use case, or any ways to modify the library that will satisfy y=
our use cases. Notice that it sets <code>EraseFileOnStop</code> to true rig=
ht at the end, so all previous metrics are still there on restart, and only=
at the end the file is also deleted.</p>
<pre><code><span class=3D"kwd">package</span> <span class=3D"pln">main</sp=
an>
<span class=3D"kwd">import</span> <span class=3D"pun">(</span>
<span class=3D"str">"log"</span>
<span class=3D"str">"math/rand"</span>
<span class=3D"str">"strconv"</span>
<span class=3D"str">"time"</span>
<span class=3D"str">"github.com/performancecopilot/speed"</spa=
n>
<span class=3D"pun">)</span>
<span class=3D"kwd">var</span> <span class=3D"pln">c</span> <span class=3D=
"pln">speed</span><span class=3D"pun">.</span><span class=3D"typ">Client</s=
pan>
<span class=3D"kwd">func</span> <span class=3D"pln">main</span><span class=
=
=3D"pun">(</span><span class=3D"pun">)</span> <span class=3D"pun">{</span>
<span class=3D"pln">speed</span><span class=3D"pun">.</span><span clas=
s=3D"typ">EnableLogging</span><span class=3D"pun">(</span><span class=3D"kw=
d">true</span><span class=3D"pun">)</span>
<span class=3D"kwd">var</span> <span class=3D"pln">err</span> <span cl=
ass=3D"pln">error</span>
<span class=3D"pln">c</span><span class=3D"pun">,</span> <span class=
=3D"pln">err</span> <span class=3D"pun">=3D</span> <span class=3D"pln">spe=
ed</span><span class=3D"pun">.</span><span class=3D"typ">NewPCPClient</span=
><span class=3D"pun">(</span><span class=3D"str">"test"</span><span=
class=3D"pun">)</span>
<span class=3D"kwd">if</span> <span class=3D"pln">err</span> <span cla=
ss=3D"pun">!</span><span class=3D"pun">=3D</span> <span class=3D"kwd">nil</=
span> <span class=3D"pun">{</span>
<span class=3D"pln">log</span><span class=3D"pun">.</span><span cl=
ass=3D"typ">Fatal</span><span class=3D"pun">(</span><span class=3D"str">=
4;Sorry, No Client"</span><span class=3D"pun">)</span>
<span class=3D"pun">}</span>
<span class=3D"pln">c</span><span class=3D"pun">.</span><span class=3D=
"typ">MustStart</span><span class=3D"pun">(</span><span class=3D"pun">)</sp=
an>
<span class=3D"pln">defer</span> <span class=3D"pln">c</span><span cla=
ss=3D"pun">.</span><span class=3D"typ">MustStop</span><span class=3D"pun">(=
</span><span class=3D"pun">)</span>
<span class=3D"pln">go</span> <span class=3D"pln">runner</span><span c=
lass=3D"pun">(</span><span class=3D"str">"a.b.c"</span><span class=
=3D"pun">)</span>
<span class=3D"pln">go</span> <span class=3D"pln">runner</span><span c=
lass=3D"pun">(</span><span class=3D"str">"d.e.f"</span><span class=
=3D"pun">)</span>
<span class=3D"pln">go</span> <span class=3D"pln">runner</span><span c=
lass=3D"pun">(</span><span class=3D"str">"g.h.i"</span><span class=
=3D"pun">)</span>
<span class=3D"pln">time</span><span class=3D"pun">.</span><span class=
=
=3D"typ">Sleep</span><span class=3D"pun">(</span><span class=3D"dec">10</s=
pan> <span class=3D"pun">*</span> <span class=3D"pln">time</span><span clas=
s=3D"pun">.</span><span class=3D"typ">Second</span><span class=3D"pun">)</s=
pan>
<span class=3D"pln">speed</span><span class=3D"pun">.</span><span clas=
s=3D"typ">EraseFileOnStop</span> <span class=3D"pun">=3D</span> <span class=
=
=3D"kwd">true</span>
<span class=3D"pun">}</span>
<span class=3D"kwd">func</span> <span class=3D"pln">runner</span><span cla=
ss=3D"pun">(</span><span class=3D"pln">metricPrefix</span> <span class=3D"p=
ln">string</span><span class=3D"pun">)</span> <span class=3D"pun">{</span>
<span class=3D"kwd">var</span> <span class=3D"pln">x</span> <span clas=
s=3D"pun">=3D</span> <span class=3D"dec">0</span>
<span class=3D"kwd">for</span> <span class=3D"pun">{</span>
<span class=3D"kwd">var</span> <span class=3D"pln">sleepTime</span=
> <span class=3D"pun">=3D</span> <span class=3D"pln">time</span><span class=
=
=3D"pun">.</span><span class=3D"typ">Duration</span><span class=3D"pun">(<=
/span><span class=3D"pln">rand</span><span class=3D"pun">.</span><span clas=
s=3D"typ">Intn</span><span class=3D"pun">(</span><span class=3D"dec">2000</=
span><span class=3D"pun">)</span><span class=3D"pun">)</span> <span class=
=3D"pun">*</span> <span class=3D"pln">time</span><span class=3D"pun">.</sp=
an><span class=3D"typ">Millisecond</span>
<span class=3D"pln">time</span><span class=3D"pun">.</span><span c=
lass=3D"typ">Sleep</span><span class=3D"pun">(</span><span class=3D"pln">sl=
eepTime</span><span class=3D"pun">)</span>
<span class=3D"pln">c</span><span class=3D"pun">.</span><span clas=
s=3D"typ">MustStop</span><span class=3D"pun">(</span><span class=3D"pun">)<=
/span>
<span class=3D"kwd">var</span> <span class=3D"pln">metricName</spa=
n> <span class=3D"pun">=3D</span> <span class=3D"pln">metricPrefix</span> <=
span class=3D"pun">+</span> <span class=3D"str">"."</span> <span cl=
ass=3D"pun">+</span> <span class=3D"pln">strconv</span><span class=3D"pun">=
.</span><span class=3D"typ">Itoa</span><span class=3D"pun">(</span><span cl=
ass=3D"pln">x</span><span class=3D"pun">)</span>
<span class=3D"pln">c</span><span class=3D"pun">.</span><span clas=
s=3D"typ">MustRegisterString</span><span class=3D"pun">(</span><span class=
=3D"pln">metricName</span><span class=3D"pun">,</span> <span class=3D"dec"=
>0</span><span class=3D"pun">,</span> <span class=3D"pln">speed</span><span=
class=3D"pun">.</span><span class=3D"typ">Int64Type</span><span class=3D"p=
un">,</span> <span class=3D"pln">speed</span><span class=3D"pun">.</span><s=
pan class=3D"typ">CounterSemantics</span><span class=3D"pun">,</span> <span=
class=3D"pln">speed</span><span class=3D"pun">.</span><span class=3D"typ">=
OneUnit</span><span class=3D"pun">)</span>
<span class=3D"pln">c</span><span class=3D"pun">.</span><span clas=
s=3D"typ">MustStart</span><span class=3D"pun">(</span><span class=3D"pun">)=
</span>
<span class=3D"pln">x</span><span class=3D"pun">+</span><span clas=
s=3D"pun">+</span>
<span class=3D"pun">}</span>
<span class=3D"pun">}</span>
</code></pre>
<blockquote>
<p>Will this approach work with archiving and long-term monitoring?</p>
</blockquote>
<p>The client must be stopped to re-register a metric because its an issue=
of read location. Adding a metric will modify locations of different block=
s inside the MMV file, which will require reinitialization of the client. H=
ence a metric can only be registered if a client is stopped. Another idea i=
s to have multiple clients, each with a different name and writing their ow=
n metrics. In fact, that is the idea of the client type and not having a si=
ngle global registry of metrics.</p>
<p>
<div width=3D"1" style=3D"color:white;clear:both">_._,_._,_</div>
<hr>
Groups.io Links:<p>
You receive all messages sent to this group.
<p>
<a target=3D"_blank" href=3D"https://groups.io/g/pcp/message/15296">View/R=
eply Online (#15296)</a> |
<a target=3D"_blank" href=3D"mailto:[email protected]?subject=3DRe:%20%5Bpcp=
%5D%20%5Bspeed%3Amaster%5D%20reported%3A%20Explain%20metric%20registration%=
20in%20documentation%20%23github%20%23golang">Reply To Group</a>
| <a target=3D"_blank" href=3D"mailto:?subject=3DRe:%20%5Bpcp%5D%20%5B=
speed%3Amaster%5D%20reported%3A%20Explain%20metric%20registration%20in%20do=
cumentation%20%23github%20%23golang">Reply To Sender</a>
|
<a target=3D"_blank" href=3D"https://groups.io/mt/4437025?uid=3D174580">=
Mute This Topic</a>
=20
| <a href=3D"https://groups.io/g/pcp/post">New Topic</a><br>
<a href=3D"https://groups.io/mk?hashtag=3Dgolang&subid=3D354243">Mute #gol=
ang</a>
|
<a href=3D"https://groups.io/mk?hashtag=3Dgithub&subid=3D354243">Mute #git=
hub</a>
<p>
<p>pcp mailing list<br />[email protected]<br /><a href=3D"https://groups.io/g=
/pcp/messages" target=3D"_blank">https://groups.io/g/pcp/messages</a></p>
<a href=3D"https://groups.io/g/pcp/editsub?uid=3D174580">Change Your Subsc=
ription</a><br>
<a href=3D"https://groups.io/g/pcp">Group Home</a><br>
<a href=3D"mailto:[email protected]">Contact Group Owner</a><br>
<a href=3D"https://groups.io/static/tos">Terms Of Service</a><br>
<a href=3D"https://groups.io/g/pcp/leave/354243/563757577/xyzzy">Unsubscri=
be From This Group</a><br>
<div width=3D"1" style=3D"color:white;clear:both">_._,_._,_</div>
--yabbadabbadoo--